示例#1
0
    def test_no_error_for_diaspora_entities_on_activitypub_recipients(
            self, mock_logger, mock_send, diasporacomment):
        key = get_dummy_private_key()
        diasporacomment.outbound_doc = diasporacomment.to_xml()
        recipients = [{
            "endpoint": "https://example.com/receive/public",
            "public": True,
            "protocol": "diaspora",
            "fid": "",
        }, {
            "endpoint": "https://example.net/inbox",
            "fid": "https://example.net/foobar",
            "public": True,
            "protocol": "activitypub",
        }]
        author = UserType(
            private_key=key,
            id="*****@*****.**",
            handle="*****@*****.**",
        )
        handle_send(diasporacomment, author, recipients)

        # Ensure first call is a public diaspora payload
        args, kwargs = mock_send.call_args_list[0]
        assert args[0] == "https://example.com/receive/public"

        # Should only be one call
        assert mock_send.call_count == 1

        # Ensure no error logged
        assert mock_logger.call_count == 0
示例#2
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     Profile.objects.filter(id=author.profile.id).update(rsa_private_key=get_dummy_private_key().exportKey())
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED, author=author.profile)
     cls.public_content = ContentFactory(visibility=Visibility.PUBLIC, author=author.profile)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
示例#3
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.profile = cls.user.profile
     cls.remote_profile = ProfileFactory(
         rsa_public_key=get_dummy_private_key().publickey().exportKey(),
     )
示例#4
0
 def test_build(self):
     env = MagicEnvelope(
         message="<status_message><foo>bar</foo></status_message>",
         private_key=get_dummy_private_key(),
         author_handle="*****@*****.**")
     doc = env.build()
     assert isinstance(doc, _Element)
示例#5
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.profile = cls.user.profile
     cls.remote_profile = ProfileFactory(
         rsa_public_key=get_dummy_private_key().publickey().exportKey(),
     )
示例#6
0
    def test_calls_handle_create_payload(self, mock_send, diasporapost):
        key = get_dummy_private_key()
        recipients = [
            ("diaspora://[email protected]/profile/xyz", key.publickey()),
            ("diaspora://foo@localhost/profile/abc", None),
            "diaspora://[email protected]/profile/zzz",
            "diaspora://[email protected]/profile/qwerty",  # Same host twice to ensure one delivery only per host
            # for public payloads
        ]
        mock_author = Mock(private_key=key, handle="*****@*****.**")
        handle_send(diasporapost, mock_author, recipients)

        # Ensure first call is a private payload
        args, kwargs = mock_send.call_args_list[0]
        assert args[0] == "https://127.0.0.1/receive/users/xyz"
        assert "aes_key" in args[1]
        assert "encrypted_magic_envelope" in args[1]
        assert kwargs['headers'] == {'Content-Type': 'application/json'}

        # Ensure public payloads and recipients, one per unique host
        args1, kwargs1 = mock_send.call_args_list[1]
        args2, kwargs2 = mock_send.call_args_list[2]
        public_endpoints = {args1[0], args2[0]}
        assert public_endpoints == {
            "https://example.net/receive/public",
            "https://localhost/receive/public"
        }
        assert args1[1].startswith("<me:env xmlns:me=")
        assert args2[1].startswith("<me:env xmlns:me=")
        assert kwargs1['headers'] == {
            'Content-Type': 'application/magic-envelope+xml'
        }
        assert kwargs2['headers'] == {
            'Content-Type': 'application/magic-envelope+xml'
        }
示例#7
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED)
     author = UserFactory()
     author.profile.rsa_private_key = get_dummy_private_key().exportKey()
     author.profile.save()
     cls.public_content = ContentFactory(visibility=Visibility.PUBLIC, author=author.profile)
     cls.profile = author.profile
