Merge pull request 'Assert the live Matrix tests run as a testing identity' (#13) from matrix-identity-guard into main
CI / checks (push) Successful in 17s
CI / checks (push) Successful in 17s
This commit was merged in pull request #13.
This commit is contained in:
commit
ad45e33517
1 file changed
+22
@@ -33,6 +33,27 @@ pytestmark = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _assert_testing_identity(transport: MatrixTransport, config: MatrixConfig) -> None:
|
||||||
|
"""Two invariants that only a live homeserver can check.
|
||||||
|
|
||||||
|
The configured user id must be the token's real owner, because the
|
||||||
|
transport filters its own messages by comparing sender to that value —
|
||||||
|
a mismatch would make the bot read its own posts as operator input.
|
||||||
|
And tests must run as a testing identity, so a stray live run can never
|
||||||
|
act as the production agent.
|
||||||
|
"""
|
||||||
|
whoami = transport._http.get("/account/whoami")
|
||||||
|
whoami.raise_for_status()
|
||||||
|
actual = whoami.json()["user_id"]
|
||||||
|
assert actual == config.user_id, (
|
||||||
|
f"NISSE_MATRIX_USER_ID is {config.user_id} but the token belongs to "
|
||||||
|
f"{actual}; the self-message filter would not match"
|
||||||
|
)
|
||||||
|
assert "testing" in actual, (
|
||||||
|
f"live tests must run as a testing identity, not {actual}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_send_lands_in_test_room() -> None:
|
def test_send_lands_in_test_room() -> None:
|
||||||
missing = [var for var in ALSO_REQUIRED if not os.environ.get(var)]
|
missing = [var for var in ALSO_REQUIRED if not os.environ.get(var)]
|
||||||
assert not missing, (
|
assert not missing, (
|
||||||
@@ -43,6 +64,7 @@ def test_send_lands_in_test_room() -> None:
|
|||||||
marker = f"transport smoke test {uuid.uuid4().hex}"
|
marker = f"transport smoke test {uuid.uuid4().hex}"
|
||||||
transport = MatrixTransport(config)
|
transport = MatrixTransport(config)
|
||||||
try:
|
try:
|
||||||
|
_assert_testing_identity(transport, config)
|
||||||
transport.send_message(marker)
|
transport.send_message(marker)
|
||||||
response = transport._http.get(
|
response = transport._http.get(
|
||||||
f"/rooms/{config.room_id}/messages",
|
f"/rooms/{config.room_id}/messages",
|
||||||
|
|||||||
Reference in new issue
Block a user