From 66e087787a88e04be272105daef2cb277890a5ab Mon Sep 17 00:00:00 2001 From: William Brown Date: Tue, 29 Jan 2019 16:52:42 +1000 Subject: [PATCH] Fixed all test! --- src/lib/constants.rs | 6 +++++- src/lib/entry.rs | 11 +++++++---- src/lib/filter.rs | 14 ++++++++++++++ src/lib/plugins/base.rs | 12 ++++++++++++ src/lib/schema.rs | 24 ++++++++++++++++++++++++ src/lib/server.rs | 7 ++++++- 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/lib/constants.rs b/src/lib/constants.rs index 20907557a..7b66bd6ef 100644 --- a/src/lib/constants.rs +++ b/src/lib/constants.rs @@ -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"], diff --git a/src/lib/entry.rs b/src/lib/entry.rs index 46795d456..1a2250130 100644 --- a/src/lib/entry.rs +++ b/src/lib/entry.rs @@ -131,9 +131,7 @@ pub struct EntryInvalid; // Modified #[derive(Serialize, Deserialize, Debug)] pub struct Entry { - #[serde(default = "EntryInvalid")] valid: VALID, - #[serde(default = "EntryNew")] state: STATE, pub id: Option, // Flag if we have been schema checked or not. @@ -214,7 +212,7 @@ impl Entry { }; // 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 Entry { // 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 = entry_classes diff --git a/src/lib/filter.rs b/src/lib/filter.rs index c573c9688..5fed5abc3 100644 --- a/src/lib/filter.rs +++ b/src/lib/filter.rs @@ -200,6 +200,8 @@ mod tests { #[test] fn test_or_entry_filter() { let e: Entry = 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 = 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 = 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 = serde_json::from_str(r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "uidNumber": ["1000"] @@ -296,6 +304,8 @@ mod tests { }"#).unwrap(); let e2: Entry = serde_json::from_str(r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "uidNumber": ["1001"] @@ -303,6 +313,8 @@ mod tests { }"#).unwrap(); let e3: Entry = serde_json::from_str(r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "uidNumber": ["1002"] @@ -310,6 +322,8 @@ mod tests { }"#).unwrap(); let e4: Entry = serde_json::from_str(r#"{ + "valid": null, + "state": null, "attrs": { "class": ["group"], "uidNumber": ["1000"] diff --git a/src/lib/plugins/base.rs b/src/lib/plugins/base.rs index a83af43a4..d3dfd2484 100644 --- a/src/lib/plugins/base.rs +++ b/src/lib/plugins/base.rs @@ -211,6 +211,8 @@ mod tests { let e: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "name": ["testperson"], @@ -249,6 +251,8 @@ mod tests { let e: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "name": ["testperson"], @@ -285,6 +289,8 @@ mod tests { let e: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "name": ["testperson"], @@ -321,6 +327,8 @@ mod tests { let e: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "name": ["testperson"], @@ -358,6 +366,8 @@ mod tests { let e: Entry = 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 = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "name": ["testperson"], diff --git a/src/lib/schema.rs b/src/lib/schema.rs index 95f8f59bf..a817be93d 100644 --- a/src/lib/schema.rs +++ b/src/lib/schema.rs @@ -1231,6 +1231,8 @@ mod tests { let schema = schema_outer.read(); let e_no_class: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": {} }"#, ) @@ -1243,6 +1245,8 @@ mod tests { let e_bad_class: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["zzzzzz"] } @@ -1256,6 +1260,8 @@ mod tests { let e_attr_invalid: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["attributetype"] } @@ -1271,6 +1277,8 @@ mod tests { let e_attr_invalid_may: Entry = 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 = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["attributetype"], "name": ["testattr"], @@ -1312,6 +1322,8 @@ mod tests { let e_ok: Entry = 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 = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["extensibleobject"], "name": ["TestPerson"], @@ -1355,6 +1369,8 @@ mod tests { let e_expect: Entry = 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 = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["extensibleobject"], "secret": ["zzzz"] @@ -1396,6 +1414,8 @@ mod tests { let e_extensible: Entry = 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 = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["person"], "name": ["testperson"], @@ -1438,6 +1460,8 @@ mod tests { let e_group: Entry = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["group"], "name": ["testgroup"], diff --git a/src/lib/server.rs b/src/lib/server.rs index 5b026ac37..c5e03a2d3 100644 --- a/src/lib/server.rs +++ b/src/lib/server.rs @@ -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 = serde_json::from_str( r#"{ + "valid": null, + "state": null, "attrs": { "class": ["object", "person"], "name": ["testperson"],