Merge branch 'kaniini/pleroma-feature/activitypub-accept-reject-conformance' into develop
This commit is contained in:
commit
745072b2cc
13 changed files with 327 additions and 30 deletions
34
test/fixtures/mastodon-reject-activity.json
vendored
Normal file
34
test/fixtures/mastodon-reject-activity.json
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"type": "Reject",
|
||||
"signature": {
|
||||
"type": "RsaSignature2017",
|
||||
"signatureValue": "rBzK4Kqhd4g7HDS8WE5oRbWQb2R+HF/6awbUuMWhgru/xCODT0SJWSri0qWqEO4fPcpoUyz2d25cw6o+iy9wiozQb3hQNnu69AR+H5Mytc06+g10KCHexbGhbAEAw/7IzmeXELHUbaqeduaDIbdt1zw4RkwLXdqgQcGXTJ6ND1wM3WMHXQCK1m0flasIXFoBxpliPAGiElV8s0+Ltuh562GvflG3kB3WO+j+NaR0ZfG5G9N88xMj9UQlCKit5gpAE5p6syUsCU2WGBHywTumv73i3OVTIFfq+P9AdMsRuzw1r7zoKEsthW4aOzLQDi01ZjvdBz8zH6JnjDU7SMN/Ig==",
|
||||
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||
"created": "2018-02-17T14:36:41Z"
|
||||
},
|
||||
"object": {
|
||||
"type": "Follow",
|
||||
"object": "http://mastodon.example.org/users/admin",
|
||||
"id": "http://localtesting.pleroma.lol/users/lain#follows/4",
|
||||
"actor": "http://localtesting.pleroma.lol/users/lain"
|
||||
},
|
||||
"nickname": "lain",
|
||||
"id": "http://mastodon.example.org/users/admin#rejects/follows/4",
|
||||
"actor": "http://mastodon.example.org/users/admin",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -2,13 +2,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
alias Pleroma.Web.Websub.WebsubServerSubscription
|
||||
import Ecto.Query
|
||||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -283,7 +282,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|> Map.put("object", object)
|
||||
|> Map.put("actor", activity.data["actor"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute Repo.get(Activity, activity.id)
|
||||
end
|
||||
|
|
@ -385,6 +384,164 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
refute User.blocks?(blocker, user)
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which were pre-accepted" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
object =
|
||||
accept_data["object"]
|
||||
|> Map.put("actor", follower.ap_id)
|
||||
|> Map.put("id", follow_activity.data["id"])
|
||||
|
||||
accept_data = Map.put(accept_data, "object", object)
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
refute activity.local
|
||||
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which were orphaned" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it fails for incoming accepts which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
:error = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
refute User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it fails for incoming rejects which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
:error = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
refute User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming rejects which are orphaned" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, _follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
reject_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
reject_data =
|
||||
Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
|
||||
refute activity.local
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == false
|
||||
end
|
||||
|
||||
test "it works for incoming rejects which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %{"locked" => true}})
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
reject_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
|
||||
|
||||
follower = Repo.get(User, follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == false
|
||||
end
|
||||
end
|
||||
|
||||
describe "prepare outgoing" do
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
test "list timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."})
|
||||
{:ok, _activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."})
|
||||
{:ok, activity_two} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue