Skip to content

Commit

Permalink
Fix a json-to-human schema translation bug (#693)
Browse files Browse the repository at this point in the history
Signed-off-by: Shaobo He <[email protected]>
  • Loading branch information
shaobo-he-aws authored Mar 4, 2024
1 parent c5dae1a commit 75c94d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cedar-policy-validator/src/human_schema/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ impl Display for ActionType {
write!(f, "\n}}")?;
}
}
} else {
// No `appliesTo` key: both principal and resource must be unspecified entities
write!(f, "appliesTo {{")?;
// context is an empty record
write!(f, " context: {{}}")?;
write!(f, "\n}}")?;
}
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion cedar-policy-validator/src/human_schema/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ mod demo_tests {
let namespace = NamespaceDefinition::new(empty(), once(("foo".to_smolstr(), action)));
let fragment = SchemaFragment(HashMap::from([("bar".to_smolstr(), namespace)]));
let as_src = fragment.as_natural_schema().unwrap();
let expected = r#"action "foo" ;"#;
let expected = r#"action "foo" appliesTo { context: {}
};"#;
assert!(as_src.contains(expected), "src was:\n`{as_src}`");
}

Expand Down

0 comments on commit 75c94d1

Please sign in to comment.