Merge branch 'federation-tweaks' into 'develop'
Instance actor tweaks See merge request funkwhale/funkwhale!116
This commit is contained in:
commit
c57755fcaa
|
@ -40,7 +40,7 @@ The last step involves generating RSA private and public keys for signing
|
||||||
your instance requests on the federation. This can be done via::
|
your instance requests on the federation. This can be done via::
|
||||||
|
|
||||||
# on docker setups
|
# on docker setups
|
||||||
docker-compose --rm api python manage.py generate_keys --no-input
|
docker-compose run --rm api python manage.py generate_keys --no-input
|
||||||
|
|
||||||
# on non-docker setups
|
# on non-docker setups
|
||||||
source /srv/funkwhale/virtualenv/bin/activate
|
source /srv/funkwhale/virtualenv/bin/activate
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
from dynamic_preferences.registries import global_preferences_registry
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +10,10 @@ def repr_instance_actor():
|
||||||
"""
|
"""
|
||||||
We do not use a serializer here, since it's pretty static
|
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 {
|
return {
|
||||||
'@context': [
|
'@context': [
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
|
@ -18,4 +24,15 @@ def repr_instance_actor():
|
||||||
'type': 'Service',
|
'type': 'Service',
|
||||||
'inbox': utils.full_url(reverse('federation:instance-inbox')),
|
'inbox': utils.full_url(reverse('federation:instance-inbox')),
|
||||||
'outbox': utils.full_url(reverse('federation:instance-outbox')),
|
'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
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ from . import views
|
||||||
|
|
||||||
router = routers.SimpleRouter(trailing_slash=False)
|
router = routers.SimpleRouter(trailing_slash=False)
|
||||||
router.register(
|
router.register(
|
||||||
r'instance',
|
r'federation/instance',
|
||||||
views.InstanceViewSet,
|
views.InstanceViewSet,
|
||||||
'instance')
|
'instance')
|
||||||
router.register(
|
router.register(
|
||||||
|
|
|
@ -54,7 +54,7 @@ def nodb_factories():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def preferences(db):
|
def preferences(db, cache):
|
||||||
manager = global_preferences_registry.manager()
|
manager = global_preferences_registry.manager()
|
||||||
manager.all()
|
manager.all()
|
||||||
yield manager
|
yield manager
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
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
|
import pytest
|
||||||
|
|
||||||
|
from funkwhale_api.federation import serializers
|
||||||
from funkwhale_api.federation import webfinger
|
from funkwhale_api.federation import webfinger
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,21 +10,9 @@ def test_instance_actor(db, settings, api_client):
|
||||||
settings.FUNKWHALE_URL = 'http://test.com'
|
settings.FUNKWHALE_URL = 'http://test.com'
|
||||||
url = reverse('federation:instance-actor')
|
url = reverse('federation:instance-actor')
|
||||||
response = api_client.get(url)
|
response = api_client.get(url)
|
||||||
assert response.data['id'] == (
|
|
||||||
settings.FUNKWHALE_URL + url
|
assert response.status_code == 200
|
||||||
)
|
assert response.data == serializers.repr_instance_actor()
|
||||||
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',
|
|
||||||
{},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('route', [
|
@pytest.mark.parametrize('route', [
|
||||||
|
|
|
@ -54,12 +54,12 @@ def test_service_serializer(settings):
|
||||||
'links': [
|
'links': [
|
||||||
{
|
{
|
||||||
'rel': 'self',
|
'rel': 'self',
|
||||||
'href': 'https://test.federation/instance/actor',
|
'href': 'https://test.federation/federation/instance/actor',
|
||||||
'type': 'application/activity+json',
|
'type': 'application/activity+json',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'aliases': [
|
'aliases': [
|
||||||
'https://test.federation/instance/actor',
|
'https://test.federation/federation/instance/actor',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ module.exports = {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
ws: true,
|
ws: true,
|
||||||
filter: function (pathname, req) {
|
filter: function (pathname, req) {
|
||||||
let proxified = ['.well-known', 'staticfiles', 'media', 'instance', 'api']
|
let proxified = ['.well-known', 'staticfiles', 'media', 'federation', 'api']
|
||||||
let matches = proxified.filter(e => {
|
let matches = proxified.filter(e => {
|
||||||
return pathname.match(`^/${e}`)
|
return pathname.match(`^/${e}`)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue