Merge branch 'discard-unhandled-activities' into 'develop'
Fix #776: Don't store unhandled ActivityPub messages in database Closes #776 See merge request funkwhale/funkwhale!696
This commit is contained in:
commit
8a5c85a823
|
@ -121,6 +121,7 @@ def receive(activity, on_behalf_of):
|
||||||
from . import models
|
from . import models
|
||||||
from . import serializers
|
from . import serializers
|
||||||
from . import tasks
|
from . import tasks
|
||||||
|
from .routes import inbox
|
||||||
|
|
||||||
# we ensure the activity has the bare minimum structure before storing
|
# we ensure the activity has the bare minimum structure before storing
|
||||||
# it in our database
|
# it in our database
|
||||||
|
@ -128,6 +129,10 @@ def receive(activity, on_behalf_of):
|
||||||
data=activity, context={"actor": on_behalf_of, "local_recipients": True}
|
data=activity, context={"actor": on_behalf_of, "local_recipients": True}
|
||||||
)
|
)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
if not inbox.get_matching_handlers(activity):
|
||||||
|
# discard unhandlable activity
|
||||||
|
return
|
||||||
|
|
||||||
if should_reject(
|
if should_reject(
|
||||||
fid=serializer.validated_data.get("id"),
|
fid=serializer.validated_data.get("id"),
|
||||||
actor_id=serializer.validated_data["actor"].fid,
|
actor_id=serializer.validated_data["actor"].fid,
|
||||||
|
|
|
@ -14,6 +14,9 @@ from funkwhale_api.federation import (
|
||||||
|
|
||||||
|
|
||||||
def test_receive_validates_basic_attributes_and_stores_activity(factories, now, mocker):
|
def test_receive_validates_basic_attributes_and_stores_activity(factories, now, mocker):
|
||||||
|
mocker.patch.object(
|
||||||
|
activity.InboxRouter, "get_matching_handlers", return_value=True
|
||||||
|
)
|
||||||
mocked_dispatch = mocker.patch("funkwhale_api.common.utils.on_commit")
|
mocked_dispatch = mocker.patch("funkwhale_api.common.utils.on_commit")
|
||||||
local_to_actor = factories["users.User"]().create_actor()
|
local_to_actor = factories["users.User"]().create_actor()
|
||||||
local_cc_actor = factories["users.User"]().create_actor()
|
local_cc_actor = factories["users.User"]().create_actor()
|
||||||
|
@ -48,6 +51,9 @@ def test_receive_validates_basic_attributes_and_stores_activity(factories, now,
|
||||||
|
|
||||||
def test_receive_calls_should_reject(factories, now, mocker):
|
def test_receive_calls_should_reject(factories, now, mocker):
|
||||||
should_reject = mocker.patch.object(activity, "should_reject", return_value=True)
|
should_reject = mocker.patch.object(activity, "should_reject", return_value=True)
|
||||||
|
mocker.patch.object(
|
||||||
|
activity.InboxRouter, "get_matching_handlers", return_value=True
|
||||||
|
)
|
||||||
local_to_actor = factories["users.User"]().create_actor()
|
local_to_actor = factories["users.User"]().create_actor()
|
||||||
remote_actor = factories["federation.Actor"]()
|
remote_actor = factories["federation.Actor"]()
|
||||||
a = {
|
a = {
|
||||||
|
@ -65,6 +71,26 @@ def test_receive_calls_should_reject(factories, now, mocker):
|
||||||
assert copy is None
|
assert copy is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_receive_skips_if_no_matching_route(factories, now, mocker):
|
||||||
|
get_matching_handlers = mocker.patch.object(
|
||||||
|
activity.InboxRouter, "get_matching_handlers", return_value=[]
|
||||||
|
)
|
||||||
|
local_to_actor = factories["users.User"]().create_actor()
|
||||||
|
remote_actor = factories["federation.Actor"]()
|
||||||
|
a = {
|
||||||
|
"@context": [],
|
||||||
|
"actor": remote_actor.fid,
|
||||||
|
"type": "Noop",
|
||||||
|
"id": "https://test.activity",
|
||||||
|
"to": [local_to_actor.fid, remote_actor.fid],
|
||||||
|
}
|
||||||
|
|
||||||
|
copy = activity.receive(activity=a, on_behalf_of=remote_actor)
|
||||||
|
get_matching_handlers.assert_called_once_with(a)
|
||||||
|
assert copy is None
|
||||||
|
assert models.Activity.objects.count() == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"params, policy_kwargs, expected",
|
"params, policy_kwargs, expected",
|
||||||
[
|
[
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Don't store unhandled ActivityPub messages in database (#776)
|
Loading…
Reference in New Issue