kopia lustrzana https://gitlab.com/marnanel/chapeau
rm old code
rodzic
47d2989d29
commit
b57fafb7a8
|
@ -10,7 +10,6 @@ import logging
|
|||
|
||||
logger = logging.getLogger(name='django_kepi')
|
||||
|
||||
#@skip("none of these tests sign their messages, so they all fail")
|
||||
class TestInbox(TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
|
@ -142,83 +141,4 @@ class TestInbox(TestCase):
|
|||
self.assertFalse(
|
||||
IncomingMessage.objects.all().exists())
|
||||
|
||||
def _test_message(secret='', **fields):
|
||||
|
||||
body = dict([(f[2:],v) for f,v in fields.items() if f.startswith('f_')])
|
||||
body['@context'] = MESSAGE_CONTEXT
|
||||
body['Host'] = INBOX_HOST
|
||||
|
||||
headers = {
|
||||
'content-type': "application/activity+json",
|
||||
'date': "Thu, 04 Apr 2019 21:12:11 GMT",
|
||||
'host': INBOX_HOST,
|
||||
}
|
||||
|
||||
if 'key_id' in fields:
|
||||
key_id = fields['key_id']
|
||||
else:
|
||||
key_id = body['actor']+'#main-key'
|
||||
|
||||
signer = httpsig.HeaderSigner(
|
||||
secret=secret,
|
||||
algorithm='rsa-sha256',
|
||||
key_id = key_id,
|
||||
headers=['(request-target)', 'host', 'date', 'content-type'],
|
||||
)
|
||||
|
||||
headers = signer.sign(
|
||||
headers,
|
||||
method='POST',
|
||||
path=INBOX_PATH,
|
||||
)
|
||||
|
||||
SIGNATURE = 'Signature'
|
||||
if headers['Authorization'].startswith(SIGNATURE):
|
||||
headers['Signature'] = headers['Authorization'][len(SIGNATURE)+1:]
|
||||
|
||||
result = IncomingMessage(
|
||||
content_type = headers['content-type'],
|
||||
date = headers['date'],
|
||||
digest = '', # FIXME ???
|
||||
host = headers['host'],
|
||||
path = INBOX_PATH,
|
||||
signature = headers['Signature'],
|
||||
body = json.dumps(body, sort_keys=True),
|
||||
)
|
||||
|
||||
result.save()
|
||||
return result
|
||||
|
||||
def _remote_user(url, name,
|
||||
publicKey='',
|
||||
inbox=None,
|
||||
sharedInbox=None,
|
||||
):
|
||||
result = {
|
||||
'@context': MESSAGE_CONTEXT,
|
||||
'id': url,
|
||||
'type': 'Person',
|
||||
'following': '',
|
||||
'followers': '',
|
||||
'outbox': '',
|
||||
'featured': '',
|
||||
'preferredUsername': name,
|
||||
'url': url,
|
||||
'publicKey': {
|
||||
'id': url+'#main-key',
|
||||
'owner': url,
|
||||
'publicKeyPem': publicKey,
|
||||
},
|
||||
}
|
||||
|
||||
if inbox is not None:
|
||||
result['inbox'] = inbox
|
||||
|
||||
if sharedInbox is not None:
|
||||
result['endpoints'] = {
|
||||
'sharedInbox': sharedInbox,
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue