Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6, RustFS and RabbitMQ configuration, migrations, hooks,
scenario scripts and the CI job from the lab 5 solution commit 64d5c67,
keep the lab 5 Makefile targets on top of the unchanged skeleton
targets, and append the lab 5 solution variables to the skeleton
.env.example. The package and the application follow the contract
version 1.6.0, and the image, the throwaway test containers and the
broker vhost description are tagged lab6 so they do not collide with a
lab 5 stand on the same host.
This is the starting point of the lab 6 cycle: lint, own tests and the
offline skeleton check pass before any lab 6 change.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from datetime import UTC, datetime
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from messenger.messaging.domain.errors import InvalidPageRequest
|
|
from messenger.messaging.infrastructure.cursor import SignedCursorCodec
|
|
|
|
KEY = (datetime(2026, 5, 17, 12, 30, 45, 123456, tzinfo=UTC), uuid4().int)
|
|
|
|
|
|
def codec(secret: bytes = b"secret-for-tests") -> SignedCursorCodec:
|
|
return SignedCursorCodec(secret)
|
|
|
|
|
|
def test_roundtrip_preserves_key() -> None:
|
|
subject = codec()
|
|
assert subject.decode("messages:a", subject.encode("messages:a", KEY)) == KEY
|
|
|
|
|
|
def test_cursor_is_opaque() -> None:
|
|
encoded = codec().encode("messages:a", KEY)
|
|
assert "2026" not in encoded
|
|
assert str(KEY[1]) not in encoded
|
|
|
|
|
|
def test_cursor_from_another_scope_is_rejected() -> None:
|
|
subject = codec()
|
|
encoded = subject.encode("messages:chat-one", KEY)
|
|
with pytest.raises(InvalidPageRequest):
|
|
subject.decode("messages:chat-two", encoded)
|
|
|
|
|
|
def test_forged_cursor_is_rejected() -> None:
|
|
encoded = codec(b"one-secret").encode("messages:a", KEY)
|
|
with pytest.raises(InvalidPageRequest):
|
|
codec(b"another-secret").decode("messages:a", encoded)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"raw",
|
|
["", "garbage", "1.2.3", "2.1.2.3", "1.notanumber.ff.AAAA", "1.1.zz.AAAA"],
|
|
)
|
|
def test_broken_cursor_is_rejected(raw: str) -> None:
|
|
with pytest.raises(InvalidPageRequest):
|
|
codec().decode("messages:a", raw)
|
|
|
|
|
|
def test_tampered_payload_is_rejected() -> None:
|
|
subject = codec()
|
|
encoded = subject.encode("messages:a", KEY)
|
|
head, _, signature = encoded.rpartition(".")
|
|
version, micros, identifier = head.split(".")
|
|
tampered = f"{version}.{int(micros) + 1}.{identifier}.{signature}"
|
|
with pytest.raises(InvalidPageRequest):
|
|
subject.decode("messages:a", tampered)
|