marnanel-wip
Marnanel Thurman 2023-11-01 19:19:53 +00:00
rodzic 2f749b6ed6
commit e0d9938857
2 zmienionych plików z 37 dodań i 12 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
from socketserver import TCPServer
from fastcgi.core import FcgiHandler
import re
import json
import logging
from kepi.config import config, subcommand
@ -12,9 +13,14 @@ logger = logging.getLogger('kepi.fastcgi')
CONTENTTYPE_ACTIVITY = 'application/activity+json'
CONTENTTYPE_HTML = 'text/html'
CONTENTTYPE_HOST_META = 'application/xrd+xml'
CONTENTTYPE_NODEINFO = (
'application/json; '
'profile=http://nodeinfo.diaspora.software/ns/schema/2.0#'
)
USER_PAGE_RE = r'users/([a-z0-9-]+)/?'
HOST_META_URI = '/.well-known/host-meta'
NODEINFO_PART_1_URI = '/.well-known/nodeinfo'
ERROR_404 = """Content-Type: text/html
Status: 404 Not found
@ -83,6 +89,24 @@ Status: 200 OK
return result
def despatch_nodeinfo_part_1(env, match):
message = {
'links': [
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
"href": f"https://{env['SERVER_NAME']}/nodeinfo.json",
},
],
}
result = f"""Content-Type: {CONTENTTYPE_NODEINFO}
Status: 200 OK
"""+json.dumps(message)
return result
def despatch(env):
# XXX Here we check HTTP_ACCEPT
# XXX and DOCUMENT_URI and possibly QUERY_STRING
@ -106,6 +130,7 @@ def despatch(env):
for regex, handler in [
(USER_PAGE_RE, despatch_user_page),
(HOST_META_URI, despatch_host_meta),
(NODEINFO_PART_1_URI, despatch_nodeinfo_part_1),
]:
match = re.match(regex, uri)

Wyświetl plik

@ -14,14 +14,14 @@ HTML_MIMETYPE = 'text/html'
HOST_META_URI = '/.well-known/host-meta'
HOST_META_MIMETYPE = 'application/xrd+xml'
NODEINFO_PART_1_URI = 'http://testserver/.well-known/nodeinfo'
NODEINFO_PART_2_URI = 'http://testserver/nodeinfo.json'
NODEINFO_PART_1_URI = '/.well-known/nodeinfo'
NODEINFO_PART_2_URI = '/nodeinfo.json'
NODEINFO_MIMETYPE = (
'application/json; '
'profile=http://nodeinfo.diaspora.software/ns/schema/2.0#'
)
WEBFINGER_BASE_URI = 'https://altair.example.com/.well-known/webfinger'
WEBFINGER_BASE_URI = '/.well-known/webfinger'
WEBFINGER_URI = WEBFINGER_BASE_URI + '?resource={}'
WEBFINGER_MIMETYPE = 'application/jrd+json; charset=utf-8'
@ -56,31 +56,31 @@ def test_fastcgi_host_meta():
"https://wombles.example.org/.well-known/webfinger?resource={uri}"
) in found.get_payload()
def test_nodeinfo_part_1(self):
def test_fastcgi_nodeinfo_part_1():
found = call_despatch_and_parse_result(
env = {
'DOCUMENT_URI': NODEINFO_PART_1_URI,
'ACCEPT': NODEINFO_MIMETYPE,
'SERVER_NAME': 'wombles.example.org',
},
)
assert found['Status'].startswith('200 ')
assert found['Content-Type']==NODEINFO_MIMETYPE
response = json.loads(response.body)
response = json.loads(found.get_payload())
assert 'links' in response
assert (
assert response['links'] == [
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
"href": NODEINFO_PART_2_URI,
"href": "https://wombles.example.org"+NODEINFO_PART_2_URI,
},
response['links'],
) in response
]
def test_part_2(self):
def test_fastcgi_nodeinfo_part_2():
found = call_despatch_and_parse_result(
env = {
@ -92,7 +92,7 @@ def test_part_2(self):
assert found['Status'].startswith('200 ')
assert found['Content-Type']==NODEINFO_MIMETYPE
response = json.loads(response.body)
response = json.loads(found.body)
assert response['version']=='2.0'
assert response['software']['name']=='kepi'
@ -100,7 +100,7 @@ def test_part_2(self):
"""
From the original: we need to do this before the tests which get 200
def setUp(self):
def setUp():
keys = json.load(open('kepi/bowler_pub/tests/keys/keys-0001.json', 'r'))
create_local_person(