diff options
Diffstat (limited to 'test')
8 files changed, 82 insertions, 33 deletions
| diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index 2d4c7f63b..0226b2a5d 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -33,16 +33,18 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do    test "refuses invalid requests" do      capture_log(fn -> -      assert {:error, {404, _}} = start_socket() -      assert {:error, {404, _}} = start_socket("?stream=ncjdk") +      assert {:error, %WebSockex.RequestError{code: 404}} = start_socket() +      assert {:error, %WebSockex.RequestError{code: 404}} = start_socket("?stream=ncjdk")        Process.sleep(30)      end)    end    test "requires authentication and a valid token for protected streams" do      capture_log(fn -> -      assert {:error, {401, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa") -      assert {:error, {401, _}} = start_socket("?stream=user") +      assert {:error, %WebSockex.RequestError{code: 401}} = +               start_socket("?stream=user&access_token=aaaaaaaaaaaa") + +      assert {:error, %WebSockex.RequestError{code: 401}} = start_socket("?stream=user")        Process.sleep(30)      end)    end @@ -102,7 +104,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do        assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")        capture_log(fn -> -        assert {:error, {401, _}} = start_socket("?stream=user") +        assert {:error, %WebSockex.RequestError{code: 401}} = start_socket("?stream=user")          Process.sleep(30)        end)      end @@ -111,7 +113,9 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do        assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")        capture_log(fn -> -        assert {:error, {401, _}} = start_socket("?stream=user:notification") +        assert {:error, %WebSockex.RequestError{code: 401}} = +                 start_socket("?stream=user:notification") +          Process.sleep(30)        end)      end @@ -120,7 +124,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do        assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])        capture_log(fn -> -        assert {:error, {401, _}} = +        assert {:error, %WebSockex.RequestError{code: 401}} =                   start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])          Process.sleep(30) diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 0dc45beb9..11789b64d 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -311,7 +311,7 @@ defmodule Pleroma.UserTest do    describe "unfollow/2" do      setup do: clear_config([:instance, :external_user_synchronization]) -    test "unfollow with syncronizes external user" do +    test "unfollow with synchronizes external user" do        clear_config([:instance, :external_user_synchronization], true)        followed = @@ -2265,7 +2265,7 @@ defmodule Pleroma.UserTest do        assert other_user.follower_count == 1      end -    test "syncronizes the counters with the remote instance for the followed when enabled" do +    test "synchronizes the counters with the remote instance for the followed when enabled" do        clear_config([:instance, :external_user_synchronization], false)        user = insert(:user) @@ -2287,7 +2287,7 @@ defmodule Pleroma.UserTest do        assert other_user.follower_count == 437      end -    test "syncronizes the counters with the remote instance for the follower when enabled" do +    test "synchronizes the counters with the remote instance for the follower when enabled" do        clear_config([:instance, :external_user_synchronization], false)        user = insert(:user) diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index b8d73ea10..13f3d93b8 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1662,7 +1662,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    end    describe "fetch_follow_information_for_user" do -    test "syncronizes following/followers counters" do +    test "synchronizes following/followers counters" do        user =          insert(:user,            local: false, diff --git a/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs b/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs index 2601a026f..9511dccea 100644 --- a/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs @@ -3,7 +3,7 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Web.AdminAPI.InstanceDocumentControllerTest do -  use Pleroma.Web.ConnCase, async: true +  use Pleroma.Web.ConnCase    import Pleroma.Factory    @dir "test/tmp/instance_static" diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index ba7293d36..2bf4edb70 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -2119,4 +2119,48 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do                 |> json_response_and_validate_schema(400)      end    end + +  describe "remove from followers" do +    setup do: oauth_access(["follow"]) + +    test "removing user from followers", %{conn: conn, user: user} do +      %{id: other_user_id} = other_user = insert(:user) + +      CommonAPI.follow(other_user, user) + +      assert %{"id" => ^other_user_id, "followed_by" => false} = +               conn +               |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers") +               |> json_response_and_validate_schema(200) + +      refute User.following?(other_user, user) +    end + +    test "removing remote user from followers", %{conn: conn, user: user} do +      %{id: other_user_id} = other_user = insert(:user, local: false) + +      CommonAPI.follow(other_user, user) + +      assert User.following?(other_user, user) + +      assert %{"id" => ^other_user_id, "followed_by" => false} = +               conn +               |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers") +               |> json_response_and_validate_schema(200) + +      refute User.following?(other_user, user) +    end + +    test "removing user from followers errors", %{user: user, conn: conn} do +      # self remove +      conn_res = post(conn, "/api/v1/accounts/#{user.id}/remove_from_followers") + +      assert %{"error" => "Can not unfollow yourself"} = +               json_response_and_validate_schema(conn_res, 400) + +      # remove non existing user +      conn_res = post(conn, "/api/v1/accounts/doesntexist/remove_from_followers") +      assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404) +    end +  end  end diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index 1328b42c9..b13a8033b 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -944,7 +944,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do      end    end -  describe "hashtag timeline handling of :restrict_unauthenticated setting" do +  describe "hashtag timeline handling of restrict_unauthenticated setting" do      setup do        user = insert(:user)        {:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"}) diff --git a/test/pleroma/web/media_proxy/invalidation/script_test.exs b/test/pleroma/web/media_proxy/invalidation/script_test.exs index 39ef365f4..3e8fd751d 100644 --- a/test/pleroma/web/media_proxy/invalidation/script_test.exs +++ b/test/pleroma/web/media_proxy/invalidation/script_test.exs @@ -10,11 +10,14 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do    test "it logs error when script is not found" do      assert capture_log(fn -> -             assert Invalidation.Script.purge( -                      ["http://example.com/media/example.jpg"], -                      script_path: "./example" -                    ) == {:error, "%ErlangError{original: :enoent}"} -           end) =~ "Error while cache purge: %ErlangError{original: :enoent}" +             assert {:error, msg} = +                      Invalidation.Script.purge( +                        ["http://example.com/media/example.jpg"], +                        script_path: "./example" +                      ) + +             assert msg =~ ~r/%ErlangError{original: :enoent(, reason: nil)?}/ +           end) =~ ~r/Error while cache purge: %ErlangError{original: :enoent(, reason: nil)?}/      capture_log(fn ->        assert Invalidation.Script.purge( diff --git a/test/support/websocket_client.ex b/test/support/websocket_client.ex index d149b324e..cf2972c38 100644 --- a/test/support/websocket_client.ex +++ b/test/support/websocket_client.ex @@ -5,18 +5,17 @@  defmodule Pleroma.Integration.WebsocketClient do    # https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs +  use WebSockex +    @doc """    Starts the WebSocket server for given ws URL. Received Socket.Message's    are forwarded to the sender pid    """    def start_link(sender, url, headers \\ []) do -    :crypto.start() -    :ssl.start() - -    :websocket_client.start_link( -      String.to_charlist(url), +    WebSockex.start_link( +      url,        __MODULE__, -      [sender], +      %{sender: sender},        extra_headers: headers      )    end @@ -36,27 +35,26 @@ defmodule Pleroma.Integration.WebsocketClient do    end    @doc false -  def init([sender], _conn_state) do -    {:ok, %{sender: sender}} -  end - -  @doc false -  def websocket_handle(frame, _conn_state, state) do +  @impl true +  def handle_frame(frame, state) do      send(state.sender, frame)      {:ok, state}    end    @doc false -  def websocket_info({:text, msg}, _conn_state, state) do +  @impl true +  def handle_info({:text, msg}, state) do      {:reply, {:text, msg}, state}    end -  def websocket_info(:close, _conn_state, _state) do +  @impl true +  def handle_info(:close, _state) do      {:close, <<>>, "done"}    end    @doc false -  def websocket_terminate(_reason, _conn_state, _state) do +  @impl true +  def terminate(_reason, _state) do      :ok    end  end | 
