[#878] Merge remote-tracking branch 'remotes/upstream/develop' into 878-activity-object-decoupling-in-tests
# Conflicts: # lib/pleroma/object.ex # test/web/activity_pub/transmogrifier_test.exs # test/web/ostatus/ostatus_test.exs
This commit is contained in:
commit
829e997223
145 changed files with 1807 additions and 345 deletions
|
|
@ -15,6 +15,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -46,12 +47,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
returned_object = Object.normalize(returned_activity)
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
assert activity =
|
||||
Activity.get_create_by_object_ap_id(
|
||||
|
|
@ -61,6 +59,32 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
end
|
||||
|
||||
test "it does not fetch replied-to activities beyond max_replies_depth" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
allowed_incoming_reply_depth?: fn _ -> false end do
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
refute Activity.get_create_by_object_ap_id(
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
)
|
||||
|
||||
assert returned_object.data["inReplyToAtomUri"] ==
|
||||
"https://shitposter.club/notice/2827873"
|
||||
end
|
||||
end
|
||||
|
||||
test "it does not crash if the object in inReplyTo can't be fetched" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|
|
|
|||
|
|
@ -12,6 +12,13 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
import ExUnit.CaptureLog
|
||||
import Tesla.Mock
|
||||
|
||||
@image "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
|
@ -584,6 +586,101 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert expected == json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "user avatar can be set", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
avatar_image = File.read!("test/fixtures/avatar_data_uri")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_avatar", %{img: avatar_image})
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %{
|
||||
"name" => _,
|
||||
"type" => _,
|
||||
"url" => [
|
||||
%{
|
||||
"href" => _,
|
||||
"mediaType" => _,
|
||||
"type" => _
|
||||
}
|
||||
]
|
||||
} = user.avatar
|
||||
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "user avatar can be reset", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_avatar", %{img: ""})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.avatar == nil
|
||||
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "can set profile banner", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_banner", %{"banner" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.banner["type"] == "Image"
|
||||
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "can reset profile banner", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_banner", %{"banner" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.banner == %{}
|
||||
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "background image can be set", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_background", %{"img" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.background["type"] == "Image"
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "background image can be reset", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_background", %{"img" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.background == %{}
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "creates an oauth app", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
app_attrs = build(:oauth_app)
|
||||
|
|
|
|||
|
|
@ -445,4 +445,39 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert Enum.at(result[:options], 2)[:votes_count] == 1
|
||||
end
|
||||
end
|
||||
|
||||
test "embeds a relationship in the account" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "drink more water"
|
||||
})
|
||||
|
||||
result = StatusView.render("status.json", %{activity: activity, for: other_user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: other_user, target: user})
|
||||
end
|
||||
|
||||
test "embeds a relationship in the account in reposts" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "˙˙ɐʎns"
|
||||
})
|
||||
|
||||
{:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
result = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
|
||||
assert result[:reblog][:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: user, target: user})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.XML
|
||||
import Pleroma.Factory
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -268,10 +270,13 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
assert favorited_activity.local
|
||||
end
|
||||
|
||||
test "handle incoming replies" do
|
||||
test_with_mock "handle incoming replies, fetching replied-to activities if we don't have them",
|
||||
OStatus,
|
||||
[:passthrough],
|
||||
[] do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, false)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
|
|
@ -284,6 +289,23 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
|
||||
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
|
||||
assert called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
|
||||
end
|
||||
|
||||
test_with_mock "handle incoming replies, not fetching replied-to activities beyond max_replies_depth",
|
||||
OStatus,
|
||||
[:passthrough],
|
||||
[] do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
allowed_incoming_reply_depth?: fn _ -> false end do
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity, false)
|
||||
|
||||
refute called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
|
||||
end
|
||||
end
|
||||
|
||||
test "handle incoming follows" do
|
||||
|
|
|
|||
|
|
@ -5,6 +5,15 @@
|
|||
defmodule Pleroma.Web.FederatingPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "returns and halt the conn when federating is disabled" do
|
||||
Pleroma.Config.put([:instance, :federating], false)
|
||||
|
||||
|
|
@ -14,11 +23,11 @@ defmodule Pleroma.Web.FederatingPlugTest do
|
|||
|
||||
assert conn.status == 404
|
||||
assert conn.halted
|
||||
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
test "does nothing when federating is enabled" do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> Pleroma.Web.FederatingPlug.call(%{})
|
||||
|
|
|
|||
|
|
@ -40,6 +40,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
user = refresh_record(user)
|
||||
assert user.info.banner["type"] == "Image"
|
||||
end
|
||||
|
||||
test "profile banner can be reset", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => ""})
|
||||
|> json_response(200)
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.banner == %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/qvitter/update_background_image" do
|
||||
|
|
@ -54,6 +66,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
user = refresh_record(user)
|
||||
assert user.info.background["type"] == "Image"
|
||||
end
|
||||
|
||||
test "background can be reset", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => ""})
|
||||
|> json_response(200)
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.background == %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/account/verify_credentials" do
|
||||
|
|
@ -821,6 +845,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: current_user, for: current_user})
|
||||
end
|
||||
|
||||
test "user avatar can be reset", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/qvitter/update_avatar.json", %{img: ""})
|
||||
|
||||
current_user = User.get_cached_by_id(current_user.id)
|
||||
assert current_user.avatar == nil
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: current_user, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/qvitter/mutes.json" do
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
|
|||
alias Pleroma.Web.Websub
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "websub subscription request", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue