b3d90e1 · Redact ids outside the wall · 5 days ago
1
from mapping import load_mapping2
from scope import ScopeError, ScopeGuard3
4
SAMPLE = """---5
workspace: growth-chef6
platform: slack7
scope: team.growth8
agent: relay-prime9
---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
19
def 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
31
def 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
37
if __name__ == "__main__":38
test_unknown_channel_is_invisible()39
test_redact_does_not_echo_unknown_id()40
print("ok")41