示例#8
0
 def test_signing_like_works(self):
     entity = DiasporaLike(guid="guid", target_guid="target_guid", handle="handle")
     entity.sign(get_dummy_private_key())
     assert entity.signature == "apkcOn6marHfo0rHiOnQq+qqspxxWOJNklQKQjoJUHmXDNRnBp8aPoLKqVOznsTEpEIhM1p5/8mPilgY" \
                                "yVFHepi/m744DFQByx7hVkMhGFiZWtJx1tTWSl1d7H85FTlE0DyPwiRYVTrG3vQD3Dr+b08WiOEzG+ii" \
                                "Q0t+vWGl8cgSS0/34mvvqX+HKUdmun2vQ50bPckNLoj3hDI6HcmZ8qFf/xx8y1BbE0zx5rTo7yOlWq8Y" \
                                "sC28oRHqHpIzOfhkIHyt+hOjO/mpuZLd7qOPfIySnGW6hM1iKewoJVDuVMN5w5VB46ETRum8JpvTQO8i" \
                                "DPB+ZqbqcEasfm2CQIxVLA=="
示例#9
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED)
     author = UserFactory()
     author.profile.rsa_private_key = get_dummy_private_key().exportKey()
     author.profile.save()
     cls.public_content = ContentFactory(visibility=Visibility.PUBLIC, author=author.profile)
     cls.profile = author.profile
示例#10
0
 def test_encrypt(self):
     private_key = get_dummy_private_key()
     public_key = private_key.publickey()
     encrypted = EncryptedPayload.encrypt("<spam>eggs</spam>", public_key)
     assert "aes_key" in encrypted
     assert "encrypted_magic_envelope" in encrypted
     # See we can decrypt it too
     decrypted = EncryptedPayload.decrypt(encrypted, private_key)
     assert etree.tostring(decrypted).decode("utf-8") == "<spam>eggs</spam>"
示例#11
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     Profile.objects.filter(id=author.profile.id).update(
         rsa_private_key=get_dummy_private_key().exportKey().decode("utf-8")
     )
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED, author=author.profile)
     cls.public_content = ContentFactory(visibility=Visibility.PUBLIC, author=author.profile)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC, guid=uuid.uuid4())
示例#12
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     author.profile.rsa_private_key = get_dummy_private_key().exportKey()
     author.profile.save()
     cls.public_content = ContentFactory(visibility=Visibility.PUBLIC,
                                         author=author.profile)
     cls.remote_reply = ContentFactory(parent=cls.public_content,
                                       author=ProfileFactory())
     cls.reply = ContentFactory(parent=cls.public_content)
示例#13
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     author.profile.rsa_private_key = get_dummy_private_key().exportKey()
     author.profile.save()
     cls.public_content = PublicContentFactory(author=author.profile)
     cls.remote_reply = PublicContentFactory(parent=cls.public_content, author=ProfileFactory())
     cls.reply = PublicContentFactory(parent=cls.public_content)
     cls.share = PublicContentFactory(share_of=cls.public_content)
     cls.share_reply = PublicContentFactory(parent=cls.share)
示例#14
0
 def test_signing_comment_works(self, mock_format_dt):
     entity = DiasporaComment(
         raw_content="raw_content", guid="guid", target_guid="target_guid", handle="handle",
         created_at="created_at",
     )
     entity.sign(get_dummy_private_key())
     assert entity.signature == "OWvW/Yxw4uCnx0WDn0n5/B4uhyZ8Pr6h3FZaw8J7PCXyPluOfYXFoHO21bykP8c2aVnuJNHe+lmeAkUC" \
                                "/kHnl4yxk/jqe3uroW842OWvsyDRQ11vHxhIqNMjiepFPkZmXX3vqrYYh5FrC/tUsZrEc8hHoOIHXFR2" \
                                "kGD0gPV+4EEG6pbMNNZ+SBVun0hvruX8iKQVnBdc/+zUI9+T/MZmLyqTq/CvuPxDyHzQPSHi68N9rJyr" \
                                "4Xa1K+R33Xq8eHHxs8LVNRqzaHGeD3DX8yBu/vP9TYmZsiWlymbuGwLCa4Yfv/VS1hQZovhg6YTxV4CR" \
                                "v4ToGL+CAJ7UHEugRRBwDw=="
示例#15
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     Profile.objects.filter(id=author.profile.id).update(
         rsa_private_key=get_dummy_private_key().exportKey().decode("utf-8")
     )
     cls.public_content = ContentFactory(author=author.profile, visibility=Visibility.PUBLIC)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
     cls.remote_reply = ContentFactory(parent=cls.public_content, author=ProfileFactory())
     cls.reply = ContentFactory(parent=cls.public_content, author=author.profile)
     cls.reply2 = ContentFactory(parent=cls.remote_content, author=author.profile)
示例#16
0
 def test_build_send_uses_outbound_doc(self, mock_me):
     protocol = self.init_protocol()
     outbound_doc = etree.fromstring("<xml>foo</xml>")
     entity = Mock(outbound_doc=outbound_doc)
     from_user = UserType(
         id="*****@*****.**", private_key=get_dummy_private_key(), handle="*****@*****.**",
     )
     protocol.build_send(entity, from_user)
     mock_me.assert_called_once_with(
         b"<xml>foo</xml>", private_key=from_user.private_key, author_handle="*****@*****.**",
     )
示例#17
0
 def test_render(self):
     env = MagicEnvelope(
         message="<status_message><foo>bar</foo></status_message>",
         private_key=get_dummy_private_key(),
         author_handle="*****@*****.**")
     env.build()
     output = env.render()
     assert output == '<me:env xmlns:me="http://salmon-protocol.org/ns/magic-env"><me:encoding>base64url' \
                      '</me:encoding><me:alg>RSA-SHA256</me:alg><me:data type="application/xml">' \
                      'PHN0YXR1c19tZXNzYWdlPjxmb28-YmFyPC9mb28-PC9zdGF0dXNfbWVzc2FnZT4=</me:data>' \
                      '<me:sig key_id="Zm9vYmFyQGV4YW1wbGUuY29t">Cmk08MR4Tp8r9eVybD1hORcR_8NLRVxAu0biOfJbk' \
                      'I1xLx1c480zJ720cpVyKaF9CxVjW3lvlvRz5YbswMv0izPzfHpXoWTXH-4UPrXaGYyJnrNvqEB2UWn4iHK' \
                      'J2Rerto8sJY2b95qbXD6Nq75EoBNub5P7DYc16ENhp38YwBRnrBEvNOewddpOpEBVobyNB7no_QR8c_xkX' \
                      'ie-hUDFNwI0z7vax9HkaBFbvEmzFPMZAAdWyjxeGiWiqY0t2ZdZRCPTezy66X6Q0qc4I8kfT-Mt1ctjGmNM' \
                      'oJ4Lgu-PrO5hSRT4QBAVyxaog5w-B0PIPuC-mUW5SZLsnX3_ZuwJww==</me:sig></me:env>'
     env2 = MagicEnvelope(
         message="<status_message><foo>bar</foo></status_message>",
         private_key=get_dummy_private_key(),
         author_handle="*****@*****.**")
     output2 = env2.render()
     assert output2 == output
示例#18
0
def test_signing_request():
    key = get_dummy_private_key()
    auth = get_http_authentication(key, "dummy_key_id")
    assert auth.algorithm == 'rsa-sha256'
    assert auth.headers == [
        '(request-target)',
        'user-agent',
        'host',
        'date',
    ]
    assert auth.key == key.exportKey()
    assert auth.key_id == 'dummy_key_id'
示例#19
0
 def test_build_signature(self):
     env = MagicEnvelope(
         message="<status_message><foo>bar</foo></status_message>",
         private_key=get_dummy_private_key(),
         author_handle="*****@*****.**")
     env.create_payload()
     signature, key_id = env._build_signature()
     assert signature == b'Cmk08MR4Tp8r9eVybD1hORcR_8NLRVxAu0biOfJbkI1xLx1c480zJ720cpVyKaF9CxVjW3lvlvRz' \
                         b'5YbswMv0izPzfHpXoWTXH-4UPrXaGYyJnrNvqEB2UWn4iHKJ2Rerto8sJY2b95qbXD6Nq75EoBNu' \
                         b'b5P7DYc16ENhp38YwBRnrBEvNOewddpOpEBVobyNB7no_QR8c_xkXie-hUDFNwI0z7vax9HkaBFb' \
                         b'vEmzFPMZAAdWyjxeGiWiqY0t2ZdZRCPTezy66X6Q0qc4I8kfT-Mt1ctjGmNMoJ4Lgu-PrO5hSRT4' \
                         b'QBAVyxaog5w-B0PIPuC-mUW5SZLsnX3_ZuwJww=='
     assert key_id == b"Zm9vYmFyQGV4YW1wbGUuY29t"
