Skip to content

Commit

Permalink
Merge pull request #149 from biscuit-auth/boolean-equality
Browse files Browse the repository at this point in the history
fix boolean equality
  • Loading branch information
divarvel authored Apr 24, 2023
2 parents eddb8b0 + d5c2bd3 commit 52fa178
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
10 changes: 9 additions & 1 deletion biscuit-auth/examples/testcases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,9 +1280,12 @@ fn expressions<T: Rng + CryptoRng>(
//boolean and
check if !false && true;
//boolean or
check if false or true;
check if false || true;
//boolean parens
check if (true || false) && true;
// boolean equality
check if true == true;
check if false == false;
//integer less than
check if 1 < 2;
Expand Down Expand Up @@ -1342,10 +1345,15 @@ fn expressions<T: Rng + CryptoRng>(
check if [true, false, true].contains(true);
check if ["abc", "def"].contains("abc");
check if [hex:12ab, hex:34de].contains(hex:34de);
check if [1, 2].contains([2]);
// set equal
check if [1, 2] == [1, 2];
// set not equal
check if [1, 4] != [1, 2];
// set intersection
check if [1, 2].intersection([2, 3]) == [2];
// set union
check if [1, 2].union([2, 3]) == [1, 2, 3];
"#)
.build_with_rng(&root, SymbolTable::default(), rng)
.unwrap();
Expand Down
16 changes: 13 additions & 3 deletions biscuit-auth/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,10 @@ public keys: []
check if true;
check if !false;
check if !false && true;
check if false or true;
check if false || true;
check if (true || false) && true;
check if true == true;
check if false == false;
check if 1 < 2;
check if 2 > 1;
check if 1 <= 2;
Expand Down Expand Up @@ -934,8 +936,11 @@ check if [2019-12-04T09:46:41Z, 2020-12-04T09:46:41Z].contains(2020-12-04T09:46:
check if [false, true].contains(true);
check if ["abc", "def"].contains("abc");
check if [hex:12ab, hex:34de].contains(hex:34de);
check if [1, 2].contains([2]);
check if [1, 2] == [1, 2];
check if [1, 4] != [1, 2];
check if [1, 2].intersection([2, 3]) == [2];
check if [1, 2].union([2, 3]) == [1, 2, 3];
```

### validation
Expand All @@ -946,7 +951,7 @@ allow if true;
```

revocation ids:
- `3e51db5f0453929a596485b59e89bf628a301a33d476132c48a1c0a208805809f15bdf99593733c1b5f30e8c1f473ee2f78042f81fd0557081bafb5370e65d0c`
- `ca25bd0ec8929d6a0095401f8a6d923bcfee2ba4661d34b1eb10decbf23c20ad0005b166e912d3be2fc6a2224ad1c786e2f90d2f67e85417aba90f6f4b096606`

authorizer world:
```
Expand Down Expand Up @@ -983,14 +988,19 @@ World {
"check if [\"abc\", \"def\"].contains(\"abc\")",
"check if [1, 2] == [1, 2]",
"check if [1, 2].contains(2)",
"check if [1, 2].contains([2])",
"check if [1, 2].intersection([2, 3]) == [2]",
"check if [1, 2].union([2, 3]) == [1, 2, 3]",
"check if [1, 4] != [1, 2]",
"check if [2019-12-04T09:46:41Z, 2020-12-04T09:46:41Z].contains(2020-12-04T09:46:41Z)",
"check if [false, true].contains(true)",
"check if [hex:12ab, hex:34de].contains(hex:34de)",
"check if false or true",
"check if false == false",
"check if false || true",
"check if hex:12ab == hex:12ab",
"check if hex:12abcd != hex:12ab",
"check if true",
"check if true == true",
}
policies: {
"allow if true",
Expand Down
13 changes: 9 additions & 4 deletions biscuit-auth/samples/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@
],
"public_keys": [],
"external_key": null,
"code": "check if true;\ncheck if !false;\ncheck if !false && true;\ncheck if false or true;\ncheck if (true || false) && true;\ncheck if 1 < 2;\ncheck if 2 > 1;\ncheck if 1 <= 2;\ncheck if 1 <= 1;\ncheck if 2 >= 1;\ncheck if 2 >= 2;\ncheck if 3 == 3;\ncheck if 1 != 3;\ncheck if 1 + 2 * 3 - 4 / 2 == 5;\ncheck if 1 | 2 ^ 3 == 0;\ncheck if \"hello world\".starts_with(\"hello\") && \"hello world\".ends_with(\"world\");\ncheck if \"aaabde\".matches(\"a*c?.e\");\ncheck if \"aaabde\".contains(\"abd\");\ncheck if \"aaabde\" == \"aaa\" + \"b\" + \"de\";\ncheck if \"abcD12\" == \"abcD12\";\ncheck if \"abcD12x\" != \"abcD12\";\ncheck if 2019-12-04T09:46:41Z < 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z > 2019-12-04T09:46:41Z;\ncheck if 2019-12-04T09:46:41Z <= 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z >= 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z >= 2019-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z >= 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z == 2020-12-04T09:46:41Z;\ncheck if 2022-12-04T09:46:41Z != 2020-12-04T09:46:41Z;\ncheck if hex:12ab == hex:12ab;\ncheck if hex:12abcd != hex:12ab;\ncheck if [1, 2].contains(2);\ncheck if [2019-12-04T09:46:41Z, 2020-12-04T09:46:41Z].contains(2020-12-04T09:46:41Z);\ncheck if [false, true].contains(true);\ncheck if [\"abc\", \"def\"].contains(\"abc\");\ncheck if [hex:12ab, hex:34de].contains(hex:34de);\ncheck if [1, 2] == [1, 2];\ncheck if [1, 4] != [1, 2];\n"
"code": "check if true;\ncheck if !false;\ncheck if !false && true;\ncheck if false || true;\ncheck if (true || false) && true;\ncheck if true == true;\ncheck if false == false;\ncheck if 1 < 2;\ncheck if 2 > 1;\ncheck if 1 <= 2;\ncheck if 1 <= 1;\ncheck if 2 >= 1;\ncheck if 2 >= 2;\ncheck if 3 == 3;\ncheck if 1 != 3;\ncheck if 1 + 2 * 3 - 4 / 2 == 5;\ncheck if 1 | 2 ^ 3 == 0;\ncheck if \"hello world\".starts_with(\"hello\") && \"hello world\".ends_with(\"world\");\ncheck if \"aaabde\".matches(\"a*c?.e\");\ncheck if \"aaabde\".contains(\"abd\");\ncheck if \"aaabde\" == \"aaa\" + \"b\" + \"de\";\ncheck if \"abcD12\" == \"abcD12\";\ncheck if \"abcD12x\" != \"abcD12\";\ncheck if 2019-12-04T09:46:41Z < 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z > 2019-12-04T09:46:41Z;\ncheck if 2019-12-04T09:46:41Z <= 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z >= 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z >= 2019-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z >= 2020-12-04T09:46:41Z;\ncheck if 2020-12-04T09:46:41Z == 2020-12-04T09:46:41Z;\ncheck if 2022-12-04T09:46:41Z != 2020-12-04T09:46:41Z;\ncheck if hex:12ab == hex:12ab;\ncheck if hex:12abcd != hex:12ab;\ncheck if [1, 2].contains(2);\ncheck if [2019-12-04T09:46:41Z, 2020-12-04T09:46:41Z].contains(2020-12-04T09:46:41Z);\ncheck if [false, true].contains(true);\ncheck if [\"abc\", \"def\"].contains(\"abc\");\ncheck if [hex:12ab, hex:34de].contains(hex:34de);\ncheck if [1, 2].contains([2]);\ncheck if [1, 2] == [1, 2];\ncheck if [1, 4] != [1, 2];\ncheck if [1, 2].intersection([2, 3]) == [2];\ncheck if [1, 2].union([2, 3]) == [1, 2, 3];\n"
}
],
"validations": {
Expand Down Expand Up @@ -1023,14 +1023,19 @@
"check if [\"abc\", \"def\"].contains(\"abc\")",
"check if [1, 2] == [1, 2]",
"check if [1, 2].contains(2)",
"check if [1, 2].contains([2])",
"check if [1, 2].intersection([2, 3]) == [2]",
"check if [1, 2].union([2, 3]) == [1, 2, 3]",
"check if [1, 4] != [1, 2]",
"check if [2019-12-04T09:46:41Z, 2020-12-04T09:46:41Z].contains(2020-12-04T09:46:41Z)",
"check if [false, true].contains(true)",
"check if [hex:12ab, hex:34de].contains(hex:34de)",
"check if false or true",
"check if false == false",
"check if false || true",
"check if hex:12ab == hex:12ab",
"check if hex:12abcd != hex:12ab",
"check if true"
"check if true",
"check if true == true"
],
"policies": [
"allow if true"
Expand All @@ -1041,7 +1046,7 @@
},
"authorizer_code": "allow if true;\n",
"revocation_ids": [
"3e51db5f0453929a596485b59e89bf628a301a33d476132c48a1c0a208805809f15bdf99593733c1b5f30e8c1f473ee2f78042f81fd0557081bafb5370e65d0c"
"ca25bd0ec8929d6a0095401f8a6d923bcfee2ba4661d34b1eb10decbf23c20ad0005b166e912d3be2fc6a2224ad1c786e2f90d2f67e85417aba90f6f4b096606"
]
}
}
Expand Down
Binary file modified biscuit-auth/samples/test017_expressions.bc
Binary file not shown.
5 changes: 2 additions & 3 deletions biscuit-auth/src/datalog/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ impl Binary {
// boolean
(Binary::And, Term::Bool(i), Term::Bool(j)) => Ok(Term::Bool(i & j)),
(Binary::Or, Term::Bool(i), Term::Bool(j)) => Ok(Term::Bool(i | j)),

(Binary::Equal, _, _) => Ok(Term::Bool(false)),
(Binary::NotEqual, _, _) => Ok(Term::Bool(true)),
(Binary::Equal, Term::Bool(i), Term::Bool(j)) => Ok(Term::Bool(i == j)),
(Binary::NotEqual, Term::Bool(i), Term::Bool(j)) => Ok(Term::Bool(i != j)),

_ => {
//println!("unexpected value type on the stack");
Expand Down

0 comments on commit 52fa178

Please sign in to comment.