X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fpleroma%2Fweb%2Ftwitter_api%2Fremote_follow_controller_test.exs;h=e7c496eb04adccf3f25c217231376bf6aa1c09b5;hb=2144ce5188901c59cd72a0b5620862b23b47544e;hp=a3e784d13b7c5ff9f420e37e96a7d12cd7b61e48;hpb=504a829edb821f24fe7138380e77533cc9f802e6;p=akkoma
diff --git a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
index a3e784d13..e7c496eb0 100644
--- a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
+++ b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
alias Pleroma.MFA
alias Pleroma.MFA.TOTP
@@ -14,18 +14,37 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
import Pleroma.Factory
import Ecto.Query
- setup do
- Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
setup_all do: clear_config([:instance, :federating], true)
- setup do: clear_config([:instance])
- setup do: clear_config([:frontend_configurations, :pleroma_fe])
setup do: clear_config([:user, :deny_follow_blocked])
describe "GET /ostatus_subscribe - remote_follow/2" do
test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
+ Tesla.Mock.mock(fn
+ %{method: :get, url: "https://mastodon.social/users/emelie/statuses/101849165031453009"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
+ }
+
+ %{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "emelie")
+ }
+
+ %{method: :get, url: "https://mastodon.social/users/emelie"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: File.read!("test/fixtures/tesla_mock/emelie.json")
+ }
+ end)
+
assert conn
|> get(
remote_follow_path(conn, :follow, %{
@@ -36,6 +55,25 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "show follow account page if the `acct` is a account link", %{conn: conn} do
+ Tesla.Mock.mock(fn
+ %{method: :get, url: "https://mastodon.social/users/emelie"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: File.read!("test/fixtures/tesla_mock/emelie.json")
+ }
+
+ %{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "emelie")
+ }
+ end)
+
response =
conn
|> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"}))
@@ -45,6 +83,25 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "show follow page if the `acct` is a account link", %{conn: conn} do
+ Tesla.Mock.mock(fn
+ %{method: :get, url: "https://mastodon.social/users/emelie"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: File.read!("test/fixtures/tesla_mock/emelie.json")
+ }
+
+ %{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "emelie")
+ }
+ end)
+
user = insert(:user)
response =
@@ -56,7 +113,14 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
assert response =~ "Remote follow"
end
- test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
+ test "show follow page with error when user can not be fetched by `acct` link", %{conn: conn} do
+ Tesla.Mock.mock(fn
+ %{method: :get, url: "https://mastodon.social/users/not_found"} ->
+ %Tesla.Env{
+ status: 404
+ }
+ end)
+
user = insert(:user)
assert capture_log(fn ->
@@ -107,7 +171,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "returns error when user is deactivated", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
user2 = insert(:user)
response =
@@ -120,7 +184,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "returns error when user is blocked", %{conn: conn} do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
user2 = insert(:user)
@@ -331,7 +395,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "returns error when user is blocked", %{conn: conn} do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
user2 = insert(:user)
{:ok, _user_block} = Pleroma.User.block(user2, user)
@@ -346,4 +410,49 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
assert response =~ "Error following account"
end
end
+
+ describe "avatar url" do
+ test "without media proxy" do
+ clear_config([:media_proxy, :enabled], false)
+
+ user =
+ insert(:user, %{
+ local: false,
+ avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
+ })
+
+ avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
+
+ assert avatar_url == "https://remote.org/avatar.png"
+ end
+
+ test "with media proxy" do
+ clear_config([:media_proxy, :enabled], true)
+
+ user =
+ insert(:user, %{
+ local: false,
+ avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
+ })
+
+ avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
+ url = Pleroma.Web.Endpoint.url()
+
+ assert String.starts_with?(avatar_url, url)
+ end
+
+ test "local avatar is not proxied" do
+ clear_config([:media_proxy, :enabled], true)
+
+ user =
+ insert(:user, %{
+ local: true,
+ avatar: %{"url" => [%{"href" => "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"}]}
+ })
+
+ avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
+
+ assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
+ end
+ end
end