forked from AkkomaGang/akkoma
Add tests for setting :instance, :quarantined_instances
No test was done for quarantined instances yet. I added a factory for followers_only notes and checked * That no followers only post is send when the target server is quarantined * That a followers only post is send when the target server is not quarantined
This commit is contained in:
parent
4ba0beb60c
commit
dd947d9bc8
2 changed files with 106 additions and 0 deletions
|
@ -267,6 +267,80 @@ test "publish to url with with different ports" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "publish/2" do
|
describe "publish/2" do
|
||||||
|
test_with_mock "doesn't publish a non-public activity to quarantined instances.",
|
||||||
|
Pleroma.Web.Federator.Publisher,
|
||||||
|
[:passthrough],
|
||||||
|
[] do
|
||||||
|
Config.put([:instance, :quarantined_instances], ["domain.com"])
|
||||||
|
|
||||||
|
follower =
|
||||||
|
insert(:user, %{
|
||||||
|
local: false,
|
||||||
|
inbox: "https://domain.com/users/nick1/inbox",
|
||||||
|
ap_enabled: true
|
||||||
|
})
|
||||||
|
|
||||||
|
actor = insert(:user, follower_address: follower.ap_id)
|
||||||
|
|
||||||
|
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||||
|
actor = refresh_record(actor)
|
||||||
|
|
||||||
|
note_activity =
|
||||||
|
insert(:followers_only_note_activity,
|
||||||
|
user: actor,
|
||||||
|
recipients: [follower.ap_id]
|
||||||
|
)
|
||||||
|
|
||||||
|
res = Publisher.publish(actor, note_activity)
|
||||||
|
|
||||||
|
assert res == :ok
|
||||||
|
|
||||||
|
assert not called(
|
||||||
|
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||||
|
inbox: "https://domain.com/users/nick1/inbox",
|
||||||
|
actor_id: actor.id,
|
||||||
|
id: note_activity.data["id"]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
test_with_mock "Publishes a non-public activity to non-quarantined instances.",
|
||||||
|
Pleroma.Web.Federator.Publisher,
|
||||||
|
[:passthrough],
|
||||||
|
[] do
|
||||||
|
Config.put([:instance, :quarantined_instances], ["somedomain.com"])
|
||||||
|
|
||||||
|
follower =
|
||||||
|
insert(:user, %{
|
||||||
|
local: false,
|
||||||
|
inbox: "https://domain.com/users/nick1/inbox",
|
||||||
|
ap_enabled: true
|
||||||
|
})
|
||||||
|
|
||||||
|
actor = insert(:user, follower_address: follower.ap_id)
|
||||||
|
|
||||||
|
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||||
|
actor = refresh_record(actor)
|
||||||
|
|
||||||
|
note_activity =
|
||||||
|
insert(:followers_only_note_activity,
|
||||||
|
user: actor,
|
||||||
|
recipients: [follower.ap_id]
|
||||||
|
)
|
||||||
|
|
||||||
|
res = Publisher.publish(actor, note_activity)
|
||||||
|
|
||||||
|
assert res == :ok
|
||||||
|
|
||||||
|
assert called(
|
||||||
|
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||||
|
inbox: "https://domain.com/users/nick1/inbox",
|
||||||
|
actor_id: actor.id,
|
||||||
|
id: note_activity.data["id"]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
test_with_mock "publishes an activity with BCC to all relevant peers.",
|
test_with_mock "publishes an activity with BCC to all relevant peers.",
|
||||||
Pleroma.Web.Federator.Publisher,
|
Pleroma.Web.Federator.Publisher,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
|
|
|
@ -142,6 +142,11 @@ defp attachment_data(ap_id, href) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def followers_only_note_factory(attrs \\ %{}) do
|
||||||
|
%Pleroma.Object{data: data} = note_factory(attrs)
|
||||||
|
%Pleroma.Object{data: Map.merge(data, %{"to" => [data["actor"] <> "/followers"]})}
|
||||||
|
end
|
||||||
|
|
||||||
def audio_factory(attrs \\ %{}) do
|
def audio_factory(attrs \\ %{}) do
|
||||||
text = sequence(:text, &"lain radio episode #{&1}")
|
text = sequence(:text, &"lain radio episode #{&1}")
|
||||||
|
|
||||||
|
@ -267,6 +272,33 @@ defp featured_collection_activity(attrs, type) do
|
||||||
|> Map.merge(attrs)
|
|> Map.merge(attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def followers_only_note_activity_factory(attrs \\ %{}) do
|
||||||
|
user = attrs[:user] || insert(:user)
|
||||||
|
note = insert(:followers_only_note, user: user)
|
||||||
|
|
||||||
|
data_attrs = attrs[:data_attrs] || %{}
|
||||||
|
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||||
|
|
||||||
|
data =
|
||||||
|
%{
|
||||||
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||||
|
"type" => "Create",
|
||||||
|
"actor" => note.data["actor"],
|
||||||
|
"to" => note.data["to"],
|
||||||
|
"object" => note.data,
|
||||||
|
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||||
|
"context" => note.data["context"]
|
||||||
|
}
|
||||||
|
|> Map.merge(data_attrs)
|
||||||
|
|
||||||
|
%Pleroma.Activity{
|
||||||
|
data: data,
|
||||||
|
actor: data["actor"],
|
||||||
|
recipients: data["to"]
|
||||||
|
}
|
||||||
|
|> Map.merge(attrs)
|
||||||
|
end
|
||||||
|
|
||||||
def note_activity_factory(attrs \\ %{}) do
|
def note_activity_factory(attrs \\ %{}) do
|
||||||
user = attrs[:user] || insert(:user)
|
user = attrs[:user] || insert(:user)
|
||||||
note = attrs[:note] || insert(:note, user: user)
|
note = attrs[:note] || insert(:note, user: user)
|
||||||
|
|
Loading…
Reference in a new issue