示例#20
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     Profile.objects.filter(id=cls.profile.id).update(
         rsa_private_key=get_dummy_private_key().exportKey().decode("utf-8")
     )
     cls.content = ContentFactory(author=cls.remote_profile, visibility=Visibility.PUBLIC)
     cls.limited_content = ContentFactory(author=cls.remote_profile, visibility=Visibility.LIMITED)
     cls.share = ContentFactory(share_of=cls.content, author=cls.profile, visibility=Visibility.PUBLIC)
     cls.limited_share = ContentFactory(
         share_of=cls.limited_content, author=cls.profile, visibility=Visibility.LIMITED
     )
     cls.local_content = LocalContentFactory(visibility=Visibility.PUBLIC)
     cls.local_share = ContentFactory(share_of=cls.local_content, author=cls.profile, visibility=Visibility.PUBLIC)
示例#21
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     private_key = get_dummy_private_key().exportKey().decode("utf-8")
     Profile.objects.filter(id=author.profile.id).update(rsa_private_key=private_key)
     author.profile.refresh_from_db()
     cls.public_content = ContentFactory(author=author.profile, visibility=Visibility.PUBLIC)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
     cls.remote_profile = ProfileFactory(with_key=True)
     cls.remote_reply = ContentFactory(parent=cls.public_content, author=cls.remote_profile)
     cls.reply = ContentFactory(parent=cls.public_content, author=author.profile)
     cls.reply2 = ContentFactory(parent=cls.remote_content, author=author.profile)
     cls.limited_content = LimitedContentFactory(author=cls.remote_profile)
     cls.limited_reply = LimitedContentFactory(author=author.profile, parent=cls.limited_content)
示例#22
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     author.profile.rsa_private_key = get_dummy_private_key().exportKey()
     author.profile.save()
     cls.public_content = PublicContentFactory(author=author.profile)
     cls.remote_reply = PublicContentFactory(parent=cls.public_content, author=ProfileFactory())
     cls.reply = PublicContentFactory(parent=cls.public_content)
     cls.share = PublicContentFactory(share_of=cls.public_content)
     cls.share_reply = PublicContentFactory(parent=cls.share)
     cls.limited_content = LimitedContentFactory(author=author.profile)
     cls.limited_reply = LimitedContentFactory(parent=cls.limited_content)
     cls.remote_limited_reply = LimitedContentFactory(parent=cls.limited_content)
     cls.limited_content.limited_visibilities.set((cls.limited_reply.author, cls.remote_limited_reply.author))
示例#23
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     Profile.objects.filter(id=cls.profile.id).update(
         rsa_private_key=get_dummy_private_key().exportKey().decode("utf-8")
     )
     cls.profile.refresh_from_db()
     cls.content = ContentFactory(author=cls.remote_profile, visibility=Visibility.PUBLIC)
     cls.limited_content = ContentFactory(author=cls.remote_profile, visibility=Visibility.LIMITED)
     cls.share = ContentFactory(share_of=cls.content, author=cls.profile, visibility=Visibility.PUBLIC)
     cls.limited_share = ContentFactory(
         share_of=cls.limited_content, author=cls.profile, visibility=Visibility.LIMITED
     )
     cls.local_content = LocalContentFactory(visibility=Visibility.PUBLIC)
     cls.local_share = ContentFactory(share_of=cls.local_content, author=cls.profile, visibility=Visibility.PUBLIC)
示例#24
0
 def test_build_send_does_right_calls(self, mock_me):
     mock_render = Mock(return_value="rendered")
     mock_me_instance = Mock(render=mock_render)
     mock_me.return_value = mock_me_instance
     protocol = Protocol()
     entity = DiasporaPost()
     private_key = get_dummy_private_key()
     outbound_entity = get_outbound_entity(entity, private_key)
     data = protocol.build_send(outbound_entity, from_user=Mock(
         private_key=private_key, handle="johnny@localhost",
     ))
     mock_me.assert_called_once_with(
         etree.tostring(entity.to_xml()), private_key=private_key, author_handle="johnny@localhost",
     )
     mock_render.assert_called_once_with()
     assert data == "rendered"
示例#25
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     private_key = get_dummy_private_key().exportKey().decode("utf-8")
     Profile.objects.filter(id=author.profile.id).update(rsa_private_key=private_key)
     author.profile.refresh_from_db()
     cls.public_content = ContentFactory(author=author.profile, visibility=Visibility.PUBLIC)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
     cls.remote_profile = ProfileFactory(with_key=True)
     cls.remote_reply = ContentFactory(parent=cls.public_content, author=cls.remote_profile)
     cls.reply = ContentFactory(parent=cls.public_content, author=author.profile)
     cls.reply2 = ContentFactory(parent=cls.remote_content, author=author.profile)
     cls.limited_content = LimitedContentFactory(author=cls.remote_profile)
     cls.limited_local_content = LimitedContentFactory(author=author.profile)
     cls.limited_reply = LimitedContentFactory(author=author.profile, parent=cls.limited_content)
     cls.limited_local_reply = LimitedContentFactory(author=author.profile, parent=cls.limited_local_content)
     cls.limited_local_reply.limited_visibilities.add(cls.remote_profile)
示例#26
0
 def test_signing_comment_works(self, mock_format_dt):
     entity = DiasporaComment(
         raw_content="raw_content",
         created_at="created_at",
         actor_id="handle",
         handle="handle",
         id="guid",
         guid="guid",
         target_id="target_guid",
         target_guid="target_guid",
         root_target_id="target_guid",
         root_target_guid="target_guid",
     )
     entity.sign(get_dummy_private_key())
     assert entity.signature == "XZYggFdQHOicguZ0ReVJkYiK5othHgBgAtwnSmm4NR31qeLa76Ur/i2B5Xi9dtopDlNS8EbFy+MLJ1ds" \
                                "ovDjPsVC1nLZrL57y0v+HtwJas6hQqNbvmEyr1q6X+0p1i93eINzt/7bxcP5uEGxy8J4ItsJzbDVLlC5" \
                                "3ZtIg7pmhR0ltqNqBHrgL8WDokfGKFlXqANchbD+Xeyv2COGbI78LwplVdYjHW1+jefjpYhMCxayIvMv" \
                                "WS8TV1hMTqUz+zSqoCHU04RgjjGW8e8vINDblQwMfEMeJ5T6OP5RiU3zCqDc3uL2zxHHh9IGC+clVuhP" \
                                "HTv8tHUHNLgc2vIzRtGh6w=="
示例#27
0
 def test_build_send_does_right_calls__private_payload(self, mock_encrypt, mock_me):
     mock_render = Mock(return_value="rendered")
     mock_me_instance = Mock(render=mock_render)
     mock_me.return_value = mock_me_instance
     protocol = Protocol()
     entity = DiasporaPost()
     entity.validate = Mock()
     private_key = get_dummy_private_key()
     outbound_entity = get_outbound_entity(entity, private_key)
     data = protocol.build_send(outbound_entity, to_user_key="public key", from_user=UserType(
         private_key=private_key, id="johnny@localhost",
         handle="johnny@localhost",
     ))
     mock_me.assert_called_once_with(
         etree.tostring(entity.to_xml()), private_key=private_key, author_handle="johnny@localhost",
     )
     mock_render.assert_called_once_with()
     mock_encrypt.assert_called_once_with(
         "rendered", "public key",
     )
     assert data == "encrypted"
