diff --git a/Cargo.toml b/Cargo.toml index 2a8cc5b81..82c9e3ea7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ lazy_static = "1.2.0" tokio = "0.1" futures = "0.1" -uuid = { version = "0.5", features = ["serde", "v4"] } +uuid = { version = "0.7", features = ["serde", "v4"] } serde = "1.0" serde_json = "1.0" serde_derive = "1.0" diff --git a/src/lib/schema.rs b/src/lib/schema.rs index c08ea58fb..24770acd9 100644 --- a/src/lib/schema.rs +++ b/src/lib/schema.rs @@ -6,6 +6,7 @@ use std::collections::HashMap; use regex::Regex; use std::convert::TryFrom; use std::str::FromStr; +use uuid::Uuid; // representations of schema that confines object types, classes // and attributes. This ties in deeply with "Entry". @@ -120,7 +121,9 @@ impl SchemaAttribute { } fn validate_uuid(&self, v: &String) -> Result<(), SchemaError> { - unimplemented!() + Uuid::parse_str(v.as_str()) + .map_err(|_| SchemaError::InvalidAttributeSyntax) + .map(|_| ()) } fn validate_principal(&self, v: &String) -> Result<(), SchemaError> { @@ -230,10 +233,18 @@ impl SchemaAttribute { v.to_lowercase() } + pub fn normalise_uuid(&self, v:&String) -> String { + // We unwrap here as we should already have been validated ... + let c_uuid = Uuid::parse_str(v.as_str()).unwrap(); + c_uuid.to_hyphenated().to_string() + } + + // FIXME: This clones everything, which is expensive! pub fn normalise_value(&self, v: &String) -> String { match self.syntax { SyntaxType::SYNTAX_ID => self.normalise_syntax(v), SyntaxType::INDEX_ID => self.normalise_index(v), + SyntaxType::UUID => self.normalise_uuid(v), SyntaxType::UTF8STRING_INSENSITIVE => self.normalise_utf8string_insensitive(v), SyntaxType::UTF8STRING_PRINCIPAL => self.normalise_principal(v), _ => v.clone(), @@ -940,6 +951,24 @@ mod tests { assert!(r5.is_err()); } + #[test] + fn test_schema_normalise_uuid() { + let sa = SchemaAttribute { + name: String::from("uuid"), + description: String::from("The universal unique id of the object"), + system: true, + secret: false, + multivalue: false, + index: vec![IndexType::EQUALITY], + syntax: SyntaxType::UUID, + }; + let u1 = String::from("936DA01F9ABD4d9d80C702AF85C822A8"); + + let un1 = sa.normalise_value(&u1); + assert_eq!(un1, "936da01f-9abd-4d9d-80c7-02af85c822a8"); + + } + #[test] fn test_schema_attribute_simple() { // Test schemaAttribute validation of types. @@ -1038,6 +1067,7 @@ mod tests { #[test] fn test_schema_classes_simple() { // Test basic functions of simple attributes + } #[test] diff --git a/src/lib/server.rs b/src/lib/server.rs index 42e85d3c6..3e421b54f 100644 --- a/src/lib/server.rs +++ b/src/lib/server.rs @@ -299,8 +299,9 @@ mod tests { let e: Entry = serde_json::from_str( r#"{ "attrs": { - "class": ["person"], + "class": ["object", "person"], "name": ["testperson"], + "uuid": ["cc8e95b4-c24f-4d68-ba54-8bed76f63930"], "description": ["testperson"], "displayname": ["testperson"] }