Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject if #199

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions biscuit-auth/examples/testcases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ fn main() {

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

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

if json {
let s = serde_json::to_string_pretty(&TestCases {
root_private_key: hex::encode(root.private().to_bytes()),
Expand Down Expand Up @@ -1953,6 +1955,37 @@ fn expressions_v4(target: &str, root: &KeyPair, test: bool) -> TestResult {
}
}

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

let biscuit = biscuit!(r#"reject if test($test), $test"#)
.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[..], "test(false); allow if true"),
);
validations.insert(
"rejection".to_string(),
validate_token(root, &data[..], "test(true); allow if true"),
);

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

fn print_blocks(token: &Biscuit) -> Vec<BlockContent> {
let mut v = Vec::new();

Expand Down
84 changes: 84 additions & 0 deletions biscuit-auth/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2361,3 +2361,87 @@ World {

result: `Ok(0)`


------------------------------

## test reject if: test029_reject_if.bc
### token

authority:
symbols: ["test"]

public keys: []

```
reject if test($test), $test;
```

### validation

authorizer code:
```
test(false);

allow if true;
```

revocation ids:
- `2060031eb9968b492123440fa9cbc781f18be812961e765a34a8702d3eee0ed54910710efbb41b3141f60748a815012fe0e703a5b5604f4262d1ac7e79766b07`

authorizer world:
```
World {
facts: {
(
"test(false)",
{
None,
},
),
}
rules: {}
checks: {
"reject if test($test), $test",
}
policies: {
"allow if true",
}
}
```

result: `Ok(0)`
### validation for "rejection"

authorizer code:
```
test(true);

allow if true;
```

revocation ids:
- `2060031eb9968b492123440fa9cbc781f18be812961e765a34a8702d3eee0ed54910710efbb41b3141f60748a815012fe0e703a5b5604f4262d1ac7e79766b07`

authorizer world:
```
World {
facts: {
(
"test(true)",
{
None,
},
),
}
rules: {}
checks: {
"reject if test($test), $test",
}
policies: {
"allow if true",
}
}
```

result: `Err(FailedLogic(Unauthorized { policy: Allow(0), checks: [Block(FailedBlockCheck { block_id: 0, check_id: 0, rule: "reject if test($test), $test" })] }))`

85 changes: 85 additions & 0 deletions biscuit-auth/samples/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,91 @@
]
}
}
},
{
"title": "test reject if",
"filename": "test029_reject_if.bc",
"token": [
{
"symbols": [
"test"
],
"public_keys": [],
"external_key": null,
"code": "reject if test($test), $test;\n"
}
],
"validations": {
"": {
"world": {
"facts": [
[
"test(false)",
[
null
]
]
],
"rules": [],
"checks": [
"reject if test($test), $test"
],
"policies": [
"allow if true"
]
},
"result": {
"Ok": 0
},
"authorizer_code": "test(false);\n\nallow if true;\n",
"revocation_ids": [
"2060031eb9968b492123440fa9cbc781f18be812961e765a34a8702d3eee0ed54910710efbb41b3141f60748a815012fe0e703a5b5604f4262d1ac7e79766b07"
]
},
"rejection": {
"world": {
"facts": [
[
"test(true)",
[
null
]
]
],
"rules": [],
"checks": [
"reject if test($test), $test"
],
"policies": [
"allow if true"
]
},
"result": {
"Err": {
"FailedLogic": {
"Unauthorized": {
"policy": {
"Allow": 0
},
"checks": [
{
"Block": {
"block_id": 0,
"check_id": 0,
"rule": "reject if test($test), $test"
}
}
]
}
}
}
},
"authorizer_code": "test(true);\n\nallow if true;\n",
"revocation_ids": [
"2060031eb9968b492123440fa9cbc781f18be812961e765a34a8702d3eee0ed54910710efbb41b3141f60748a815012fe0e703a5b5604f4262d1ac7e79766b07"
]
}
}
}
]
}
Binary file added biscuit-auth/samples/test029_reject_if.bc
Binary file not shown.
Loading