Skip to content

Commit

Permalink
Merge branch 'v5' into closures
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed May 23, 2024
2 parents 025ba46 + 54a573a commit 2f2c3d8
Show file tree
Hide file tree
Showing 14 changed files with 1,335 additions and 14 deletions.
49 changes: 48 additions & 1 deletion biscuit-auth/examples/testcases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn main() {
};

let mut results = Vec::new();

add_test_result(&mut results, basic_token(&target, &root, test));

add_test_result(&mut results, different_root_key(&target, &root, test));
Expand Down Expand Up @@ -143,6 +144,8 @@ fn main() {

add_test_result(&mut results, reject_if(&target, &root, test));

add_test_result(&mut results, null(&target, &root, test));

add_test_result(&mut results, expressions_v5(&target, &root, test));

if json {
Expand Down Expand Up @@ -1979,10 +1982,54 @@ fn reject_if(target: &str, root: &KeyPair, test: bool) -> TestResult {
}
}

fn null(target: &str, root: &KeyPair, test: bool) -> TestResult {
let mut rng: StdRng = SeedableRng::seed_from_u64(1234);
let title = "test null".to_string();
let filename = "test030_null".to_string();
let token;

let biscuit = biscuit!(
r#"
check if fact(null, $value), $value == null;
reject if fact(null, $value), $value != null;
"#
)
.build_with_rng(&root, SymbolTable::default(), &mut rng)
.unwrap();
token = print_blocks(&biscuit);

let data = write_or_load_testcase(target, &filename, root, &biscuit, test);

let mut validations = BTreeMap::new();
validations.insert(
"".to_string(),
validate_token(root, &data[..], "fact(null, null); allow if true"),
);
validations.insert(
"rejection1".to_string(),
validate_token(root, &data[..], "fact(null, 1); allow if true"),
);
validations.insert(
"rejection2".to_string(),
validate_token(root, &data[..], "fact(null, true); allow if true"),
);
validations.insert(
"rejection3".to_string(),
validate_token(root, &data[..], "fact(null, \"abcd\"); allow if true"),
);

TestResult {
title,
filename,
token,
validations,
}
}

fn expressions_v5(target: &str, root: &KeyPair, test: bool) -> TestResult {
let mut rng: StdRng = SeedableRng::seed_from_u64(1234);
let title = "test expression syntax and all available operations (v5 blocks)".to_string();
let filename = "test030_expressions_v5".to_string();
let filename = "test031_expressions_v5".to_string();
let token;

let biscuit = biscuit!(
Expand Down
Loading

0 comments on commit 2f2c3d8

Please sign in to comment.