From d88b7869fe5d5b97339577dbbf37de346b868e01 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Mon, 7 May 2018 22:28:46 +0200 Subject: [PATCH] See #192: added .well-known/nodeinfo endpoint --- api/funkwhale_api/federation/views.py | 20 +++++++++++++++++++- api/tests/federation/test_views.py | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/api/funkwhale_api/federation/views.py b/api/funkwhale_api/federation/views.py index 9b51a534d..ef581408c 100644 --- a/api/funkwhale_api/federation/views.py +++ b/api/funkwhale_api/federation/views.py @@ -85,13 +85,31 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet): return response.Response({}, status=200) -class WellKnownViewSet(FederationMixin, viewsets.GenericViewSet): +class WellKnownViewSet(viewsets.GenericViewSet): authentication_classes = [] permission_classes = [] renderer_classes = [renderers.WebfingerRenderer] + @list_route(methods=['get']) + def nodeinfo(self, request, *args, **kwargs): + if not preferences.get('instance__nodeinfo_enabled'): + return HttpResponse(status=404) + data = { + 'links': [ + { + 'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0', + 'href': utils.full_url( + reverse('api:v1:instance:nodeinfo-2.0') + ) + } + ] + } + return response.Response(data) + @list_route(methods=['get']) def webfinger(self, request, *args, **kwargs): + if not preferences.get('federation__enabled'): + return HttpResponse(status=405) try: resource_type, resource = webfinger.clean_resource( request.GET['resource']) diff --git a/api/tests/federation/test_views.py b/api/tests/federation/test_views.py index 09ecfc8ff..cc81f0657 100644 --- a/api/tests/federation/test_views.py +++ b/api/tests/federation/test_views.py @@ -70,6 +70,32 @@ def test_wellknown_webfinger_system( assert response.data == serializer.data +def test_wellknown_nodeinfo(db, preferences, api_client, settings): + expected = { + 'links': [ + { + 'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0', + 'href': '{}{}'.format( + settings.FUNKWHALE_URL, + reverse('api:v1:instance:nodeinfo-2.0') + ) + } + ] + } + url = reverse('federation:well-known-nodeinfo') + response = api_client.get(url) + assert response.status_code == 200 + assert response['Content-Type'] == 'application/jrd+json' + assert response.data == expected + + +def test_wellknown_nodeinfo_disabled(db, preferences, api_client): + preferences['instance__nodeinfo_enabled'] = False + url = reverse('federation:well-known-nodeinfo') + response = api_client.get(url) + assert response.status_code == 404 + + def test_audio_file_list_requires_authenticated_actor( db, preferences, api_client): preferences['federation__music_needs_approval'] = True