示例#28
0
    def test_survives_sending_share_if_diaspora_payload_cannot_be_created(
            self, mock_send, share):
        key = get_dummy_private_key()
        share.target_handle = None  # Ensure diaspora payload fails
        recipients = [{
            "endpoint": "https://example.com/receive/public",
            "public": True,
            "protocol": "diaspora",
            "fid": "",
        }, {
            "endpoint": "https://example.tld/receive/public",
            "public": True,
            "protocol": "diaspora",
            "fid": "",
        }, {
            "endpoint": "https://example.net/inbox",
            "fid": "https://example.net/foobar",
            "public": True,
            "protocol": "activitypub",
        }]
        author = UserType(
            private_key=key,
            id="*****@*****.**",
            handle="*****@*****.**",
        )
        handle_send(share, author, recipients)

        # Ensure first call is a public activitypub payload
        args, kwargs = mock_send.call_args_list[0]
        assert args[0] == "https://example.net/inbox"
        assert kwargs['headers'] == {
            'Content-Type':
            'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
        }
        assert encode_if_text(
            "https://www.w3.org/ns/activitystreams#Public") in args[1]

        # Should only be one call
        assert mock_send.call_count == 1
示例#29
0
 def test_sign_with_parent(self, mock_validate):
     entities = message_to_objects(DIASPORA_POST_COMMENT, "*****@*****.**",
                                   sender_key_fetcher=Mock())
     entity = entities[0]
     entity.sign_with_parent(get_dummy_private_key())
     assert entity.parent_signature == "UTIDiFZqjxfU6ssVlmjz2RwOD/WPmMTFv57qOm0BZvBhF8Ef49Ynse1c2XTtx3rs8DyRMn54" \
                                       "Uw4E0T+3t0Q5SHEQTLtRnOdRXrgNGAnlJ2xRmBWqe6xvvgc4nJ8OnffXhVgI8DBx6YUFRDjJ" \
                                       "fnVQhnqbWr4ZAcpywCyL9IDkap3cTyn6wHo2WFRtq5syTCtMS8RZLXgpVLCeMfHhrXlePIA/" \
                                       "YwMNn0GGi+9qSWXYVFG75cPjcWeY4t5q8EHCQReSSxG4a3HGbc7MigLvHzuhdOWOV8563dYo" \
                                       "/5xS3zlQUt8I3AwXOzHr+57r1egMBHYyXTXsS8gFisj7mH4TsLM+Yw=="
     assert etree.tostring(entity.outbound_doc) == b'<comment>\n      <guid>((guidguidguidguidguidguid))</guid>\n' \
                                                   b'      <parent_guid>((parent_guidparent_guidparent_guidparent' \
                                                   b'_guid))</parent_guid>\n      <author_signature>((base64-enco' \
                                                   b'ded data))</author_signature>\n      <text>((text))</text>\n' \
                                                   b'      <author>[email protected]</author>\n   ' \
                                                   b'   <author_signature>((signature))</author_signature>\n    ' \
                                                   b'<parent_author_signature>UTIDiFZqjxfU6ssVlmjz2RwOD/WPmMTFv57' \
                                                   b'qOm0BZvBhF8Ef49Ynse1c2XTtx3rs8DyRMn54Uw4E0T+3t0Q5SHEQTLtRnOd' \
                                                   b'RXrgNGAnlJ2xRmBWqe6xvvgc4nJ8OnffXhVgI8DBx6YUFRDjJfnVQhnqbWr4' \
                                                   b'ZAcpywCyL9IDkap3cTyn6wHo2WFRtq5syTCtMS8RZLXgpVLCeMfHhrXlePIA' \
                                                   b'/YwMNn0GGi+9qSWXYVFG75cPjcWeY4t5q8EHCQReSSxG4a3HGbc7MigLvHzu' \
                                                   b'hdOWOV8563dYo/5xS3zlQUt8I3AwXOzHr+57r1egMBHYyXTXsS8gFisj7mH4' \
                                                   b'TsLM+Yw==</parent_author_signature></comment>'
示例#30
0
 def __init__(self, nokey=False):
     if nokey:
         self.private_key = None
     else:
         self.private_key = get_dummy_private_key()
