Tree shaking
Tree shaking for httpapi/authz/decision keeps 78 lines, deletes 32 and adds 0. It keeps 2 files and removes 1.
policy_test.rego: 0 lines kept, 32 deleted, 0 added. Tree shaking removes the file.
1# The tests of the policy. `opa test` runs them, and `just test-rego` with rego4k. `DemoBundlesTest` runs them as JUnit
2# tests. The debugger offers the input of each test as an example.
3package httpapi.authz_test
4
5import data.httpapi.authz
6
7test_viewer_reads_a_report if {
8 authz.allow with input as {"method": "GET", "path": "/reports/q3", "user": "alice"}
9}
10
11test_viewer_cannot_edit_a_report if {
12 not authz.allow with input as {"method": "PUT", "path": "/reports/q3", "user": "alice"}
13}
14
15test_user_reads_own_profile if {
16 authz.allow with input as {"method": "GET", "path": "/users/bob", "user": "bob"}
17}
18
19test_unknown_user_has_no_roles if {
20 authz.decision == {"allow": false, "roles": []} with input as {"method": "GET", "path": "/reports/q3", "user": "mallory"}
21}
22
23# Each case is a test of its own, with the note as its name.
24test_permissions[tc.note] if {
25 some tc in [
26 {"note": "an editor edits a report", "user": "bob", "method": "PUT", "path": "/reports/q3", "allow": true},
27 {"note": "an editor cannot delete a report", "user": "bob", "method": "DELETE", "path": "/reports/q3", "allow": false},
28 {"note": "an admin deletes a user", "user": "carol", "method": "DELETE", "path": "/users/bob", "allow": true},
29 {"note": "a viewer cannot read another profile", "user": "alice", "method": "GET", "path": "/users/bob", "allow": false},
30 ]
31 authz.allow == tc.allow with input as {"method": tc.method, "path": tc.path, "user": tc.user}
32}
Counts
| Lines kept | 78 |
| Lines deleted | 32 |
| Lines added | 0 |
| Files kept | 2 |
| Files removed | 1 |
Builtins (4)
- concat
- equal
- glob.match
- object.get
Legend
1A kept line: the shaken bundle has it.
2A deleted line: the shaken bundle does not have it.
+An added line: only the shaken bundle has it.
- policy.rego a removed file