kopia lustrzana https://gitlab.com/jaywink/federation
Add test for ActivityPub Follow post receive Accept sending
rodzic
273818dc43
commit
4b778112d8
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
from federation.tests.fixtures.entities import *
|
from federation.tests.fixtures.entities import *
|
||||||
|
from federation.tests.fixtures.types import *
|
||||||
from federation.tests.fixtures.keys import get_dummy_private_key
|
from federation.tests.fixtures.keys import get_dummy_private_key
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from Crypto.PublicKey.RSA import RsaKey
|
||||||
|
|
||||||
from federation.entities.activitypub.constants import (
|
from federation.entities.activitypub.constants import (
|
||||||
CONTEXTS_DEFAULT, CONTEXT_MANUALLY_APPROVES_FOLLOWERS, CONTEXT_LD_SIGNATURES, CONTEXT_HASHTAG, CONTEXT_SENSITIVE)
|
CONTEXTS_DEFAULT, CONTEXT_MANUALLY_APPROVES_FOLLOWERS, CONTEXT_LD_SIGNATURES, CONTEXT_HASHTAG, CONTEXT_SENSITIVE)
|
||||||
from federation.entities.activitypub.entities import ActivitypubProfile
|
from federation.entities.activitypub.entities import ActivitypubProfile, ActivitypubAccept
|
||||||
|
from federation.types import UserType
|
||||||
|
|
||||||
|
|
||||||
class TestEntitiesConvertToAS2:
|
class TestEntitiesConvertToAS2:
|
||||||
|
@ -37,3 +42,26 @@ class TestEntitiesConvertToAS2:
|
||||||
CONTEXT_MANUALLY_APPROVES_FOLLOWERS,
|
CONTEXT_MANUALLY_APPROVES_FOLLOWERS,
|
||||||
]
|
]
|
||||||
assert result.get('type') == 'Person'
|
assert result.get('type') == 'Person'
|
||||||
|
|
||||||
|
|
||||||
|
class TestEntitiesPostReceive:
|
||||||
|
@patch("federation.utils.activitypub.retrieve_and_parse_profile", autospec=True)
|
||||||
|
@patch("federation.entities.activitypub.entities.handle_send", autospec=True)
|
||||||
|
def test_follow_post_receive__sends_correct_accept_back(
|
||||||
|
self, mock_send, mock_retrieve, activitypubfollow, profile
|
||||||
|
):
|
||||||
|
mock_retrieve.return_value = profile
|
||||||
|
activitypubfollow.post_receive()
|
||||||
|
args, kwargs = mock_send.call_args_list[0]
|
||||||
|
assert isinstance(args[0], ActivitypubAccept)
|
||||||
|
assert args[0].activity_id.startswith("https://example.com/profile#accept-")
|
||||||
|
assert args[0].actor_id == "https://example.com/profile"
|
||||||
|
assert args[0].target_id == "https://localhost/follow"
|
||||||
|
assert isinstance(args[1], UserType)
|
||||||
|
assert args[1].id == "https://example.com/profile"
|
||||||
|
assert isinstance(args[1].private_key, RsaKey)
|
||||||
|
assert kwargs['recipients'] == [{
|
||||||
|
"fid": "https://example.com/private",
|
||||||
|
"protocol": "activitypub",
|
||||||
|
"public": False,
|
||||||
|
}]
|
||||||
|
|
|
@ -2,7 +2,7 @@ import uuid
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from federation.entities.activitypub.entities import ActivitypubPost, ActivitypubAccept
|
from federation.entities.activitypub.entities import ActivitypubPost, ActivitypubAccept, ActivitypubFollow
|
||||||
from federation.entities.base import Profile
|
from federation.entities.base import Profile
|
||||||
from federation.entities.diaspora.entities import (
|
from federation.entities.diaspora.entities import (
|
||||||
DiasporaPost, DiasporaComment, DiasporaLike, DiasporaProfile, DiasporaRetraction,
|
DiasporaPost, DiasporaComment, DiasporaLike, DiasporaProfile, DiasporaRetraction,
|
||||||
|
@ -21,6 +21,15 @@ def activitypubaccept():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def activitypubfollow():
|
||||||
|
return ActivitypubFollow(
|
||||||
|
activity_id="https://localhost/follow",
|
||||||
|
actor_id="https://localhost/profile",
|
||||||
|
target_id="https://example.com/profile",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def profile():
|
def profile():
|
||||||
return Profile(
|
return Profile(
|
||||||
|
@ -31,6 +40,10 @@ def profile():
|
||||||
id="https://example.com/alice",
|
id="https://example.com/alice",
|
||||||
handle="alice@example.com",
|
handle="alice@example.com",
|
||||||
guid="guid",
|
guid="guid",
|
||||||
|
inboxes={
|
||||||
|
"private": "https://example.com/private",
|
||||||
|
"public": "https://example.com/public",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from federation.tests.fixtures.keys import get_dummy_private_key
|
||||||
|
from federation.types import UserType
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def usertype():
|
||||||
|
return UserType(
|
||||||
|
id="https://localhost/profile",
|
||||||
|
private_key=get_dummy_private_key(),
|
||||||
|
)
|
Ładowanie…
Reference in New Issue