2018-09-16 20:42:27 +00:00
|
|
|
from django.test import TestCase, Client
|
|
|
|
from django_kepi.views import InboxView
|
2018-09-23 20:58:38 +00:00
|
|
|
from django_kepi.models import QuarantinedMessage, QuarantinedMessageNeeds
|
2018-09-16 20:42:27 +00:00
|
|
|
|
|
|
|
class TestInbox(TestCase):
|
|
|
|
|
|
|
|
def test_specific_post(self):
|
|
|
|
|
|
|
|
QuarantinedMessage.objects.all().delete()
|
|
|
|
|
|
|
|
c = Client()
|
|
|
|
|
|
|
|
c.post('/users/alice/inbox',
|
|
|
|
content_type = 'application/activity+json',
|
|
|
|
data = {
|
|
|
|
"id": "https://example.net/hello-world",
|
2018-09-23 20:58:38 +00:00
|
|
|
"actor": "https://users.example.net/mary",
|
|
|
|
"object": "https://things.example.org/lamb",
|
|
|
|
"type": "Like",
|
2018-09-16 20:42:27 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
QuarantinedMessage.objects.filter(username='alice').exists())
|
|
|
|
|
|
|
|
def test_shared_post(self):
|
|
|
|
|
|
|
|
QuarantinedMessage.objects.all().delete()
|
|
|
|
|
|
|
|
c = Client()
|
|
|
|
|
|
|
|
c.post('/sharedInbox',
|
|
|
|
content_type = 'application/activity+json',
|
|
|
|
data = {
|
|
|
|
"id": "https://example.net/hello-world",
|
2018-09-23 20:58:38 +00:00
|
|
|
"actor": "https://users.example.net/mary",
|
|
|
|
"object": "https://things.example.org/lamb",
|
|
|
|
"type": "Like",
|
2018-09-16 20:42:27 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
QuarantinedMessage.objects.filter(username=None).exists())
|
2018-09-23 20:58:38 +00:00
|
|
|
|
2018-09-27 15:38:41 +00:00
|
|
|
def test_non_json(self):
|
|
|
|
|
|
|
|
QuarantinedMessage.objects.all().delete()
|
|
|
|
|
|
|
|
c = Client()
|
|
|
|
|
|
|
|
c.post('/sharedInbox',
|
|
|
|
content_type = 'text/plain',
|
|
|
|
data = 'Hello',
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertFalse(
|
|
|
|
QuarantinedMessage.objects.all().exists())
|
|
|
|
|
|
|
|
def test_malformed_json(self):
|
|
|
|
|
|
|
|
QuarantinedMessage.objects.all().delete()
|
|
|
|
|
|
|
|
c = Client()
|
|
|
|
|
|
|
|
text = """{
|
|
|
|
"id": "https://example.net/hello-world",
|
|
|
|
"actor": "https://users.example.net/mary",
|
|
|
|
"object": "https://things.example.org/lamb",
|
|
|
|
"type": "Like"
|
|
|
|
}"""
|
|
|
|
|
|
|
|
c.post('/sharedInbox',
|
|
|
|
content_type = 'application/activity+json',
|
|
|
|
data = text,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
QuarantinedMessage.objects.all().exists())
|
|
|
|
|
|
|
|
QuarantinedMessage.objects.all().delete()
|
|
|
|
|
|
|
|
text = text[1:] # remove leading {, so the JSON is invalid
|
|
|
|
|
|
|
|
c.post('/sharedInbox',
|
|
|
|
content_type = 'application/activity+json',
|
|
|
|
data = text,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertFalse(
|
|
|
|
QuarantinedMessage.objects.all().exists())
|
|
|
|
|
|
|
|
|