Fixed all test!

This commit is contained in:
William Brown 2019-01-29 16:52:42 +10:00
parent a064f87076
commit 66e087787a
6 changed files with 68 additions and 6 deletions

View file

@ -2,8 +2,10 @@ pub static UUID_ADMIN: &'static str = "00000000-0000-0000-0000-000000000000";
pub static UUID_ANONYMOUS: &'static str = "00000000-0000-0000-0000-ffffffffffff";
pub static JSON_ANONYMOUS_V1: &'static str = r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["object", "account"],
"class": ["account", "object"],
"name": ["anonymous"],
"uuid": ["00000000-0000-0000-0000-ffffffffffff"],
"description": ["Anonymous access account."],
@ -14,6 +16,8 @@ pub static JSON_ANONYMOUS_V1: &'static str = r#"{
pub static UUID_SYSTEM_INFO: &'static str = "00000000-0000-0000-0000-ffffff000001";
pub static JSON_SYSTEM_INFO_V1: &'static str = r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["object", "system_info"],
"name": ["system_info"],

View file

@ -131,9 +131,7 @@ pub struct EntryInvalid; // Modified
#[derive(Serialize, Deserialize, Debug)]
pub struct Entry<VALID, STATE> {
#[serde(default = "EntryInvalid")]
valid: VALID,
#[serde(default = "EntryNew")]
state: STATE,
pub id: Option<i64>,
// Flag if we have been schema checked or not.
@ -214,7 +212,7 @@ impl<STATE> Entry<EntryInvalid, STATE> {
};
// Should never fail!
new_attrs.insert(attr_name_normal, avas_normal).unwrap();
let _ = new_attrs.insert(attr_name_normal, avas_normal);
}
let ne = Entry {
@ -232,7 +230,12 @@ impl<STATE> Entry<EntryInvalid, STATE> {
// if found, then do a len/filter/check on the resulting class set?
{
let entry_classes = (&ne).classes();
// First, check we have class on the object ....
if !ne.attribute_pres("class") {
return Err(SchemaError::InvalidClass)
}
let entry_classes = ne.classes();
let entry_classes_size = entry_classes.len();
let classes: HashMap<String, &SchemaClass> = entry_classes

View file

@ -200,6 +200,8 @@ mod tests {
#[test]
fn test_or_entry_filter() {
let e: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"userid": ["william"],
"uidNumber": ["1000"]
@ -234,6 +236,8 @@ mod tests {
#[test]
fn test_and_entry_filter() {
let e: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"userid": ["william"],
"uidNumber": ["1000"]
@ -268,6 +272,8 @@ mod tests {
#[test]
fn test_not_entry_filter() {
let e1: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"userid": ["william"],
"uidNumber": ["1000"]
@ -289,6 +295,8 @@ mod tests {
#[test]
fn test_nested_entry_filter() {
let e1: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"uidNumber": ["1000"]
@ -296,6 +304,8 @@ mod tests {
}"#).unwrap();
let e2: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"uidNumber": ["1001"]
@ -303,6 +313,8 @@ mod tests {
}"#).unwrap();
let e3: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"uidNumber": ["1002"]
@ -310,6 +322,8 @@ mod tests {
}"#).unwrap();
let e4: Entry<EntryValid, EntryNew> = serde_json::from_str(r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["group"],
"uidNumber": ["1000"]

View file

@ -211,6 +211,8 @@ mod tests {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],
@ -249,6 +251,8 @@ mod tests {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],
@ -285,6 +289,8 @@ mod tests {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],
@ -321,6 +327,8 @@ mod tests {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],
@ -358,6 +366,8 @@ mod tests {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],
@ -392,6 +402,8 @@ mod tests {
fn test_pre_create_uuid_exist() {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],

View file

@ -1231,6 +1231,8 @@ mod tests {
let schema = schema_outer.read();
let e_no_class: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {}
}"#,
)
@ -1243,6 +1245,8 @@ mod tests {
let e_bad_class: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["zzzzzz"]
}
@ -1256,6 +1260,8 @@ mod tests {
let e_attr_invalid: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["attributetype"]
}
@ -1271,6 +1277,8 @@ mod tests {
let e_attr_invalid_may: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["attributetype"],
"name": ["testattr"],
@ -1292,6 +1300,8 @@ mod tests {
let e_attr_invalid_syn: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["attributetype"],
"name": ["testattr"],
@ -1312,6 +1322,8 @@ mod tests {
let e_ok: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["attributetype"],
"name": ["testattr"],
@ -1342,6 +1354,8 @@ mod tests {
// attr name to lower
let e_test: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["extensibleobject"],
"name": ["TestPerson"],
@ -1355,6 +1369,8 @@ mod tests {
let e_expect: Entry<EntryValid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["extensibleobject"],
"name": ["testperson"],
@ -1381,6 +1397,8 @@ mod tests {
let e_extensible_bad: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["extensibleobject"],
"secret": ["zzzz"]
@ -1396,6 +1414,8 @@ mod tests {
let e_extensible: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["extensibleobject"],
"secret": ["true"]
@ -1424,6 +1444,8 @@ mod tests {
// now test some entries
let e_person: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["person"],
"name": ["testperson"],
@ -1438,6 +1460,8 @@ mod tests {
let e_group: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["group"],
"name": ["testgroup"],

View file

@ -549,7 +549,10 @@ impl<'a> QueryServerWriteTransaction<'a> {
self.internal_create(audit, vec![e.invalidate()])
} else if results.len() == 1 {
// it exists. To guarantee content exactly as is, we compare if it's identical.
if e.compare(&results[0]) {
audit_log!(audit, "LEFT -> {:?}", &e);
audit_log!(audit, "RIGHT -> {:?}", &results[0]);
if ! e.compare(&results[0]) {
self.internal_delete(audit, filt);
self.internal_create(audit, vec![e.invalidate()]);
};
@ -763,6 +766,8 @@ mod tests {
let e: Entry<EntryInvalid, EntryNew> = serde_json::from_str(
r#"{
"valid": null,
"state": null,
"attrs": {
"class": ["object", "person"],
"name": ["testperson"],