Verified Commit abca719d authored by Agate's avatar Agate 💬

More fields on instance actor repr

parent 1e1ee2f6
Pipeline #632 passed with stage
in 2 minutes and 2 seconds
from django.urls import reverse
from django.conf import settings
from dynamic_preferences.registries import global_preferences_registry
from . import utils
......@@ -8,6 +10,10 @@ def repr_instance_actor():
"""
We do not use a serializer here, since it's pretty static
"""
actor_url = utils.full_url(reverse('federation:instance-actor'))
preferences = global_preferences_registry.manager()
public_key = preferences['federation__public_key']
return {
'@context': [
'https://www.w3.org/ns/activitystreams',
......@@ -18,4 +24,15 @@ def repr_instance_actor():
'type': 'Service',
'inbox': utils.full_url(reverse('federation:instance-inbox')),
'outbox': utils.full_url(reverse('federation:instance-outbox')),
'preferredUsername': 'service',
'name': 'Service Bot - {}'.format(settings.FEDERATION_HOSTNAME),
'summary': 'Bot account for federating with {}'.format(
settings.FEDERATION_HOSTNAME
),
'publicKey': {
'id': '{}#main-key'.format(actor_url),
'owner': actor_url,
'publicKeyPem': public_key
},
}
from django.urls import reverse
from funkwhale_api.federation import keys
from funkwhale_api.federation import serializers
def test_repr_instance_actor(db, preferences, settings):
_, public_key = keys.get_key_pair()
preferences['federation__public_key'] = public_key.decode('utf-8')
settings.FEDERATION_HOSTNAME = 'test.federation'
settings.FUNKWHALE_URL = 'https://test.federation'
actor_url = settings.FUNKWHALE_URL + reverse('federation:instance-actor')
inbox_url = settings.FUNKWHALE_URL + reverse('federation:instance-inbox')
outbox_url = settings.FUNKWHALE_URL + reverse('federation:instance-outbox')
expected = {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
{},
],
'id': actor_url,
'type': 'Service',
'preferredUsername': 'service',
'name': 'Service Bot - test.federation',
'summary': 'Bot account for federating with test.federation',
'inbox': inbox_url,
'outbox': outbox_url,
'publicKey': {
'id': '{}#main-key'.format(actor_url),
'owner': actor_url,
'publicKeyPem': public_key.decode('utf-8')
},
}
assert expected == serializers.repr_instance_actor()
......@@ -2,6 +2,7 @@ from django.urls import reverse
import pytest
from funkwhale_api.federation import serializers
from funkwhale_api.federation import webfinger
......@@ -9,21 +10,9 @@ def test_instance_actor(db, settings, api_client):
settings.FUNKWHALE_URL = 'http://test.com'
url = reverse('federation:instance-actor')
response = api_client.get(url)
assert response.data['id'] == (
settings.FUNKWHALE_URL + url
)
assert response.data['type'] == 'Service'
assert response.data['inbox'] == (
settings.FUNKWHALE_URL + reverse('federation:instance-inbox')
)
assert response.data['outbox'] == (
settings.FUNKWHALE_URL + reverse('federation:instance-outbox')
)
assert response.data['@context'] == [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
{},
]
assert response.status_code == 200
assert response.data == serializers.repr_instance_actor()
@pytest.mark.parametrize('route', [
......
......@@ -54,12 +54,12 @@ def test_service_serializer(settings):
'links': [
{
'rel': 'self',
'href': 'https://test.federation/instance/actor',
'href': 'https://test.federation/federation/instance/actor',
'type': 'application/activity+json',
}
],
'aliases': [
'https://test.federation/instance/actor',
'https://test.federation/federation/instance/actor',
]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment