247 lines
5.8 KiB
Python
247 lines
5.8 KiB
Python
|
import aputils
|
||
|
import unittest
|
||
|
|
||
|
from . import scriptpath
|
||
|
|
||
|
|
||
|
class ObjectsTest(unittest.TestCase):
|
||
|
def test_hostmeta(self):
|
||
|
output = aputils.HostMeta.new('social.example.com')
|
||
|
data = f'''<?xml version="1.0" encoding="UTF-8">
|
||
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||
|
<Link rel="lrdd" template="https://social.example.com/.well-known/webfinger?resource={{uri}}" />
|
||
|
</XRD>'''
|
||
|
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
def test_hostmeta_json(self):
|
||
|
output = aputils.HostMetaJson.new('social.example.com')
|
||
|
data = {'links': [{'rel': 'lrdd', 'template': f'https://social.example.com/.well-known/webfinger?resource={{uri}}'}]}
|
||
|
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
def test_nodeinfo_20(self):
|
||
|
output = aputils.Nodeinfo.new(
|
||
|
name = 'ap-software',
|
||
|
version = '1.0.2',
|
||
|
protocols = ['activitypub'],
|
||
|
metadata = {'peers': ['social2.barkshark.xyz']},
|
||
|
open_regs = True,
|
||
|
users = 5,
|
||
|
halfyear = 5,
|
||
|
month = 2,
|
||
|
posts = 69,
|
||
|
comments = 420
|
||
|
)
|
||
|
|
||
|
data = {
|
||
|
'version': '2.0',
|
||
|
'software': {
|
||
|
'name': 'ap-software',
|
||
|
'version': '1.0.2'
|
||
|
},
|
||
|
'protocols': [
|
||
|
aputils.NodeinfoProtocol.ACTIVITYPUB
|
||
|
],
|
||
|
'services': {
|
||
|
'inbound': [],
|
||
|
'outbound': []
|
||
|
},
|
||
|
'openRegistrations': True,
|
||
|
'usage': {
|
||
|
'localPosts': 69,
|
||
|
'localComments': 420,
|
||
|
'users': {
|
||
|
'total': 5,
|
||
|
'activeHalfyear': 5,
|
||
|
'activeMonth': 2
|
||
|
}
|
||
|
},
|
||
|
'metadata': {
|
||
|
'peers': [
|
||
|
'social2.barkshark.xyz'
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
self.assertEqual(output['version'], '2.0')
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
|
||
|
def test_nodeinfo_21(self):
|
||
|
output = aputils.Nodeinfo.new(
|
||
|
name = 'ap-software',
|
||
|
version = '1.0.2',
|
||
|
protocols = ['activitypub'],
|
||
|
metadata = {'peers': ['social2.barkshark.xyz']},
|
||
|
open_regs = True,
|
||
|
users = 5,
|
||
|
halfyear = 5,
|
||
|
month = 2,
|
||
|
posts = 69,
|
||
|
comments = 420,
|
||
|
repo = 'https://git.example.com/example/ap-software',
|
||
|
homepage = 'https://social.example.com'
|
||
|
)
|
||
|
|
||
|
data = {
|
||
|
'version': '2.1',
|
||
|
'software': {
|
||
|
'name': 'ap-software',
|
||
|
'version': '1.0.2',
|
||
|
'repository': 'https://git.example.com/example/ap-software',
|
||
|
'homepage': 'https://social.example.com'
|
||
|
},
|
||
|
'protocols': [
|
||
|
aputils.NodeinfoProtocol.ACTIVITYPUB
|
||
|
],
|
||
|
'services': {
|
||
|
'inbound': [],
|
||
|
'outbound': []
|
||
|
},
|
||
|
'openRegistrations': True,
|
||
|
'usage': {
|
||
|
'localPosts': 69,
|
||
|
'localComments': 420,
|
||
|
'users': {
|
||
|
'total': 5,
|
||
|
'activeHalfyear': 5,
|
||
|
'activeMonth': 2
|
||
|
}
|
||
|
},
|
||
|
'metadata': {
|
||
|
'peers': [
|
||
|
'social2.barkshark.xyz'
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
self.assertEqual(output['version'], '2.1')
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
def test_webfinger_full(self):
|
||
|
output = aputils.Webfinger.new(
|
||
|
handle = 'merpinator',
|
||
|
domain = 'social.example.com',
|
||
|
actor = 'https://social.example.com/users/merpinator',
|
||
|
profile = 'https://social.example.com/@merpinator',
|
||
|
interaction = 'https://social.example.com/authorize_interaction?uri={uri}'
|
||
|
)
|
||
|
|
||
|
data = {
|
||
|
'subject': 'acct:merpinator@social.example.com',
|
||
|
'aliases': [
|
||
|
'https://social.example.com/users/merpinator',
|
||
|
'https://social.example.com/@merpinator'
|
||
|
],
|
||
|
'links': [
|
||
|
{
|
||
|
'rel': 'self',
|
||
|
'type': 'application/activity+json',
|
||
|
'href': 'https://social.example.com/users/merpinator'
|
||
|
},
|
||
|
{
|
||
|
'rel': 'http://webfinger.net/rel/profile-page',
|
||
|
'type': 'text/html',
|
||
|
'href': 'https://social.example.com/@merpinator'
|
||
|
},
|
||
|
{
|
||
|
'rel': 'http://ostatus.org/schema/1.0/subscribe',
|
||
|
'template': 'https://social.example.com/authorize_interaction?uri={uri}'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
|
||
|
self.assertEqual(output.handle, 'merpinator')
|
||
|
self.assertEqual(output.domain, 'social.example.com')
|
||
|
self.assertEqual(output.actor, 'https://social.example.com/users/merpinator')
|
||
|
self.assertEqual(output.profile, 'https://social.example.com/@merpinator')
|
||
|
self.assertEqual(output.interaction, 'https://social.example.com/authorize_interaction?uri={uri}')
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
def test_webfinger_profile(self):
|
||
|
output = aputils.Webfinger.new(
|
||
|
handle = 'merpinator',
|
||
|
domain = 'social.example.com',
|
||
|
actor = 'https://social.example.com/users/merpinator',
|
||
|
profile = 'https://social.example.com/@merpinator'
|
||
|
)
|
||
|
|
||
|
data = {
|
||
|
'subject': 'acct:merpinator@social.example.com',
|
||
|
'aliases': [
|
||
|
'https://social.example.com/users/merpinator',
|
||
|
'https://social.example.com/@merpinator'
|
||
|
],
|
||
|
'links': [
|
||
|
{
|
||
|
'rel': 'self',
|
||
|
'type': 'application/activity+json',
|
||
|
'href': 'https://social.example.com/users/merpinator'
|
||
|
},
|
||
|
{
|
||
|
'rel': 'http://webfinger.net/rel/profile-page',
|
||
|
'type': 'text/html',
|
||
|
'href': 'https://social.example.com/@merpinator'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
def test_webfinger_actor(self):
|
||
|
output = aputils.Webfinger.new(
|
||
|
handle = 'merpinator',
|
||
|
domain = 'social.example.com',
|
||
|
actor = 'https://social.example.com/users/merpinator'
|
||
|
)
|
||
|
|
||
|
data = {
|
||
|
'subject': 'acct:merpinator@social.example.com',
|
||
|
'aliases': [
|
||
|
'https://social.example.com/users/merpinator'
|
||
|
],
|
||
|
'links': [
|
||
|
{
|
||
|
'rel': 'self',
|
||
|
'type': 'application/activity+json',
|
||
|
'href': 'https://social.example.com/users/merpinator'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
|
||
|
self.assertEqual(output, data)
|
||
|
|
||
|
|
||
|
def test_wellknown_nodeinfo(self):
|
||
|
output = aputils.WellKnownNodeinfo.new_template(
|
||
|
domain = 'social.example.com',
|
||
|
path = '/nodeinfo',
|
||
|
v21 = True,
|
||
|
v20 = True
|
||
|
)
|
||
|
|
||
|
data = {
|
||
|
'links': [
|
||
|
{
|
||
|
'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||
|
'href': 'https://social.example.com/nodeinfo/2.0.json'
|
||
|
},
|
||
|
{
|
||
|
'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.1',
|
||
|
'href': 'https://social.example.com/nodeinfo/2.1.json'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
|
||
|
self.assertEqual(output.v20, 'https://social.example.com/nodeinfo/2.0.json')
|
||
|
self.assertEqual(output.v21, 'https://social.example.com/nodeinfo/2.1.json')
|
||
|
self.assertEqual(output, data)
|