diff options
| author | Roman Chvanikov <chvanikoff@pm.me> | 2019-09-14 18:29:51 +0300 | 
|---|---|---|
| committer | Roman Chvanikov <chvanikoff@pm.me> | 2019-09-14 18:29:51 +0300 | 
| commit | d7457c9165b83c0f1514cf0532b5a8bdc515ea02 (patch) | |
| tree | 65209338d595c55397f85ad2295bc48b778b820e /test | |
| parent | 0bd2b85edbf3b7062570778649cf2b77cc7a0bce (diff) | |
| parent | 3ae448b592214b43af1d079c997c6f6b91d31aeb (diff) | |
| download | pleroma-d7457c9165b83c0f1514cf0532b5a8bdc515ea02.tar.gz pleroma-d7457c9165b83c0f1514cf0532b5a8bdc515ea02.zip  | |
Merge branch 'develop' into refactor/subscription
Diffstat (limited to 'test')
| -rw-r--r-- | test/activity_test.exs | 8 | ||||
| -rw-r--r-- | test/integration/mastodon_websocket_test.exs | 29 | ||||
| -rw-r--r-- | test/web/activity_pub/publisher_test.exs | 24 | ||||
| -rw-r--r-- | test/web/activity_pub/relay_test.exs | 13 | ||||
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 67 | ||||
| -rw-r--r-- | test/web/twitter_api/util_controller_test.exs | 13 | ||||
| -rw-r--r-- | test/web/web_finger/web_finger_controller_test.exs | 13 | 
7 files changed, 127 insertions, 40 deletions
diff --git a/test/activity_test.exs b/test/activity_test.exs index f9f789a76..275cab81e 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -213,7 +213,11 @@ defmodule Pleroma.ActivityTest do      assert [] == Activity.all_by_actor_and_id(user, []) -    assert [%Activity{id: ^id2}, %Activity{id: ^id1}] = -             Activity.all_by_actor_and_id(user.ap_id, [id1, id2]) +    activities = +      user.ap_id +      |> Activity.all_by_actor_and_id([id1, id2]) +      |> Enum.sort(&(&1.id < &2.id)) + +    assert [%Activity{id: ^id1}, %Activity{id: ^id2}] = activities    end  end diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs index 3975cdcd6..63bf73412 100644 --- a/test/integration/mastodon_websocket_test.exs +++ b/test/integration/mastodon_websocket_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.Integration.MastodonWebsocketTest do    use Pleroma.DataCase +  import ExUnit.CaptureLog    import Pleroma.Factory    alias Pleroma.Integration.WebsocketClient @@ -39,13 +40,17 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do    end    test "refuses invalid requests" do -    assert {:error, {400, _}} = start_socket() -    assert {:error, {404, _}} = start_socket("?stream=ncjdk") +    capture_log(fn -> +      assert {:error, {400, _}} = start_socket() +      assert {:error, {404, _}} = start_socket("?stream=ncjdk") +    end)    end    test "requires authentication and a valid token for protected streams" do -    assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa") -    assert {:error, {403, _}} = start_socket("?stream=user") +    capture_log(fn -> +      assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa") +      assert {:error, {403, _}} = start_socket("?stream=user") +    end)    end    test "allows public streams without authentication" do @@ -100,19 +105,27 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do      test "accepts the 'user' stream", %{token: token} = _state do        assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}") -      assert {:error, {403, "Forbidden"}} = start_socket("?stream=user") + +      assert capture_log(fn -> +               assert {:error, {403, "Forbidden"}} = start_socket("?stream=user") +             end) =~ ":badarg"      end      test "accepts the 'user:notification' stream", %{token: token} = _state do        assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}") -      assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification") + +      assert capture_log(fn -> +               assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification") +             end) =~ ":badarg"      end      test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do        assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}]) -      assert {:error, {403, "Forbidden"}} = -               start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}]) +      assert capture_log(fn -> +               assert {:error, {403, "Forbidden"}} = +                        start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}]) +             end) =~ ":badarg"      end    end  end diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs index 36a39c84c..381757e1b 100644 --- a/test/web/activity_pub/publisher_test.exs +++ b/test/web/activity_pub/publisher_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.Web.ActivityPub.PublisherTest do    use Pleroma.DataCase +  import ExUnit.CaptureLog    import Pleroma.Factory    import Tesla.Mock    import Mock @@ -188,7 +189,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do        actor = insert(:user)        inbox = "http://connrefused.site/users/nick1/inbox" -      assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) +      assert capture_log(fn -> +               assert {:error, _} = +                        Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) +             end) =~ "connrefused"        assert called(Instances.set_unreachable(inbox))      end @@ -212,14 +216,16 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do        actor = insert(:user)        inbox = "http://connrefused.site/users/nick1/inbox" -      assert {:error, _} = -               Publisher.publish_one(%{ -                 inbox: inbox, -                 json: "{}", -                 actor: actor, -                 id: 1, -                 unreachable_since: NaiveDateTime.utc_now() -               }) +      assert capture_log(fn -> +               assert {:error, _} = +                        Publisher.publish_one(%{ +                          inbox: inbox, +                          json: "{}", +                          actor: actor, +                          id: 1, +                          unreachable_since: NaiveDateTime.utc_now() +                        }) +             end) =~ "connrefused"        refute called(Instances.set_unreachable(inbox))      end diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs index 4f7d592a6..9db4255d8 100644 --- a/test/web/activity_pub/relay_test.exs +++ b/test/web/activity_pub/relay_test.exs @@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Relay +  import ExUnit.CaptureLog    import Pleroma.Factory    import Mock @@ -20,7 +21,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do    describe "follow/1" do      test "returns errors when user not found" do -      assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"} +      assert capture_log(fn -> +               assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"} +             end) =~ "Could not fetch by AP id"      end      test "returns activity" do @@ -37,7 +40,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do    describe "unfollow/1" do      test "returns errors when user not found" do -      assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"} +      assert capture_log(fn -> +               assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"} +             end) =~ "Could not fetch by AP id"      end      test "returns activity" do @@ -78,7 +83,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do            }          ) -      assert Relay.publish(activity) == {:error, nil} +      assert capture_log(fn -> +               assert Relay.publish(activity) == {:error, nil} +             end) =~ "[error] error: nil"      end      test_with_mock "returns announce activity and publish to federate", diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 95fcecc52..27a8366f7 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -3890,7 +3890,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do          build_conn()          |> assign(:user, user) -      [conn: conn, activity: activity] +      [conn: conn, activity: activity, user: user]      end      test "returns users who have favorited the status", %{conn: conn, activity: activity} do @@ -3950,6 +3950,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        [%{"id" => id}] = response        assert id == other_user.id      end + +    test "requires authentification for private posts", %{conn: conn, user: user} do +      other_user = insert(:user) + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "status" => "@#{other_user.nickname} wanna get some #cofe together?", +          "visibility" => "direct" +        }) + +      {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) + +      conn +      |> assign(:user, nil) +      |> get("/api/v1/statuses/#{activity.id}/favourited_by") +      |> json_response(404) + +      response = +        build_conn() +        |> assign(:user, other_user) +        |> get("/api/v1/statuses/#{activity.id}/favourited_by") +        |> json_response(200) + +      [%{"id" => id}] = response +      assert id == other_user.id +    end    end    describe "GET /api/v1/statuses/:id/reblogged_by" do @@ -3961,7 +3987,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do          build_conn()          |> assign(:user, user) -      [conn: conn, activity: activity] +      [conn: conn, activity: activity, user: user]      end      test "returns users who have reblogged the status", %{conn: conn, activity: activity} do @@ -4021,6 +4047,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        [%{"id" => id}] = response        assert id == other_user.id      end + +    test "requires authentification for private posts", %{conn: conn, user: user} do +      other_user = insert(:user) + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "status" => "@#{other_user.nickname} wanna get some #cofe together?", +          "visibility" => "direct" +        }) + +      conn +      |> assign(:user, nil) +      |> get("/api/v1/statuses/#{activity.id}/reblogged_by") +      |> json_response(404) + +      response = +        build_conn() +        |> assign(:user, other_user) +        |> get("/api/v1/statuses/#{activity.id}/reblogged_by") +        |> json_response(200) + +      assert [] == response +    end    end    describe "POST /auth/password, with valid parameters" do @@ -4155,13 +4204,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        Config.put([:suggestions, :enabled], true)        Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}") -      res = -        conn -        |> assign(:user, user) -        |> get("/api/v1/suggestions") -        |> json_response(500) +      assert capture_log(fn -> +               res = +                 conn +                 |> assign(:user, user) +                 |> get("/api/v1/suggestions") +                 |> json_response(500) -      assert res == "Something went wrong" +               assert res == "Something went wrong" +             end) =~ "Could not retrieve suggestions"      end      test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index a3c6145c0..187abf427 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do    alias Pleroma.Repo    alias Pleroma.User    alias Pleroma.Web.CommonAPI +  import ExUnit.CaptureLog    import Pleroma.Factory    import Mock @@ -338,12 +339,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do      test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do        user = insert(:user) -      response = -        conn -        |> assign(:user, user) -        |> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found") +      assert capture_log(fn -> +               response = +                 conn +                 |> assign(:user, user) +                 |> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found") -      assert html_response(response, 200) =~ "Error fetching user" +               assert html_response(response, 200) =~ "Error fetching user" +             end) =~ "Object has been deleted"      end    end diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs index e23086b2a..bd3ccaaf7 100644 --- a/test/web/web_finger/web_finger_controller_test.exs +++ b/test/web/web_finger/web_finger_controller_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do    use Pleroma.Web.ConnCase +  import ExUnit.CaptureLog    import Pleroma.Factory    import Tesla.Mock @@ -75,11 +76,13 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do    test "Sends a 404 when invalid format" do      user = insert(:user) -    assert_raise Phoenix.NotAcceptableError, fn -> -      build_conn() -      |> put_req_header("accept", "text/html") -      |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost") -    end +    assert capture_log(fn -> +             assert_raise Phoenix.NotAcceptableError, fn -> +               build_conn() +               |> put_req_header("accept", "text/html") +               |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost") +             end +           end) =~ "no supported media type in accept header"    end    test "Sends a 400 when resource param is missing" do  | 
