Skip to content

Commit

Permalink
Merge pull request #240 from biscuit-auth/typeof-array-map-sample
Browse files Browse the repository at this point in the history
add samples for typeof on array / map
  • Loading branch information
divarvel authored Nov 5, 2024
2 parents f099d38 + 070ea98 commit 15931f2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions biscuit-auth/examples/testcases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,10 @@ fn type_of(target: &str, root: &KeyPair, test: bool) -> TestResult {
check if null.type() == "null";
null(null);
check if null($t), $t.type() == "null";
array([1,2,3]);
check if array($t), $t.type() == "array";
map({"a": true});
check if map($t), $t.type() == "map";
"#
)
.build_with_rng(&root, SymbolTable::default(), &mut rng)
Expand Down
12 changes: 10 additions & 2 deletions biscuit-auth/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,7 @@ result: `Err(Execution(ShadowedVariable))`
### token

authority:
symbols: ["integer", "string", "test", "date", "bytes", "bool", "set", "null", "t"]
symbols: ["integer", "string", "test", "date", "bytes", "bool", "set", "null", "array", "map", "a", "t"]

public keys: []

Expand All @@ -2885,6 +2885,8 @@ bytes(hex:aa);
bool(true);
set({false, true});
null(null);
array([1, 2, 3]);
map({"a": true});
check if 1.type() == "integer";
check if integer($t), $t.type() == "integer";
check if "test".type() == "string";
Expand All @@ -2899,6 +2901,8 @@ check if {false, true}.type() == "set";
check if set($t), $t.type() == "set";
check if null.type() == "null";
check if null($t), $t.type() == "null";
check if array($t), $t.type() == "array";
check if map($t), $t.type() == "map";
```

### validation
Expand All @@ -2909,7 +2913,7 @@ allow if true;
```

revocation ids:
- `be401996253dce45ac3d8b2f4b289af1f2cc2a4447a8265a1a2ca879c43377978ffc5ac6633053cd7c30e7c33cf258a37767226834bc80b005c48eb0229c4502`
- `c8f7ff152b40a3e8f3ab19a435ccd16c41288762864022895b99d2abb6330c794b3f1378a4651b31d249f4c35b69246d88124d40e05e634a0eb9ca9e54b1ca0a`

