Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/emojireactvalidator
This commit is contained in:
commit
ef55d24054
30 changed files with 863 additions and 616 deletions
|
|
@ -728,7 +728,7 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
assert length(Notification.for_user(user)) == 1
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
|
||||
{:ok, _} = CommonAPI.unfavorite(activity.id, other_user)
|
||||
|
||||
assert Enum.empty?(Notification.for_user(user))
|
||||
end
|
||||
|
|
@ -762,7 +762,7 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
assert length(Notification.for_user(user)) == 1
|
||||
|
||||
{:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
|
||||
{:ok, _} = CommonAPI.unrepeat(activity.id, other_user)
|
||||
|
||||
assert Enum.empty?(Notification.for_user(user))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Federator
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
|
|
@ -874,122 +873,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "unreacting to an object" do
|
||||
test_with_mock "sends an activity to federation", Federator, [:passthrough], [] do
|
||||
Config.put([:instance, :federating], true)
|
||||
user = insert(:user)
|
||||
reactor = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"})
|
||||
assert object = Object.normalize(activity)
|
||||
|
||||
{:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, reactor, "🔥")
|
||||
|
||||
assert called(Federator.publish(reaction_activity))
|
||||
|
||||
{:ok, unreaction_activity, _object} =
|
||||
ActivityPub.unreact_with_emoji(reactor, reaction_activity.data["id"])
|
||||
|
||||
assert called(Federator.publish(unreaction_activity))
|
||||
end
|
||||
|
||||
test "adds an undo activity to the db" do
|
||||
user = insert(:user)
|
||||
reactor = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"})
|
||||
assert object = Object.normalize(activity)
|
||||
|
||||
{:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, reactor, "🔥")
|
||||
|
||||
{:ok, unreaction_activity, _object} =
|
||||
ActivityPub.unreact_with_emoji(reactor, reaction_activity.data["id"])
|
||||
|
||||
assert unreaction_activity.actor == reactor.ap_id
|
||||
assert unreaction_activity.data["object"] == reaction_activity.data["id"]
|
||||
|
||||
object = Object.get_by_ap_id(object.data["id"])
|
||||
assert object.data["reaction_count"] == 0
|
||||
assert object.data["reactions"] == []
|
||||
end
|
||||
|
||||
test "reverts emoji unreact on error" do
|
||||
[user, reactor] = insert_list(2, :user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Status"})
|
||||
object = Object.normalize(activity)
|
||||
|
||||
{:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, reactor, "😀")
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
assert {:error, :reverted} =
|
||||
ActivityPub.unreact_with_emoji(reactor, reaction_activity.data["id"])
|
||||
end
|
||||
|
||||
object = Object.get_by_ap_id(object.data["id"])
|
||||
|
||||
assert object.data["reaction_count"] == 1
|
||||
assert object.data["reactions"] == [["😀", [reactor.ap_id]]]
|
||||
end
|
||||
end
|
||||
|
||||
describe "unliking" do
|
||||
test_with_mock "sends an activity to federation", Federator, [:passthrough], [] do
|
||||
Config.put([:instance, :federating], true)
|
||||
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
refute called(Federator.publish())
|
||||
|
||||
{:ok, _like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
object = Object.get_by_id(object.id)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
assert called(Federator.publish(unlike_activity))
|
||||
end
|
||||
|
||||
test "reverts unliking on error" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
object = Object.normalize(note_activity)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
assert {:error, :reverted} = ActivityPub.unlike(user, object)
|
||||
end
|
||||
|
||||
assert Object.get_by_ap_id(object.data["id"]) == object
|
||||
assert object.data["like_count"] == 1
|
||||
assert Activity.get_by_id(like_activity.id)
|
||||
end
|
||||
|
||||
test "unliking a previously liked object" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
# Unliking something that hasn't been liked does nothing
|
||||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
|
||||
object = Object.get_by_id(object.id)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
assert Activity.get_by_id(like_activity.id) == nil
|
||||
assert note_activity.actor in unlike_activity.recipients
|
||||
end
|
||||
end
|
||||
|
||||
describe "announcing an object" do
|
||||
test "adds an announce activity to the db" do
|
||||
note_activity = insert(:note_activity)
|
||||
|
|
@ -1059,52 +942,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "unannouncing an object" do
|
||||
test "unannouncing a previously announced object" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
# Unannouncing an object that is not announced does nothing
|
||||
{:ok, object} = ActivityPub.unannounce(user, object)
|
||||
refute object.data["announcement_count"]
|
||||
|
||||
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
|
||||
assert object.data["announcement_count"] == 1
|
||||
|
||||
{:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object)
|
||||
assert object.data["announcement_count"] == 0
|
||||
|
||||
assert unannounce_activity.data["to"] == [
|
||||
User.ap_followers(user),
|
||||
object.data["actor"]
|
||||
]
|
||||
|
||||
assert unannounce_activity.data["type"] == "Undo"
|
||||
assert unannounce_activity.data["object"] == announce_activity.data
|
||||
assert unannounce_activity.data["actor"] == user.ap_id
|
||||
assert unannounce_activity.data["context"] == announce_activity.data["context"]
|
||||
|
||||
assert Activity.get_by_id(announce_activity.id) == nil
|
||||
end
|
||||
|
||||
test "reverts unannouncing on error" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _announce_activity, object} = ActivityPub.announce(user, object)
|
||||
assert object.data["announcement_count"] == 1
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
assert {:error, :reverted} = ActivityPub.unannounce(user, object)
|
||||
end
|
||||
|
||||
object = Object.get_by_ap_id(object.data["id"])
|
||||
assert object.data["announcement_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "uploading files" do
|
||||
test "copies the file to the configured folder" do
|
||||
file = %Plug.Upload{
|
||||
|
|
@ -1211,7 +1048,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "blocking / unblocking" do
|
||||
describe "blocking" do
|
||||
test "reverts block activity on error" do
|
||||
[blocker, blocked] = insert_list(2, :user)
|
||||
|
||||
|
|
@ -1233,38 +1070,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert activity.data["actor"] == blocker.ap_id
|
||||
assert activity.data["object"] == blocked.ap_id
|
||||
end
|
||||
|
||||
test "reverts unblock activity on error" do
|
||||
[blocker, blocked] = insert_list(2, :user)
|
||||
{:ok, block_activity} = ActivityPub.block(blocker, blocked)
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
assert {:error, :reverted} = ActivityPub.unblock(blocker, blocked)
|
||||
end
|
||||
|
||||
assert block_activity.data["type"] == "Block"
|
||||
assert block_activity.data["actor"] == blocker.ap_id
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 1
|
||||
assert Repo.aggregate(Object, :count, :id) == 1
|
||||
end
|
||||
|
||||
test "creates an undo activity for the last block" do
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, block_activity} = ActivityPub.block(blocker, blocked)
|
||||
{:ok, activity} = ActivityPub.unblock(blocker, blocked)
|
||||
|
||||
assert activity.data["type"] == "Undo"
|
||||
assert activity.data["actor"] == blocker.ap_id
|
||||
|
||||
embedded_object = activity.data["object"]
|
||||
assert is_map(embedded_object)
|
||||
assert embedded_object["type"] == "Block"
|
||||
assert embedded_object["object"] == blocked.ap_id
|
||||
assert embedded_object["id"] == block_activity.data["id"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "timeline post-processing" do
|
||||
|
|
|
|||
|
|
@ -50,6 +50,46 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Undos" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, post_activity} = CommonAPI.post(user, %{"status" => "uguu"})
|
||||
{:ok, like} = CommonAPI.favorite(user, post_activity.id)
|
||||
{:ok, valid_like_undo, []} = Builder.undo(user, like)
|
||||
|
||||
%{user: user, like: like, valid_like_undo: valid_like_undo}
|
||||
end
|
||||
|
||||
test "it validates a basic like undo", %{valid_like_undo: valid_like_undo} do
|
||||
assert {:ok, _, _} = ObjectValidator.validate(valid_like_undo, [])
|
||||
end
|
||||
|
||||
test "it does not validate if the actor of the undo is not the actor of the object", %{
|
||||
valid_like_undo: valid_like_undo
|
||||
} do
|
||||
other_user = insert(:user, ap_id: "https://gensokyo.2hu/users/raymoo")
|
||||
|
||||
bad_actor =
|
||||
valid_like_undo
|
||||
|> Map.put("actor", other_user.ap_id)
|
||||
|
||||
{:error, cng} = ObjectValidator.validate(bad_actor, [])
|
||||
|
||||
assert {:actor, {"not the same as object actor", []}} in cng.errors
|
||||
end
|
||||
|
||||
test "it does not validate if the object is missing", %{valid_like_undo: valid_like_undo} do
|
||||
missing_object =
|
||||
valid_like_undo
|
||||
|> Map.put("object", "https://gensokyo.2hu/objects/1")
|
||||
|
||||
{:error, cng} = ObjectValidator.validate(missing_object, [])
|
||||
|
||||
assert {:object, {"can't find object", []}} in cng.errors
|
||||
assert length(cng.errors) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "deletes" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -99,6 +99,106 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Undo objects" do
|
||||
setup do
|
||||
poster = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
|
||||
{:ok, like} = CommonAPI.favorite(user, post.id)
|
||||
{:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")
|
||||
{:ok, announce, _} = CommonAPI.repeat(post.id, user)
|
||||
{:ok, block} = ActivityPub.block(user, poster)
|
||||
User.block(user, poster)
|
||||
|
||||
{:ok, undo_data, _meta} = Builder.undo(user, like)
|
||||
{:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
||||
|
||||
{:ok, undo_data, _meta} = Builder.undo(user, reaction)
|
||||
{:ok, reaction_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
||||
|
||||
{:ok, undo_data, _meta} = Builder.undo(user, announce)
|
||||
{:ok, announce_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
||||
|
||||
{:ok, undo_data, _meta} = Builder.undo(user, block)
|
||||
{:ok, block_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
||||
|
||||
%{
|
||||
like_undo: like_undo,
|
||||
post: post,
|
||||
like: like,
|
||||
reaction_undo: reaction_undo,
|
||||
reaction: reaction,
|
||||
announce_undo: announce_undo,
|
||||
announce: announce,
|
||||
block_undo: block_undo,
|
||||
block: block,
|
||||
poster: poster,
|
||||
user: user
|
||||
}
|
||||
end
|
||||
|
||||
test "deletes the original block", %{block_undo: block_undo, block: block} do
|
||||
{:ok, _block_undo, _} = SideEffects.handle(block_undo)
|
||||
refute Activity.get_by_id(block.id)
|
||||
end
|
||||
|
||||
test "unblocks the blocked user", %{block_undo: block_undo, block: block} do
|
||||
blocker = User.get_by_ap_id(block.data["actor"])
|
||||
blocked = User.get_by_ap_id(block.data["object"])
|
||||
|
||||
{:ok, _block_undo, _} = SideEffects.handle(block_undo)
|
||||
refute User.blocks?(blocker, blocked)
|
||||
end
|
||||
|
||||
test "an announce undo removes the announce from the object", %{
|
||||
announce_undo: announce_undo,
|
||||
post: post
|
||||
} do
|
||||
{:ok, _announce_undo, _} = SideEffects.handle(announce_undo)
|
||||
|
||||
object = Object.get_by_ap_id(post.data["object"])
|
||||
|
||||
assert object.data["announcement_count"] == 0
|
||||
assert object.data["announcements"] == []
|
||||
end
|
||||
|
||||
test "deletes the original announce", %{announce_undo: announce_undo, announce: announce} do
|
||||
{:ok, _announce_undo, _} = SideEffects.handle(announce_undo)
|
||||
refute Activity.get_by_id(announce.id)
|
||||
end
|
||||
|
||||
test "a reaction undo removes the reaction from the object", %{
|
||||
reaction_undo: reaction_undo,
|
||||
post: post
|
||||
} do
|
||||
{:ok, _reaction_undo, _} = SideEffects.handle(reaction_undo)
|
||||
|
||||
object = Object.get_by_ap_id(post.data["object"])
|
||||
|
||||
assert object.data["reaction_count"] == 0
|
||||
assert object.data["reactions"] == []
|
||||
end
|
||||
|
||||
test "deletes the original reaction", %{reaction_undo: reaction_undo, reaction: reaction} do
|
||||
{:ok, _reaction_undo, _} = SideEffects.handle(reaction_undo)
|
||||
refute Activity.get_by_id(reaction.id)
|
||||
end
|
||||
|
||||
test "a like undo removes the like from the object", %{like_undo: like_undo, post: post} do
|
||||
{:ok, _like_undo, _} = SideEffects.handle(like_undo)
|
||||
|
||||
object = Object.get_by_ap_id(post.data["object"])
|
||||
|
||||
assert object.data["like_count"] == 0
|
||||
assert object.data["likes"] == []
|
||||
end
|
||||
|
||||
test "deletes the original like", %{like_undo: like_undo, like: like} do
|
||||
{:ok, _like_undo, _} = SideEffects.handle(like_undo)
|
||||
refute Activity.get_by_id(like.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "like objects" do
|
||||
setup do
|
||||
poster = insert(:user)
|
||||
|
|
|
|||
185
test/web/activity_pub/transmogrifier/undo_handling_test.exs
Normal file
185
test/web/activity_pub/transmogrifier/undo_handling_test.exs
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it works for incoming emoji reaction undos" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
{:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, user, "👌")
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-undo-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", reaction_activity.data["id"])
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert activity.actor == user.ap_id
|
||||
assert activity.data["id"] == data["id"]
|
||||
assert activity.data["type"] == "Undo"
|
||||
end
|
||||
|
||||
test "it returns an error for incoming unlikes wihout a like activity" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-undo-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
assert Transmogrifier.handle_incoming(data) == :error
|
||||
end
|
||||
|
||||
test "it works for incoming unlikes with an existing like activity" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
|
||||
|
||||
like_data =
|
||||
File.read!("test/fixtures/mastodon-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_liker = insert(:user, ap_id: like_data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-undo-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", like_data)
|
||||
|> Map.put("actor", like_data["actor"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Undo"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
|
||||
assert data["object"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
|
||||
note = Object.get_by_ap_id(like_data["object"])
|
||||
assert note.data["like_count"] == 0
|
||||
assert note.data["likes"] == []
|
||||
end
|
||||
|
||||
test "it works for incoming unlikes with an existing like activity and a compact object" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
|
||||
|
||||
like_data =
|
||||
File.read!("test/fixtures/mastodon-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_liker = insert(:user, ap_id: like_data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-undo-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", like_data["id"])
|
||||
|> Map.put("actor", like_data["actor"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Undo"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
|
||||
assert data["object"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
end
|
||||
|
||||
test "it works for incoming unannounces with an existing notice" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
|
||||
announce_data =
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_announcer = insert(:user, ap_id: announce_data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: announce_data, local: false}} =
|
||||
Transmogrifier.handle_incoming(announce_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-undo-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", announce_data)
|
||||
|> Map.put("actor", announce_data["actor"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Undo"
|
||||
|
||||
assert data["object"] ==
|
||||
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||
end
|
||||
|
||||
test "it works for incomming unfollows with an existing follow" do
|
||||
user = insert(:user)
|
||||
|
||||
follow_data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
_follower = insert(:user, ap_id: follow_data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-unfollow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", follow_data)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Undo"
|
||||
assert data["object"]["type"] == "Follow"
|
||||
assert data["object"]["object"] == user.ap_id
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it works for incoming unblocks with an existing block" do
|
||||
user = insert(:user)
|
||||
|
||||
block_data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
_blocker = insert(:user, ap_id: block_data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-unblock-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", block_data)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
assert data["type"] == "Undo"
|
||||
assert data["object"] == block_data["id"]
|
||||
|
||||
blocker = User.get_cached_by_ap_id(data["actor"])
|
||||
|
||||
refute User.blocks?(blocker, user)
|
||||
end
|
||||
end
|
||||
|
|
@ -378,7 +378,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Undo"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
|
||||
assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
assert data["object"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
end
|
||||
|
||||
test "it works for incoming unlikes with an existing like activity and a compact object" do
|
||||
|
|
@ -403,7 +403,44 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Undo"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
|
||||
assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
assert data["object"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
end
|
||||
|
||||
test "it works for incoming emoji reactions" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/emoji-reaction.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "EmojiReact"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2"
|
||||
assert data["object"] == activity.data["object"]
|
||||
assert data["content"] == "👌"
|
||||
end
|
||||
|
||||
test "it reject invalid emoji reactions" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/emoji-reaction-too-long.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/emoji-reaction-no-emoji.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it works for incoming announces" do
|
||||
|
|
@ -729,35 +766,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert user.locked == true
|
||||
end
|
||||
|
||||
test "it works for incoming unannounces with an existing notice" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
|
||||
announce_data =
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
{:ok, %Activity{data: announce_data, local: false}} =
|
||||
Transmogrifier.handle_incoming(announce_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-undo-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", announce_data)
|
||||
|> Map.put("actor", announce_data["actor"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Undo"
|
||||
assert object_data = data["object"]
|
||||
assert object_data["type"] == "Announce"
|
||||
assert object_data["object"] == activity.data["object"]
|
||||
|
||||
assert object_data["id"] ==
|
||||
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||
end
|
||||
|
||||
test "it works for incomming unfollows with an existing follow" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -852,32 +860,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute User.following?(blocked, blocker)
|
||||
end
|
||||
|
||||
test "it works for incoming unblocks with an existing block" do
|
||||
user = insert(:user)
|
||||
|
||||
block_data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-unblock-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", block_data)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
assert data["type"] == "Undo"
|
||||
assert data["object"]["type"] == "Block"
|
||||
assert data["object"]["object"] == user.ap_id
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
blocker = User.get_cached_by_ap_id(data["actor"])
|
||||
|
||||
refute User.blocks?(blocker, user)
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which were pre-accepted" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
|
|
|||
|
|
@ -102,34 +102,6 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "make_unlike_data/3" do
|
||||
test "returns data for unlike activity" do
|
||||
user = insert(:user)
|
||||
like_activity = insert(:like_activity, data_attrs: %{"context" => "test context"})
|
||||
|
||||
object = Object.normalize(like_activity.data["object"])
|
||||
|
||||
assert Utils.make_unlike_data(user, like_activity, nil) == %{
|
||||
"type" => "Undo",
|
||||
"actor" => user.ap_id,
|
||||
"object" => like_activity.data,
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => [Pleroma.Constants.as_public()],
|
||||
"context" => like_activity.data["context"]
|
||||
}
|
||||
|
||||
assert Utils.make_unlike_data(user, like_activity, "9mJEZK0tky1w2xD2vY") == %{
|
||||
"type" => "Undo",
|
||||
"actor" => user.ap_id,
|
||||
"object" => like_activity.data,
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => [Pleroma.Constants.as_public()],
|
||||
"context" => like_activity.data["context"],
|
||||
"id" => "9mJEZK0tky1w2xD2vY"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_like_data" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -375,10 +375,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||
|
||||
{:ok, unreaction, _} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||
{:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert unreaction.data["type"] == "Undo"
|
||||
assert unreaction.data["object"] == reaction.data["id"]
|
||||
assert unreaction.local
|
||||
end
|
||||
|
||||
test "repeating a status" do
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
capture_log(fn ->
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v2/search", %{"q" => "2hu"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v2/search?q=2hu")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["accounts"] == []
|
||||
assert results["statuses"] == []
|
||||
|
|
@ -54,8 +54,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v2/search", %{"q" => "2hu #private"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v2/search?#{URI.encode_query(%{q: "2hu #private"})}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[account | _] = results["accounts"]
|
||||
assert account["id"] == to_string(user_three.id)
|
||||
|
|
@ -68,8 +68,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
assert status["id"] == to_string(activity.id)
|
||||
|
||||
results =
|
||||
get(conn, "/api/v2/search", %{"q" => "天子"})
|
||||
|> json_response(200)
|
||||
get(conn, "/api/v2/search?q=天子")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[status] = results["statuses"]
|
||||
assert status["id"] == to_string(activity.id)
|
||||
|
|
@ -89,8 +89,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read"]))
|
||||
|> get("/api/v2/search", %{"q" => "Agent"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v2/search?q=Agent")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
status_ids = Enum.map(results["statuses"], fn g -> g["id"] end)
|
||||
|
||||
|
|
@ -107,8 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/accounts/search", %{"q" => "shp"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/accounts/search?q=shp")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
result_ids = for result <- results, do: result["acct"]
|
||||
|
||||
|
|
@ -117,8 +117,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/accounts/search", %{"q" => "2hu"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/accounts/search?q=2hu")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
result_ids = for result <- results, do: result["acct"]
|
||||
|
||||
|
|
@ -130,8 +130,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/accounts/search", %{"q" => "shp@shitposter.club xxx "})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/accounts/search?q=shp@shitposter.club xxx")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(results) == 1
|
||||
end
|
||||
|
|
@ -146,8 +146,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
capture_log(fn ->
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["accounts"] == []
|
||||
assert results["statuses"] == []
|
||||
|
|
@ -173,8 +173,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[account | _] = results["accounts"]
|
||||
assert account["id"] == to_string(user_three.id)
|
||||
|
|
@ -194,8 +194,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=https://shitposter.club/notice/2827873")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[status, %{"id" => ^activity_id}] = results["statuses"]
|
||||
|
||||
|
|
@ -212,10 +212,12 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
})
|
||||
|
||||
capture_log(fn ->
|
||||
q = Object.normalize(activity).data["id"]
|
||||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => Object.normalize(activity).data["id"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=#{q}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[] = results["statuses"]
|
||||
end)
|
||||
|
|
@ -228,8 +230,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read"]))
|
||||
|> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "true"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=mike@osada.macgirvin.com&resolve=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[account] = results["accounts"]
|
||||
assert account["acct"] == "mike@osada.macgirvin.com"
|
||||
|
|
@ -238,8 +240,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "false"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=mike@osada.macgirvin.com&resolve=false")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] == results["accounts"]
|
||||
end
|
||||
|
|
@ -254,16 +256,16 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu", "limit" => 1})
|
||||
|> get("/api/v1/search?q=2hu&limit=1")
|
||||
|
||||
assert results = json_response(result, 200)
|
||||
assert results = json_response_and_validate_schema(result, 200)
|
||||
assert [%{"id" => activity_id1}] = results["statuses"]
|
||||
assert [_] = results["accounts"]
|
||||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu", "limit" => 1, "offset" => 1})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu&limit=1&offset=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => activity_id2}] = results["statuses"]
|
||||
assert [] = results["accounts"]
|
||||
|
|
@ -279,13 +281,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
assert %{"statuses" => [_activity], "accounts" => [], "hashtags" => []} =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu", "type" => "statuses"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu&type=statuses")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"statuses" => [], "accounts" => [_user_two], "hashtags" => []} =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu", "type" => "accounts"})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu&type=accounts")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "search uses account_id to filter statuses by the author", %{conn: conn} do
|
||||
|
|
@ -297,8 +299,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu", "account_id" => user.id})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu&account_id=#{user.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => activity_id1}] = results["statuses"]
|
||||
assert activity_id1 == activity1.id
|
||||
|
|
@ -306,8 +308,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
results =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "2hu", "account_id" => user_two.id})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/search?q=2hu&account_id=#{user_two.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => activity_id2}] = results["statuses"]
|
||||
assert activity_id2 == activity2.id
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -41,7 +43,9 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
|
||||
{:ok, activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||
{:ok, _reaction_activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
result =
|
||||
conn
|
||||
|
|
@ -52,7 +56,9 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
assert %{"id" => id} = json_response(result, 200)
|
||||
assert to_string(activity.id) == id
|
||||
|
||||
object = Object.normalize(activity)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
object = Object.get_by_ap_id(activity.data["object"])
|
||||
|
||||
assert object.data["reaction_count"] == 0
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue