diff --git a/cedar-policy-validator/src/human_schema/grammar.lalrpop b/cedar-policy-validator/src/human_schema/grammar.lalrpop index a5a0363917..9ba1a4f77e 100644 --- a/cedar-policy-validator/src/human_schema/grammar.lalrpop +++ b/cedar-policy-validator/src/human_schema/grammar.lalrpop @@ -178,10 +178,8 @@ Ident: Node = { => Node::with_source_loc("namespace".parse().unwrap(), Loc::new(l..r, Arc::clone(src))), ENTITY => Node::with_source_loc("entity".parse().unwrap(), Loc::new(l..r, Arc::clone(src))), - IN - => Node::with_source_loc("in".parse().unwrap(), Loc::new(l..r, Arc::clone(src))), SET - => Node::with_source_loc("set".parse().unwrap(), Loc::new(l..r, Arc::clone(src))), + => Node::with_source_loc("Set".parse().unwrap(), Loc::new(l..r, Arc::clone(src))), APPLIESTO => Node::with_source_loc("appliesTo".parse().unwrap(), Loc::new(l..r, Arc::clone(src))), PRINCIPAL diff --git a/cedar-policy-validator/src/human_schema/test.rs b/cedar-policy-validator/src/human_schema/test.rs index 2c64ff7098..c70b80404c 100644 --- a/cedar-policy-validator/src/human_schema/test.rs +++ b/cedar-policy-validator/src/human_schema/test.rs @@ -948,6 +948,7 @@ mod parser_tests { #[cfg(test)] mod translator_tests { use cedar_policy_core::FromNormalizedStr; + use smol_str::ToSmolStr; use crate::{SchemaError, SchemaFragment, SchemaTypeVariant, TypeOfAttribute, ValidatorSchema}; @@ -1267,4 +1268,158 @@ mod translator_tests { ) ); } + + #[test] + fn entity_named_namespace() { + let src = r#" + entity namespace = {}; + entity Foo in [namespace] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["namespace".to_smolstr()]); + } + + #[test] + fn entity_named_in() { + // This fails because `in` is reserved + let src = r#" + entity in = {}; + entity Foo in [in] = {}; + "#; + + assert!(SchemaFragment::from_str_natural(src).is_err()); + } + + #[test] + fn entity_named_set() { + let src = r#" + entity Set = {}; + entity Foo in [Set] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["Set".to_smolstr()]); + } + + #[test] + fn entity_named_applies_to() { + let src = r#" + entity appliesTo = {}; + entity Foo in [appliesTo] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["appliesTo".to_smolstr()]); + } + + #[test] + fn entity_named_principal() { + let src = r#" + entity principal = {}; + entity Foo in [principal ] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["principal".to_smolstr()]); + } + + #[test] + fn entity_named_resource() { + let src = r#" + entity resource= {}; + entity Foo in [resource] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["resource".to_smolstr()]); + } + + #[test] + fn entity_named_action() { + let src = r#" + entity action= {}; + entity Foo in [action] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["action".to_smolstr()]); + } + + #[test] + fn entity_named_context() { + let src = r#" + entity context= {}; + entity Foo in [context] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["context".to_smolstr()]); + } + + #[test] + fn entity_named_attributes() { + let src = r#" + entity attributes= {}; + entity Foo in [attributes] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["attributes".to_smolstr()]); + } + + #[test] + fn entity_named_bool() { + let src = r#" + entity Bool= {}; + entity Foo in [Bool] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["Bool".to_smolstr()]); + } + + #[test] + fn entity_named_long() { + let src = r#" + entity Long= {}; + entity Foo in [Long] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["Long".to_smolstr()]); + } + + #[test] + fn entity_named_string() { + let src = r#" + entity String= {}; + entity Foo in [String] = {}; + "#; + + let (schema, _) = SchemaFragment::from_str_natural(src).unwrap(); + let ns = schema.0.get("").unwrap(); + let foo = ns.entity_types.get("Foo").unwrap(); + assert_eq!(foo.member_of_types, vec!["String".to_smolstr()]); + } }