1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
6 use Pleroma.Web.ConnCase
9 alias Pleroma.Web.CommonAPI
10 import ExUnit.CaptureLog
11 import Pleroma.Factory
14 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
18 clear_config([:instance])
19 clear_config([:frontend_configurations, :pleroma_fe])
20 clear_config([:user, :deny_follow_blocked])
22 describe "GET /ostatus_subscribe - remote_follow/2" do
23 test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
26 remote_follow_path(conn, :follow, %{
27 acct: "https://mastodon.social/users/emelie/statuses/101849165031453009"
30 |> redirected_to() =~ "/notice/"
33 test "show follow account page if the `acct` is a account link", %{conn: conn} do
36 |> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"}))
39 assert response =~ "Log in to follow"
42 test "show follow page if the `acct` is a account link", %{conn: conn} do
47 |> assign(:user, user)
48 |> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"}))
51 assert response =~ "Remote follow"
54 test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
57 assert capture_log(fn ->
60 |> assign(:user, user)
62 remote_follow_path(conn, :follow, %{
63 acct: "https://mastodon.social/users/not_found"
68 assert response =~ "Error fetching user"
69 end) =~ "Object has been deleted"
73 describe "POST /ostatus_subscribe - do_remote_follow/2 with assigned user " do
74 test "follows user", %{conn: conn} do
80 |> assign(:user, user)
81 |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}})
84 assert response =~ "Account followed!"
85 assert user2.follower_address in User.following(user)
88 test "returns error when user is deactivated", %{conn: conn} do
89 user = insert(:user, deactivated: true)
94 |> assign(:user, user)
95 |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}})
98 assert response =~ "Error following account"
101 test "returns error when user is blocked", %{conn: conn} do
102 Pleroma.Config.put([:user, :deny_follow_blocked], true)
104 user2 = insert(:user)
106 {:ok, _user_block} = Pleroma.User.block(user2, user)
110 |> assign(:user, user)
111 |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}})
114 assert response =~ "Error following account"
117 test "returns error when followee not found", %{conn: conn} do
122 |> assign(:user, user)
123 |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => "jimm"}})
126 assert response =~ "Error following account"
129 test "returns success result when user already in followers", %{conn: conn} do
131 user2 = insert(:user)
132 {:ok, _, _, _} = CommonAPI.follow(user, user2)
136 |> assign(:user, refresh_record(user))
137 |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}})
140 assert response =~ "Account followed!"
144 describe "POST /ostatus_subscribe - do_remote_follow/2 without assigned user " do
145 test "follows", %{conn: conn} do
147 user2 = insert(:user)
151 |> post(remote_follow_path(conn, :do_follow), %{
152 "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
156 assert response =~ "Account followed!"
157 assert user2.follower_address in User.following(user)
160 test "returns error when followee not found", %{conn: conn} do
165 |> post(remote_follow_path(conn, :do_follow), %{
166 "authorization" => %{"name" => user.nickname, "password" => "test", "id" => "jimm"}
170 assert response =~ "Error following account"
173 test "returns error when login invalid", %{conn: conn} do
178 |> post(remote_follow_path(conn, :do_follow), %{
179 "authorization" => %{"name" => "jimm", "password" => "test", "id" => user.id}
183 assert response =~ "Wrong username or password"
186 test "returns error when password invalid", %{conn: conn} do
188 user2 = insert(:user)
192 |> post(remote_follow_path(conn, :do_follow), %{
193 "authorization" => %{"name" => user.nickname, "password" => "42", "id" => user2.id}
197 assert response =~ "Wrong username or password"
200 test "returns error when user is blocked", %{conn: conn} do
201 Pleroma.Config.put([:user, :deny_follow_blocked], true)
203 user2 = insert(:user)
204 {:ok, _user_block} = Pleroma.User.block(user2, user)
208 |> post(remote_follow_path(conn, :do_follow), %{
209 "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
213 assert response =~ "Error following account"