示例#31
0
def private_key():
    return get_dummy_private_key()
示例#32
0
    def test_calls_handle_create_payload(self, mock_send, profile):
        key = get_dummy_private_key()
        recipients = [
            {
                "endpoint": "https://127.0.0.1/receive/users/1234",
                "public_key": key.publickey(),
                "public": False,
                "protocol": "diaspora",
                "fid": "",
            },
            {
                "endpoint": "https://example.com/receive/public",
                "public": True,
                "protocol": "diaspora",
                "fid": "",
            },
            {
                "endpoint": "https://example.net/receive/public",
                "public": True,
                "protocol": "diaspora",
                "fid": "",
            },
            # Same twice to ensure one delivery only per unique
            {
                "endpoint": "https://example.net/receive/public",
                "public": True,
                "protocol": "diaspora",
                "fid": "",
            },
            {
                "endpoint": "https://example.net/foobar/inbox",
                "fid": "https://example.net/foobar",
                "public": False,
                "protocol": "activitypub",
            },
            {
                "endpoint": "https://example.net/inbox",
                "fid": "https://example.net/foobar",
                "public": True,
                "protocol": "activitypub",
            }
        ]
        author = UserType(
            private_key=key,
            id="*****@*****.**",
            handle="*****@*****.**",
        )
        handle_send(profile, author, recipients)

        # Ensure first call is a private diaspora payload
        args, kwargs = mock_send.call_args_list[0]
        assert args[0] == "https://127.0.0.1/receive/users/1234"
        assert "aes_key" in args[1]
        assert "encrypted_magic_envelope" in args[1]
        assert kwargs['headers'] == {'Content-Type': 'application/json'}

        # Ensure second call is a private activitypub payload
        args, kwargs = mock_send.call_args_list[1]
        assert args[0] == "https://example.net/foobar/inbox"
        assert kwargs['headers'] == {
            'Content-Type':
            'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
        }
        assert encode_if_text(
            "https://www.w3.org/ns/activitystreams#Public") not in args[1]

        # Ensure third call is a public activitypub payload
        args, kwargs = mock_send.call_args_list[2]
        assert args[0] == "https://example.net/inbox"
        assert kwargs['headers'] == {
            'Content-Type':
            'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
        }
        assert encode_if_text(
            "https://www.w3.org/ns/activitystreams#Public") in args[1]

        # Ensure diaspora public payloads and recipients, one per unique host
        args3, kwargs3 = mock_send.call_args_list[3]
        args4, kwargs4 = mock_send.call_args_list[4]
        public_endpoints = {args3[0], args4[0]}
        assert public_endpoints == {
            "https://example.net/receive/public",
            "https://example.com/receive/public",
        }
        assert args3[1].startswith("<me:env xmlns:me=")
        assert args4[1].startswith("<me:env xmlns:me=")
        assert kwargs3['headers'] == {
            'Content-Type': 'application/magic-envelope+xml'
        }
        assert kwargs4['headers'] == {
            'Content-Type': 'application/magic-envelope+xml'
        }

        with pytest.raises(IndexError):
            # noinspection PyStatementEffect
            mock_send.call_args_list[5]
示例#33
0
 def test_sign_with_parent__calls_to_xml(self, mock_validate):
     entity = DiasporaComment()
     with patch.object(entity, "to_xml") as mock_to_xml:
         entity.sign_with_parent(get_dummy_private_key())
         mock_to_xml.assert_called_once_with()
示例#34
0
def get_private_key(identifier: str) -> RsaKey:
    return get_dummy_private_key()
示例#35
0
 def test_get_json_payload_magic_envelope(self, mock_decrypt):
     protocol = Protocol()
     protocol.user = UserType(id="foobar", private_key=get_dummy_private_key())
     protocol.get_json_payload_magic_envelope("payload")
     mock_decrypt.assert_called_once_with(payload="payload", private_key=get_dummy_private_key())
示例#36
0
def test_create_relayable_signature():
    doc = etree.XML(XML)
    signature = create_relayable_signature(get_dummy_private_key(), doc)
    assert signature == SIGNATURE3