diff options
author | Andrew Godwin | 2022-12-17 12:00:47 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-17 12:00:47 -0700 |
commit | 62f2b867b9dbdfde6be79b729515711c5c2cd877 (patch) | |
tree | 284fe76602d3afdee41d7840fda04aae12ac08c7 /tests/users | |
parent | d7ffb47fb2d973fd2d6eea09c57fd3620d6b6af1 (diff) | |
download | takahe-62f2b867b9dbdfde6be79b729515711c5c2cd877.tar.gz takahe-62f2b867b9dbdfde6be79b729515711c5c2cd877.tar.bz2 takahe-62f2b867b9dbdfde6be79b729515711c5c2cd877.zip |
Fix serving of system actor
Fixes #183
Diffstat (limited to 'tests/users')
-rw-r--r-- | tests/users/models/test_system_actor.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/users/models/test_system_actor.py b/tests/users/models/test_system_actor.py new file mode 100644 index 0000000..855d2f6 --- /dev/null +++ b/tests/users/models/test_system_actor.py @@ -0,0 +1,33 @@ +import pytest +from asgiref.sync import async_to_sync +from django.test.client import RequestFactory +from pytest_httpx import HTTPXMock + +from core.signatures import HttpSignature +from users.models import SystemActor + + +@pytest.mark.django_db +def test_system_actor_signed(config_system, httpx_mock: HTTPXMock): + """ + Tests that the system actor signs requests properly + """ + system_actor = SystemActor() + system_actor.generate_keys() + # Send a fake outbound request + httpx_mock.add_response() + async_to_sync(system_actor.signed_request)( + method="get", + uri="http://example.com/test-actor", + ) + # Retrieve it and construct a fake request object + outbound_request = httpx_mock.get_request() + fake_request = RequestFactory().get( + path="/test-actor", + HTTP_HOST="example.com", + HTTP_DATE=outbound_request.headers["date"], + HTTP_SIGNATURE=outbound_request.headers["signature"], + HTTP_ACCEPT=outbound_request.headers["accept"], + ) + # Verify that + HttpSignature.verify_request(fake_request, system_actor.public_key) |