40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import pytest
|
|
|
|
from app.commands import is_allowed, normalize_id
|
|
|
|
|
|
@pytest.mark.parametrize("allowlist", [None, "", " ", ",;"])
|
|
def test_empty_allowlist_denies(allowlist):
|
|
assert not is_allowed("telegram", "123", allowlist)
|
|
assert not is_allowed("matrix", "@a:b.de", allowlist)
|
|
|
|
|
|
def test_telegram_numeric():
|
|
assert is_allowed("telegram", "123", "123, 456")
|
|
assert is_allowed("telegram", " 456 ", "123;456")
|
|
assert not is_allowed("telegram", "789", "123,456")
|
|
assert not is_allowed("telegram", "alice", "alice")
|
|
assert not is_allowed("telegram", "", "123")
|
|
|
|
|
|
def test_matrix_domain_case_insensitive():
|
|
assert is_allowed("matrix", "@Alice:Example.ORG", "@Alice:example.org")
|
|
assert is_allowed("matrix", "@alice:example.org", "@alice:EXAMPLE.org other")
|
|
assert not is_allowed("matrix", "@alice:example.org", "@bob:example.org")
|
|
|
|
|
|
def test_matrix_localpart_case_sensitive():
|
|
assert not is_allowed("matrix", "@alice:example.org", "@Alice:example.org")
|
|
|
|
|
|
def test_invalid_ids_and_backend():
|
|
assert normalize_id("matrix", "alice") is None
|
|
assert normalize_id("matrix", "@alice") is None
|
|
assert normalize_id("irc", "1") is None
|
|
assert not is_allowed("irc", "1", "1")
|
|
|
|
|
|
def test_backends_not_mixed():
|
|
assert not is_allowed("matrix", "123", "123")
|
|
assert not is_allowed("telegram", "@a:b.de", "@a:b.de")
|