|
21 | 21 | class TestAuthorize:
|
22 | 22 | fn = authorize
|
23 | 23 |
|
24 |
| - def test_user_tries_to_read(self): |
| 24 | + def test_user_tries_to_read_everything(self): |
25 | 25 | user_policies: PolicyContext = {
|
26 | 26 | "user": {"00df": READ | UPDATE},
|
27 | 27 | "product": {"*": READ},
|
28 | 28 | }
|
29 |
| - # Purposefully don't pass a selector |
30 |
| - scope = authorize(user_policies, resource="coupon", operation="READ") |
31 |
| - assert scope == [] |
| 29 | + # Purposefully don't pass a selector, meaning it's trying to read |
| 30 | + # everything. But user can't see anything from coupons. |
| 31 | + with raises(NotEnoughPrivilegesErr): |
| 32 | + _ = authorize(user_policies, resource="coupon", operation="READ") |
32 | 33 |
|
33 | 34 | scope = authorize(user_policies, resource="user", operation="READ")
|
34 | 35 | assert scope == ["00df"]
|
35 | 36 |
|
36 | 37 | scope = authorize(user_policies, resource="product", operation="READ")
|
37 | 38 | assert scope == ["*"]
|
38 | 39 |
|
| 40 | + def test_user_tries_to_read_specifics(self): |
| 41 | + user_policies: PolicyContext = { |
| 42 | + "coupon": {"00df": READ, "ddf9": READ, "ddfc": READ, "fcc3": READ}, |
| 43 | + } |
| 44 | + |
| 45 | + with raises(NotEnoughPrivilegesErr): |
| 46 | + scope = authorize( |
| 47 | + user_policies, |
| 48 | + resource="coupon", |
| 49 | + operation="READ", |
| 50 | + selector="d3f4", |
| 51 | + ) |
| 52 | + |
| 53 | + scope = authorize( |
| 54 | + user_policies, resource="coupon", operation="READ", selector="fcc3" |
| 55 | + ) |
| 56 | + assert scope == ["fcc3"] |
| 57 | + |
39 | 58 | def test_user_tries_to_write_on_specific_policies(self):
|
40 | 59 | user_id = "00df"
|
41 | 60 | user_policies: PolicyContext = {
|
|
0 commit comments