b3d90e1 · Redact ids outside the wall · 5 days ago

python41 lines · 1.0 KB
1from mapping import load_mapping
2from scope import ScopeError, ScopeGuard
3
4SAMPLE = """---
5workspace: growth-chef
6platform: slack
7scope: team.growth
8agent: relay-prime
9---
10
11| id | name | role | direction |
12|----|------|------|-----------|
13| C0MGMT01 | #mgmt | management | in |
14| C0REPT02 | #reports | reports | out |
15| C0OPS03 | #ops | room | both |
16"""
17
18
19def test_unknown_channel_is_invisible():
20 mapping = load_mapping(SAMPLE)
21 guard = ScopeGuard(mapping)
22 assert guard.allow("C0OPS03")
23 assert not guard.allow("C0SECRET")
24 try:
25 guard.require("C0SECRET", "write")
26 raise AssertionError("wall failed")
27 except ScopeError as err:
28 assert "C0SECRET" not in str(err)
29
30
31def test_redact_does_not_echo_unknown_id():
32 guard = ScopeGuard(load_mapping(SAMPLE))
33 assert guard.redact("C0OPS03") == "C0OPS03"
34 assert guard.redact("C0SECRET") == ""
35
36
37if __name__ == "__main__":
38 test_unknown_channel_is_invisible()
39 test_redact_does_not_echo_unknown_id()
40 print("ok")
41