Handle "Move" activity
This commit is contained in:
parent
4270861085
commit
61fc739ab8
7 changed files with 146 additions and 0 deletions
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Builders.ActivityBuilder
|
||||
alias Pleroma.Object
|
||||
|
|
@ -1420,4 +1422,50 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert follow_info.hide_follows == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "Move activity" do
|
||||
test "create" do
|
||||
%{ap_id: old_ap_id} = old_user = insert(:user)
|
||||
%{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
|
||||
follower = insert(:user)
|
||||
|
||||
User.follow(follower, old_user)
|
||||
|
||||
assert User.following?(follower, old_user)
|
||||
|
||||
assert {:ok, activity} = ActivityPub.move(old_user, new_user)
|
||||
|
||||
assert %Activity{
|
||||
actor: ^old_ap_id,
|
||||
data: %{
|
||||
"actor" => ^old_ap_id,
|
||||
"object" => ^old_ap_id,
|
||||
"target" => ^new_ap_id,
|
||||
"type" => "Move"
|
||||
},
|
||||
local: true
|
||||
} = activity
|
||||
|
||||
params = %{
|
||||
"op" => "move_following",
|
||||
"origin_id" => old_user.id,
|
||||
"target_id" => new_user.id
|
||||
}
|
||||
|
||||
assert_enqueued(worker: Pleroma.Workers.BackgroundWorker, args: params)
|
||||
|
||||
Pleroma.Workers.BackgroundWorker.perform(params, nil)
|
||||
|
||||
refute User.following?(follower, old_user)
|
||||
assert User.following?(follower, new_user)
|
||||
end
|
||||
|
||||
test "old user must be in the new user's `also_known_as` list" do
|
||||
old_user = insert(:user)
|
||||
new_user = insert(:user)
|
||||
|
||||
assert {:error, "Target account must have the origin in `alsoKnownAs`"} =
|
||||
ActivityPub.move(old_user, new_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1181,6 +1181,30 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
|
||||
assert [user.follower_address] == activity.data["to"]
|
||||
end
|
||||
|
||||
test "it accepts Move activities" do
|
||||
old_user = insert(:user)
|
||||
new_user = insert(:user)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Move",
|
||||
"actor" => old_user.ap_id,
|
||||
"object" => old_user.ap_id,
|
||||
"target" => new_user.ap_id
|
||||
}
|
||||
|
||||
assert :error = Transmogrifier.handle_incoming(message)
|
||||
|
||||
{:ok, _new_user} = User.update_and_set_cache(new_user, %{also_known_as: [old_user.ap_id]})
|
||||
|
||||
assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(message)
|
||||
assert activity.actor == old_user.ap_id
|
||||
assert activity.data["actor"] == old_user.ap_id
|
||||
assert activity.data["object"] == old_user.ap_id
|
||||
assert activity.data["target"] == new_user.ap_id
|
||||
assert activity.data["type"] == "Move"
|
||||
end
|
||||
end
|
||||
|
||||
describe "prepare outgoing" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue