2018-09-28 20:47:05 +00:00
|
|
|
from funkwhale_api.federation import actors, serializers
|
2018-03-31 13:47:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_actor_fetching(r_mock):
|
|
|
|
payload = {
|
2018-06-09 13:36:16 +00:00
|
|
|
"id": "https://actor.mock/users/actor#main-key",
|
|
|
|
"owner": "test",
|
|
|
|
"publicKeyPem": "test_pem",
|
2018-03-31 13:47:21 +00:00
|
|
|
}
|
2018-06-09 13:36:16 +00:00
|
|
|
actor_url = "https://actor.mock/"
|
2018-03-31 13:47:21 +00:00
|
|
|
r_mock.get(actor_url, json=payload)
|
|
|
|
r = actors.get_actor_data(actor_url)
|
|
|
|
|
|
|
|
assert r == payload
|
|
|
|
|
|
|
|
|
2019-04-11 09:25:17 +00:00
|
|
|
def test_get_actor(factories, r_mock, mocker):
|
|
|
|
update_domain_nodeinfo = mocker.patch(
|
|
|
|
"funkwhale_api.federation.tasks.update_domain_nodeinfo"
|
|
|
|
)
|
2018-06-09 13:36:16 +00:00
|
|
|
actor = factories["federation.Actor"].build()
|
2018-04-27 22:25:47 +00:00
|
|
|
payload = serializers.ActorSerializer(actor).data
|
2018-09-06 18:35:02 +00:00
|
|
|
r_mock.get(actor.fid, json=payload)
|
|
|
|
new_actor = actors.get_actor(actor.fid)
|
2018-04-27 22:25:47 +00:00
|
|
|
|
|
|
|
assert new_actor.pk is not None
|
|
|
|
assert serializers.ActorSerializer(new_actor).data == payload
|
2019-04-11 09:25:17 +00:00
|
|
|
update_domain_nodeinfo.assert_called_once_with(domain_name=new_actor.domain_id)
|
2018-04-27 22:25:47 +00:00
|
|
|
|
|
|
|
|
2018-04-28 03:55:21 +00:00
|
|
|
def test_get_actor_use_existing(factories, preferences, mocker):
|
2018-06-09 13:36:16 +00:00
|
|
|
preferences["federation__actor_fetch_delay"] = 60
|
|
|
|
actor = factories["federation.Actor"]()
|
|
|
|
get_data = mocker.patch("funkwhale_api.federation.actors.get_actor_data")
|
2018-09-06 18:35:02 +00:00
|
|
|
new_actor = actors.get_actor(actor.fid)
|
2018-04-27 22:25:47 +00:00
|
|
|
|
|
|
|
assert new_actor == actor
|
|
|
|
get_data.assert_not_called()
|
|
|
|
|
|
|
|
|
2018-04-28 03:55:21 +00:00
|
|
|
def test_get_actor_refresh(factories, preferences, mocker):
|
2018-06-09 13:36:16 +00:00
|
|
|
preferences["federation__actor_fetch_delay"] = 0
|
|
|
|
actor = factories["federation.Actor"]()
|
2018-04-27 22:25:47 +00:00
|
|
|
payload = serializers.ActorSerializer(actor).data
|
|
|
|
# actor changed their username in the meantime
|
2018-06-09 13:36:16 +00:00
|
|
|
payload["preferredUsername"] = "New me"
|
2018-06-10 09:27:38 +00:00
|
|
|
mocker.patch("funkwhale_api.federation.actors.get_actor_data", return_value=payload)
|
2018-09-06 18:35:02 +00:00
|
|
|
new_actor = actors.get_actor(actor.fid)
|
2018-04-27 22:25:47 +00:00
|
|
|
|
|
|
|
assert new_actor == actor
|
|
|
|
assert new_actor.last_fetch_date > actor.last_fetch_date
|
2018-06-09 13:36:16 +00:00
|
|
|
assert new_actor.preferred_username == "New me"
|
2019-01-30 10:54:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_service_actor(db, settings):
|
|
|
|
settings.FEDERATION_HOSTNAME = "test.hello"
|
|
|
|
settings.FEDERATION_SERVICE_ACTOR_USERNAME = "bob"
|
|
|
|
actor = actors.get_service_actor()
|
|
|
|
|
|
|
|
assert actor.preferred_username == "bob"
|
|
|
|
assert actor.domain.name == "test.hello"
|
|
|
|
assert actor.private_key is not None
|
|
|
|
assert actor.type == "Service"
|
|
|
|
assert actor.public_key is not None
|