kopia lustrzana https://gitlab.com/jaywink/federation
Create controllers.handle_create_payload - but only for diaspora now
rodzic
eecb3e013f
commit
d2c565bc24
|
@ -1,7 +1,7 @@
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
from federation.exceptions import NoSuitableProtocolFoundError
|
from federation.exceptions import NoSuitableProtocolFoundError
|
||||||
|
from federation.protocols.diaspora.protocol import Protocol
|
||||||
|
|
||||||
PROTOCOLS = (
|
PROTOCOLS = (
|
||||||
"diaspora",
|
"diaspora",
|
||||||
|
@ -35,6 +35,20 @@ def handle_receive(payload, user=None, sender_key_fetcher=None):
|
||||||
return sender, found_protocol.PROTOCOL_NAME, entities
|
return sender, found_protocol.PROTOCOL_NAME, entities
|
||||||
|
|
||||||
|
|
||||||
def handle_send():
|
def handle_create_payload(from_user, to_user, entity):
|
||||||
"""Send."""
|
"""Create a payload with the correct protocol.
|
||||||
pass
|
|
||||||
|
Since we don't know the protocol, we need to first query the recipient. However, for a PoC implementation,
|
||||||
|
supporting only Diaspora, we're going to assume that for now.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
from_user (obj) - User sending the object
|
||||||
|
to_user (obj) - Contact entry to send to
|
||||||
|
entity (obj) - Entity object to send
|
||||||
|
|
||||||
|
`from_user` must have `private_key` and `handle` attributes.
|
||||||
|
`to_user` must have `key` attribute.
|
||||||
|
"""
|
||||||
|
protocol = Protocol()
|
||||||
|
data = protocol.build_send(from_user=from_user, to_user=to_user, entity=entity)
|
||||||
|
return data
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch, Mock
|
||||||
|
from Crypto.PublicKey import RSA
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from federation.controllers import handle_receive
|
from federation.controllers import handle_receive, handle_create_payload
|
||||||
|
from federation.entities.base import Post
|
||||||
from federation.exceptions import NoSuitableProtocolFoundError
|
from federation.exceptions import NoSuitableProtocolFoundError
|
||||||
from federation.protocols.diaspora.protocol import Protocol
|
from federation.protocols.diaspora.protocol import Protocol
|
||||||
from federation.tests.fixtures.payloads import UNENCRYPTED_DIASPORA_PAYLOAD
|
from federation.tests.fixtures.payloads import UNENCRYPTED_DIASPORA_PAYLOAD
|
||||||
|
@ -25,3 +27,17 @@ class TestHandleReceiveProtocolIdentification(object):
|
||||||
payload = "foobar"
|
payload = "foobar"
|
||||||
with pytest.raises(NoSuitableProtocolFoundError):
|
with pytest.raises(NoSuitableProtocolFoundError):
|
||||||
handle_receive(payload)
|
handle_receive(payload)
|
||||||
|
|
||||||
|
|
||||||
|
class TestHandleCreatePayloadBuildsAPayload(object):
|
||||||
|
|
||||||
|
def test_handle_create_payload_builds_an_xml(self):
|
||||||
|
from_user = Mock(private_key=RSA.generate(2048), handle="foobar@domain.tld")
|
||||||
|
to_user = Mock(key=RSA.generate(2048).publickey())
|
||||||
|
entity = Post()
|
||||||
|
data = handle_create_payload(from_user, to_user, entity)
|
||||||
|
assert len(data) > 0
|
||||||
|
parts = data.split("=")
|
||||||
|
assert len(parts) == 2
|
||||||
|
assert parts[0] == "xml"
|
||||||
|
assert len(parts[1]) > 0
|
||||||
|
|
Ładowanie…
Reference in New Issue