funkwhale/api/tests/federation/test_authentication.py

40 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

2018-06-10 08:55:16 +00:00
from funkwhale_api.federation import authentication, keys
2018-04-03 21:25:44 +00:00
def test_authenticate(factories, mocker, api_request):
private, public = keys.get_key_pair()
2018-06-09 13:36:16 +00:00
actor_url = "https://test.federation/actor"
mocker.patch(
2018-06-09 13:36:16 +00:00
"funkwhale_api.federation.actors.get_actor_data",
return_value={
2018-06-09 13:36:16 +00:00
"id": actor_url,
"type": "Person",
"outbox": "https://test.com",
"inbox": "https://test.com",
"preferredUsername": "test",
"publicKey": {
"publicKeyPem": public.decode("utf-8"),
"owner": actor_url,
"id": actor_url + "#main-key",
},
},
)
signed_request = factories["federation.SignedRequest"](
auth__key=private, auth__key_id=actor_url + "#main-key", auth__headers=["date"]
)
prepared = signed_request.prepare()
django_request = api_request.get(
2018-06-09 13:36:16 +00:00
"/",
**{
2018-06-09 13:36:16 +00:00
"HTTP_DATE": prepared.headers["date"],
"HTTP_SIGNATURE": prepared.headers["signature"],
}
)
authenticator = authentication.SignatureAuthentication()
user, _ = authenticator.authenticate(django_request)
actor = django_request.actor
assert user.is_anonymous is True
2018-06-09 13:36:16 +00:00
assert actor.public_key == public.decode("utf-8")
assert actor.fid == actor_url