Ensure sender_key_fetcher is called with id, not handle

merge-requests/131/head
Jason Robinson 2018-08-26 21:02:40 +03:00
rodzic 946e40c0bb
commit 89ba3f345b
4 zmienionych plików z 6 dodań i 5 usunięć

Wyświetl plik

@ -109,7 +109,7 @@ def element_to_objects(
# If relayable, fetch sender key for validation
entity._xml_tags = get_element_child_info(element, "tag")
if sender_key_fetcher:
entity._sender_key = sender_key_fetcher(entity.handle)
entity._sender_key = sender_key_fetcher(entity.actor_id)
else:
profile = retrieve_and_parse_profile(entity.handle)
if profile:

Wyświetl plik

@ -6,7 +6,7 @@ from Crypto.Signature import PKCS1_v1_5
from lxml import etree
from federation.exceptions import SignatureVerificationError
from federation.utils.diaspora import fetch_public_key
from federation.utils.diaspora import fetch_public_key, generate_diaspora_profile_id
from federation.utils.text import decode_if_bytes
NAMESPACE = "http://salmon-protocol.org/ns/magic-env"
@ -73,7 +73,8 @@ class MagicEnvelope:
def fetch_public_key(self):
if self.sender_key_fetcher:
self.public_key = self.sender_key_fetcher(self.author_handle)
actor_id = generate_diaspora_profile_id(self.author_handle)
self.public_key = self.sender_key_fetcher(actor_id)
return
self.public_key = fetch_public_key(self.author_handle)

Wyświetl plik

@ -209,7 +209,7 @@ class TestDiasporaEntityMappersReceive:
def test_element_to_objects_calls_sender_key_fetcher(self, mock_validate):
mock_fetcher = Mock()
message_to_objects(DIASPORA_POST_COMMENT, "diaspora://alice@alice.diaspora.example.org/profile/", mock_fetcher)
mock_fetcher.assert_called_once_with("alice@alice.diaspora.example.org")
mock_fetcher.assert_called_once_with("diaspora://alice@alice.diaspora.example.org/profile/")
@patch("federation.entities.diaspora.mappers.DiasporaComment._validate_signatures")
@patch("federation.entities.diaspora.mappers.retrieve_and_parse_profile")

Wyświetl plik

@ -45,7 +45,7 @@ class TestMagicEnvelope:
mock_fetcher = Mock(return_value="public key")
env = MagicEnvelope(author_handle="spam@eggs", sender_key_fetcher=mock_fetcher)
env.fetch_public_key()
mock_fetcher.assert_called_once_with("spam@eggs")
mock_fetcher.assert_called_once_with("diaspora://spam@eggs/profile/")
assert not mock_fetch.called
@patch("federation.protocols.diaspora.magic_envelope.fetch_public_key", autospec=True)