Skip to content

Commit

Permalink
sort facts in dump_code to get a consistent order
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Nov 28, 2024
1 parent 0fc3869 commit a5f9696
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions biscuit-auth/src/token/authorizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ impl Authorizer {
pub fn dump_code(&self) -> String {
let (facts, rules, checks, policies) = self.dump();
let mut f = String::new();

let mut facts = facts.into_iter().map(|f| f.to_string()).collect::<Vec<_>>();
facts.sort();
for fact in &facts {
let _ = writeln!(f, "{fact};");
}
Expand Down
4 changes: 2 additions & 2 deletions biscuit-auth/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ fn authorizer_macro() {
let authorizer = b.build().unwrap();
assert_eq!(
authorizer.dump_code(),
r#"fact("test", hex:aabbcc, [true], "my_value");
r#"appended(true);
fact("test", hex:aabbcc, [true], "my_value");
rule("test", true);
appended(true);
rule($0, true) <- fact($0, $1, $2, "my_value");
Expand Down

0 comments on commit a5f9696

Please sign in to comment.