kopia lustrzana https://gitlab.com/marnanel/chapeau
Added view for host-meta, and a test for it, which passes.
Moved views.py into views/activitypub.py, so we can have a separate file for the host-meta view. views/activitypub.py should be split up further at some point.2019-08-17
rodzic
9f04e85577
commit
71e97f6554
|
@ -12,5 +12,10 @@ urlpatterns = [
|
|||
path('users/<str:username>/followers', django_kepi.views.FollowersView.as_view()),
|
||||
path('users/<str:username>/following', django_kepi.views.FollowingView.as_view()),
|
||||
path('sharedInbox', django_kepi.views.InboxView.as_view()),
|
||||
|
||||
# XXX We might want to split out the patterns that HAVE to be
|
||||
# at the root.
|
||||
|
||||
path('.well-known/host-meta', django_kepi.views.HostMeta.as_view()),
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
from .activitypub import KepiView, ThingView, ActorView, \
|
||||
FollowersView, FollowingView, \
|
||||
AllUsersView, \
|
||||
UserCollectionView, \
|
||||
InboxView, OutboxView
|
||||
|
||||
from .host_meta import HostMeta
|
||||
|
||||
__all__ = [
|
||||
'KepiView', 'ThingView', 'ActorView',
|
||||
'FollowersView', 'FollowingView',
|
||||
'AllUsersView',
|
||||
'UserCollectionView',
|
||||
'InboxView', 'OutboxView',
|
||||
|
||||
'HostMeta',
|
||||
]
|
|
@ -0,0 +1,25 @@
|
|||
import django.views
|
||||
from django.shortcuts import render
|
||||
import logging
|
||||
|
||||
logger = logging.Logger('django_kepi')
|
||||
|
||||
class HostMeta(django.views.View):
|
||||
|
||||
def get(self, request):
|
||||
|
||||
logger.info('Returning host-meta.xml')
|
||||
|
||||
context = {
|
||||
'hostname': request.get_host(),
|
||||
}
|
||||
|
||||
result = render(
|
||||
request=request,
|
||||
template_name='host-meta.xml',
|
||||
context=context,
|
||||
content_type='application/xrd+xml',
|
||||
)
|
||||
|
||||
return result
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
from django.conf import settings
|
||||
from django.test import TestCase, Client
|
||||
import logging
|
||||
import json
|
||||
|
||||
HOST_META_URL = 'https://altair.example.com/.well-known/host-meta'
|
||||
HOST_META_MIME_TYPE = 'application/xrd+xml'
|
||||
|
||||
logger = logging.getLogger(name='django_kepi')
|
||||
|
||||
class TestHostMeta(TestCase):
|
||||
|
||||
def test_host_meta(self):
|
||||
|
||||
logger.debug('Get host-meta from %s',
|
||||
HOST_META_URL)
|
||||
|
||||
settings.ALLOWED_HOSTS = [
|
||||
'altair.example.com',
|
||||
'testserver',
|
||||
]
|
||||
|
||||
client = Client()
|
||||
response = client.get(HOST_META_URL,
|
||||
HTTP_ACCEPT = HOST_META_MIME_TYPE,
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self.assertEqual(response['Content-Type'],
|
||||
HOST_META_MIME_TYPE)
|
||||
|
||||
self.assertIn(
|
||||
"/.well-known/webfinger?resource={uri}",
|
||||
str(response.content, encoding='UTF-8'))
|
Ładowanie…
Reference in New Issue