authorizer world:
```
Expand All @@ -2922,10 +2926,12 @@ World {
),
},
facts: [
"array([1, 2, 3])",
"bool(true)",
"bytes(hex:aa)",
"date(2023-12-28T00:00:00Z)",
"integer(1)",
"map({\"a\": true})",
"null(null)",
"set({false, true})",
"string(\"test\")",
Expand All @@ -2942,11 +2948,13 @@ World {
"check if \"test\".type() == \"string\"",
"check if (2023-12-28T00:00:00Z).type() == \"date\"",
"check if 1.type() == \"integer\"",
"check if array($t), $t.type() == \"array\"",
"check if bool($t), $t.type() == \"bool\"",
"check if bytes($t), $t.type() == \"bytes\"",
"check if date($t), $t.type() == \"date\"",
"check if hex:aa.type() == \"bytes\"",
"check if integer($t), $t.type() == \"integer\"",
"check if map($t), $t.type() == \"map\"",
"check if null($t), $t.type() == \"null\"",
"check if null.type() == \"null\"",
"check if set($t), $t.type() == \"set\"",
Expand Down
11 changes: 9 additions & 2 deletions biscuit-auth/samples/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -2712,11 +2712,14 @@
"bool",
"set",
"null",
"array",
"map",
"a",
"t"
],
"public_keys": [],
"external_key": null,
"code": "integer(1);\nstring(\"test\");\ndate(2023-12-28T00:00:00Z);\nbytes(hex:aa);\nbool(true);\nset({false, true});\nnull(null);\ncheck if 1.type() == \"integer\";\ncheck if integer($t), $t.type() == \"integer\";\ncheck if \"test\".type() == \"string\";\ncheck if string($t), $t.type() == \"string\";\ncheck if (2023-12-28T00:00:00Z).type() == \"date\";\ncheck if date($t), $t.type() == \"date\";\ncheck if hex:aa.type() == \"bytes\";\ncheck if bytes($t), $t.type() == \"bytes\";\ncheck if true.type() == \"bool\";\ncheck if bool($t), $t.type() == \"bool\";\ncheck if {false, true}.type() == \"set\";\ncheck if set($t), $t.type() == \"set\";\ncheck if null.type() == \"null\";\ncheck if null($t), $t.type() == \"null\";\n"
"code": "integer(1);\nstring(\"test\");\ndate(2023-12-28T00:00:00Z);\nbytes(hex:aa);\nbool(true);\nset({false, true});\nnull(null);\narray([1, 2, 3]);\nmap({\"a\": true});\ncheck if 1.type() == \"integer\";\ncheck if integer($t), $t.type() == \"integer\";\ncheck if \"test\".type() == \"string\";\ncheck if string($t), $t.type() == \"string\";\ncheck if (2023-12-28T00:00:00Z).type() == \"date\";\ncheck if date($t), $t.type() == \"date\";\ncheck if hex:aa.type() == \"bytes\";\ncheck if bytes($t), $t.type() == \"bytes\";\ncheck if true.type() == \"bool\";\ncheck if bool($t), $t.type() == \"bool\";\ncheck if {false, true}.type() == \"set\";\ncheck if set($t), $t.type() == \"set\";\ncheck if null.type() == \"null\";\ncheck if null($t), $t.type() == \"null\";\ncheck if array($t), $t.type() == \"array\";\ncheck if map($t), $t.type() == \"map\";\n"
}
],
"validations": {
Expand All @@ -2728,10 +2731,12 @@
0
],
"facts": [
"array([1, 2, 3])",
"bool(true)",
"bytes(hex:aa)",
"date(2023-12-28T00:00:00Z)",
"integer(1)",
"map({\"a\": true})",
"null(null)",
"set({false, true})",
"string(\"test\")"
Expand All @@ -2746,11 +2751,13 @@
"check if \"test\".type() == \"string\"",
"check if (2023-12-28T00:00:00Z).type() == \"date\"",
"check if 1.type() == \"integer\"",
"check if array($t), $t.type() == \"array\"",
"check if bool($t), $t.type() == \"bool\"",
"check if bytes($t), $t.type() == \"bytes\"",
"check if date($t), $t.type() == \"date\"",
"check if hex:aa.type() == \"bytes\"",
"check if integer($t), $t.type() == \"integer\"",
"check if map($t), $t.type() == \"map\"",
"check if null($t), $t.type() == \"null\"",
"check if null.type() == \"null\"",
"check if set($t), $t.type() == \"set\"",
Expand All @@ -2769,7 +2776,7 @@
},
"authorizer_code": "allow if true;\n",
"revocation_ids": [
"be401996253dce45ac3d8b2f4b289af1f2cc2a4447a8265a1a2ca879c43377978ffc5ac6633053cd7c30e7c33cf258a37767226834bc80b005c48eb0229c4502"
"c8f7ff152b40a3e8f3ab19a435ccd16c41288762864022895b99d2abb6330c794b3f1378a4651b31d249f4c35b69246d88124d40e05e634a0eb9ca9e54b1ca0a"
]
}
}
Expand Down
Binary file modified biscuit-auth/samples/test033_typeof.bc
Binary file not shown.
2 changes: 0 additions & 2 deletions biscuit-auth/src/token/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,10 @@ impl Term {
Term::Map(m) => Term::Map(
m.into_iter()
.map(|(key, term)| {
println!("will try to apply parameters on {key:?} -> {term:?}");
(
match key {
MapKey::Parameter(name) => {
if let Some(Some(key_term)) = parameters.get(&name) {
println!("found key term: {key_term}");
match key_term {
Term::Integer(i) => MapKey::Integer(*i),
Term::Str(s) => MapKey::Str(s.clone()),
Expand Down

0 comments on commit 15931f2

Please sign in to comment.