From 119caf75b17d94478b2de373d267ce7b5423ca53 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 16 Sep 2025 10:01:28 +0200 Subject: [PATCH] update samples - Use sets in closures sample https://github.com/eclipse-biscuit/biscuit-rust/pull/289 - Add a case for check all with no matches https://github.com/eclipse-biscuit/biscuit-rust/pull/294 - Add missing case in heterogeneous equals sample https://github.com/eclipse-biscuit/biscuit-rust/pull/309 --- samples/current/README.md | 51 +++++++++++++++++-- samples/current/samples.json | 59 ++++++++++++++++++++-- samples/current/test028_expressions_v4.bc | Bin 388 -> 416 bytes 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/samples/current/README.md b/samples/current/README.md index 9b319e6..16715ea 100644 --- a/samples/current/README.md +++ b/samples/current/README.md @@ -2108,6 +2108,49 @@ World { } ``` +result: `Err(FailedLogic(Unauthorized { policy: Allow(0), checks: [Block(FailedBlockCheck { block_id: 0, check_id: 0, rule: "check all operation($op), allowed_operations($allowed), $allowed.contains($op)" })] }))` +### validation for "no matches" + +authorizer code: +``` +allow if true; +``` + +revocation ids: +- `c456817012e1d523c6d145b6d6a3475d9f7dd4383c535454ff3f745ecf4234984ce09b9dec0551f3d783abe850f826ce43b12f1fd91999a4753a56ecf4c56d0d` + +authorizer world: +``` +World { + facts: [ + Facts { + origin: { + Some( + 0, + ), + }, + facts: [ + "allowed_operations({\"A\", \"B\"})", + ], + }, +] + rules: [] + checks: [ + Checks { + origin: Some( + 0, + ), + checks: [ + "check all operation($op), allowed_operations($allowed), $allowed.contains($op)", + ], + }, +] + policies: [ + "allow if true", +] +} +``` + result: `Err(FailedLogic(Unauthorized { policy: Allow(0), checks: [Block(FailedBlockCheck { block_id: 0, check_id: 0, rule: "check all operation($op), allowed_operations($allowed), $allowed.contains($op)" })] }))` @@ -2417,6 +2460,7 @@ public keys: [] block version: 4 ``` +check if true !== false; check if 1 !== 3; check if 1 | 2 ^ 3 === 0; check if "abcD12x" !== "abcD12"; @@ -2433,7 +2477,7 @@ allow if true; ``` revocation ids: -- `117fa653744c859561555e6a6f5990e3a8e7817f91b87aa6991b6d64297158b4e884c92d10f49f74c96069df722aa676839b72751ca9d1fe83a7025b591de00b` +- `9402c07923aa33bc911de80e61f388f5c4533e6b36e45317dc1db1e6bcc7664ed0c1c504d0ca8925208008961d95bbdbc36f6e3d91b3173369cc19ed625e9a0c` authorizer world: ``` @@ -2451,6 +2495,7 @@ World { "check if 1 | 2 ^ 3 === 0", "check if 2022-12-04T09:46:41Z !== 2020-12-04T09:46:41Z", "check if hex:12abcd !== hex:12ab", + "check if true !== false", "check if {1, 4} !== {1, 2}", ], }, @@ -3011,7 +3056,7 @@ result: `Ok(0)` authorizer code: ``` -allow if [true].any($p -> [true].all($p -> $p)); +allow if {"true"}.any($p -> {"true"}.all($p -> $p)); ``` revocation ids: @@ -3042,7 +3087,7 @@ World { }, ] policies: [ - "allow if [true].any($p -> [true].all($p -> $p))", + "allow if {\"true\"}.any($p -> {\"true\"}.all($p -> $p))", ] } ``` diff --git a/samples/current/samples.json b/samples/current/samples.json index 28a97c5..3366eaf 100644 --- a/samples/current/samples.json +++ b/samples/current/samples.json @@ -1965,6 +1965,56 @@ "revocation_ids": [ "c456817012e1d523c6d145b6d6a3475d9f7dd4383c535454ff3f745ecf4234984ce09b9dec0551f3d783abe850f826ce43b12f1fd91999a4753a56ecf4c56d0d" ] + }, + "no matches": { + "world": { + "facts": [ + { + "origin": [ + 0 + ], + "facts": [ + "allowed_operations({\"A\", \"B\"})" + ] + } + ], + "rules": [], + "checks": [ + { + "origin": 0, + "checks": [ + "check all operation($op), allowed_operations($allowed), $allowed.contains($op)" + ] + } + ], + "policies": [ + "allow if true" + ] + }, + "result": { + "Err": { + "FailedLogic": { + "Unauthorized": { + "policy": { + "Allow": 0 + }, + "checks": [ + { + "Block": { + "block_id": 0, + "check_id": 0, + "rule": "check all operation($op), allowed_operations($allowed), $allowed.contains($op)" + } + } + ] + } + } + } + }, + "authorizer_code": "allow if true;\n", + "revocation_ids": [ + "c456817012e1d523c6d145b6d6a3475d9f7dd4383c535454ff3f745ecf4234984ce09b9dec0551f3d783abe850f826ce43b12f1fd91999a4753a56ecf4c56d0d" + ] } } }, @@ -2201,7 +2251,7 @@ ], "public_keys": [], "external_key": null, - "code": "check if 1 !== 3;\ncheck if 1 | 2 ^ 3 === 0;\ncheck if \"abcD12x\" !== \"abcD12\";\ncheck if 2022-12-04T09:46:41Z !== 2020-12-04T09:46:41Z;\ncheck if hex:12abcd !== hex:12ab;\ncheck if {1, 4} !== {1, 2};\n", + "code": "check if true !== false;\ncheck if 1 !== 3;\ncheck if 1 | 2 ^ 3 === 0;\ncheck if \"abcD12x\" !== \"abcD12\";\ncheck if 2022-12-04T09:46:41Z !== 2020-12-04T09:46:41Z;\ncheck if hex:12abcd !== hex:12ab;\ncheck if {1, 4} !== {1, 2};\n", "version": 4 } ], @@ -2219,6 +2269,7 @@ "check if 1 | 2 ^ 3 === 0", "check if 2022-12-04T09:46:41Z !== 2020-12-04T09:46:41Z", "check if hex:12abcd !== hex:12ab", + "check if true !== false", "check if {1, 4} !== {1, 2}" ] } @@ -2232,7 +2283,7 @@ }, "authorizer_code": "allow if true;\n", "revocation_ids": [ - "117fa653744c859561555e6a6f5990e3a8e7817f91b87aa6991b6d64297158b4e884c92d10f49f74c96069df722aa676839b72751ca9d1fe83a7025b591de00b" + "9402c07923aa33bc911de80e61f388f5c4533e6b36e45317dc1db1e6bcc7664ed0c1c504d0ca8925208008961d95bbdbc36f6e3d91b3173369cc19ed625e9a0c" ] } } @@ -2800,7 +2851,7 @@ } ], "policies": [ - "allow if [true].any($p -> [true].all($p -> $p))" + "allow if {\"true\"}.any($p -> {\"true\"}.all($p -> $p))" ] }, "result": { @@ -2808,7 +2859,7 @@ "Execution": "ShadowedVariable" } }, - "authorizer_code": "allow if [true].any($p -> [true].all($p -> $p));\n", + "authorizer_code": "allow if {\"true\"}.any($p -> {\"true\"}.all($p -> $p));\n", "revocation_ids": [ "2cd348b6df5f08b900903fd8d3fbea0bb89b665c331a2aa2131e0b8ecb38b3550275d4ccd8db35da6c4433eed1d456cfb761e3fcc7845894d891e986ca044b02" ] diff --git a/samples/current/test028_expressions_v4.bc b/samples/current/test028_expressions_v4.bc index c34d7a103fcfe7a1ada52e0be46ec70f544137e0..7d94e82d59e486fafc7c3a1fa354ad7020aaccb4 100644 GIT binary patch delta 102 zcmV-s0Ga=U1E2#268QoOjslSeAr3GB3IqxQFaQb!8UhFuu^9&eK$HT&c_XSbypbK~ z4q@|%^~6&?Yc}Ll7u+4O=Df#dPSC-{1klQfB_MzZmK~M5+rw{eJ(05)Gil5j?P6Y< I43l61ByU(H$N&HU delta 86 zcmV-c0IC0=1B3$x65Rp{@&Sf04L)rkNXU sWGQi2wCIG%EfDmdbje_8-*PIZc7vO8bsVYD{)49iTUj083zK{SBt9f2dH?_b