Create test in outbox passes

2019-08-17
Marnanel Thurman 2019-07-19 22:13:48 +01:00
rodzic 7b3c1125cd
commit 7ed917764e
1 zmienionych plików z 66 dodań i 12 usunięć

Wyświetl plik

@ -1,7 +1,6 @@
from django.test import TestCase
from unittest import skip
from tests import create_local_note, create_local_person, \
create_remote_person, test_message_body_and_headers
from tests import *
from django_kepi.create import create
from django_kepi.models.audience import Audience, AUDIENCE_FIELD_NAMES
from django_kepi.models.mention import Mention
@ -18,8 +17,8 @@ SENDER_DOMAIN = urlparse(SENDER_ID).netloc
SENDER_FOLLOWERS = SENDER_ID + 'followers'
SENDER_KEY = SENDER_ID + '#main-key'
RECIPIENT_ID = 'https://altair.example.com/users/alice'
OUTBOX = RECIPIENT_ID+'/outbox'
ALICE_ID = 'https://testserver/users/alice'
OUTBOX = ALICE_ID+'/outbox'
OUTBOX_PATH = '/users/alice/outbox'
# as given in https://www.w3.org/TR/activitypub/
@ -27,7 +26,7 @@ OBJECT_FORM = {
"@context": ["https://www.w3.org/ns/activitystreams",
{"@language": "en"}],
"type": "Note",
'attributedTo': SENDER_ID,
'attributedTo': ALICE_ID,
"name": "Chris liked 'Minimal ActivityPub update client'",
"object": "https://rhiaro.co.uk/2016/05/minimal-activitypub",
"to": ["https://rhiaro.co.uk/#amy",
@ -38,8 +37,8 @@ OBJECT_FORM = {
CREATE_FORM = {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': SENDER_ID + '#foo',
'actor': SENDER_ID,
'id': ALICE_ID + '#foo',
'actor': ALICE_ID,
'type': 'Create',
'object': OBJECT_FORM,
}
@ -48,6 +47,42 @@ logger = logging.getLogger(name='django_kepi')
class TestOutbox(TestCase):
def _send(self,
content,
keys = None,
sender = None):
if keys is None:
keys = json.load(open('tests/keys/keys-0001.json', 'r'))
if sender is None:
sender = create_local_person(
name = 'alice',
publicKey = keys['public'],
privateKey = keys['private'],
)
f_body = dict([('f_'+f,v) for f,v in content.items()])
body, headers = test_message_body_and_headers(
secret = keys['private'],
path = OUTBOX_PATH,
key_id = sender['name']+'#main-key',
**f_body,
)
headers=dict([('HTTP_'+f,v) for f,v in headers.items()])
c = Client()
response = c.post(OUTBOX,
body,
**headers,
content_type='application/activity+json',
)
return response
@skip("not finished")
def test_no_signature(self):
c = Client()
@ -57,15 +92,31 @@ class TestOutbox(TestCase):
)
statuses = Item.objects.filter(
f_attributedTo=json.dumps(SENDER_ID),
f_attributedTo=json.dumps(ALICE_ID),
)
self.assertEqual(
statuses,
[])
def test_create(self):
self._send(
content = CREATE_FORM,
)
statuses = Item.objects.filter(
f_attributedTo=json.dumps(ALICE_ID),
)
self.assertEqual(
len(statuses),
0)
1)
@skip("not finished")
@httpretty.activate
def test_create(self):
def test_post_by_interloper(self):
body = dict([('f_'+f,v) for f,v in CREATE_FORM.items()])
@ -104,19 +155,22 @@ class TestOutbox(TestCase):
len(statuses),
1)
@skip("not finished")
@httpretty.activate
def test_unwrapped_object(self):
keys = json.load(open('tests/keys/keys-0001.json', 'r'))
body, headers = test_message_body_and_headers(
key_id = ALICE_ID+'#main-key',
secret = keys['private'],
path = OUTBOX_PATH,
)
print(body, headers)
c = Client()
response = c.post(OUTBOX,
json.dumps(OBJECT_FORM),
bytes(json.dumps(OBJECT_FORM), encoding='UTF-8'),
content_type='application/activity+json',
headers=dict([('HTTP_'+f,v) for f,v in headers.items()])
)
statuses = Item.objects.filter(