diff options
| author | Mark Felder <feld@FreeBSD.org> | 2020-09-23 11:56:22 -0500 | 
|---|---|---|
| committer | Mark Felder <feld@FreeBSD.org> | 2020-09-23 11:56:22 -0500 | 
| commit | f3a1f9c3bbb7321876a09b3846b5e10ecf4af94f (patch) | |
| tree | bcfd29188a841470cdeca478b1c5a3bbd4cc930a /test/web/mastodon_api | |
| parent | 34d7e864db8f9cc7fb73ce2fef8466ce8e09ed85 (diff) | |
| parent | e02101e15c425416975f756aca7f3b058006668d (diff) | |
| download | pleroma-f3a1f9c3bbb7321876a09b3846b5e10ecf4af94f.tar.gz pleroma-f3a1f9c3bbb7321876a09b3846b5e10ecf4af94f.zip  | |
Merge branch 'develop' into feature/bulk-confirmation
Diffstat (limited to 'test/web/mastodon_api')
7 files changed, 122 insertions, 69 deletions
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index 17a1e7d66..f7f1369e4 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -1442,7 +1442,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    describe "verify_credentials" do      test "verify_credentials" do        %{user: user, conn: conn} = oauth_access(["read:accounts"]) -      [notification | _] = insert_list(7, :notification, user: user) + +      [notification | _] = +        insert_list(7, :notification, user: user, activity: insert(:note_activity)) +        Pleroma.Notification.set_read_up_to(user, notification.id)        conn = get(conn, "/api/v1/accounts/verify_credentials") diff --git a/test/web/mastodon_api/controllers/auth_controller_test.exs b/test/web/mastodon_api/controllers/auth_controller_test.exs index 4fa95fce1..bf2438fe2 100644 --- a/test/web/mastodon_api/controllers/auth_controller_test.exs +++ b/test/web/mastodon_api/controllers/auth_controller_test.exs @@ -61,7 +61,7 @@ defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do      end      test "it returns 204", %{conn: conn} do -      assert json_response(conn, :no_content) +      assert empty_json_response(conn)      end      test "it creates a PasswordResetToken record for user", %{user: user} do @@ -91,7 +91,7 @@ defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do        assert conn               |> post("/auth/password?nickname=#{user.nickname}") -             |> json_response(:no_content) +             |> empty_json_response()        ObanHelpers.perform_all()        token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id) @@ -112,7 +112,7 @@ defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do        assert conn               |> post("/auth/password?nickname=#{user.nickname}") -             |> json_response(:no_content) +             |> empty_json_response()      end    end @@ -125,24 +125,21 @@ defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do      test "it returns 204 when user is not found", %{conn: conn, user: user} do        conn = post(conn, "/auth/password?email=nonexisting_#{user.email}") -      assert conn -             |> json_response(:no_content) +      assert empty_json_response(conn)      end      test "it returns 204 when user is not local", %{conn: conn, user: user} do        {:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))        conn = post(conn, "/auth/password?email=#{user.email}") -      assert conn -             |> json_response(:no_content) +      assert empty_json_response(conn)      end      test "it returns 204 when user is deactivated", %{conn: conn, user: user} do        {:ok, user} = Repo.update(Ecto.Changeset.change(user, deactivated: true, local: true))        conn = post(conn, "/auth/password?email=#{user.email}") -      assert conn -             |> json_response(:no_content) +      assert empty_json_response(conn)      end    end diff --git a/test/web/mastodon_api/controllers/marker_controller_test.exs b/test/web/mastodon_api/controllers/marker_controller_test.exs index 6dd40fb4a..9f0481120 100644 --- a/test/web/mastodon_api/controllers/marker_controller_test.exs +++ b/test/web/mastodon_api/controllers/marker_controller_test.exs @@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do      test "gets markers with correct scopes", %{conn: conn} do        user = insert(:user)        token = insert(:oauth_token, user: user, scopes: ["read:statuses"]) -      insert_list(7, :notification, user: user) +      insert_list(7, :notification, user: user, activity: insert(:note_activity))        {:ok, %{"notifications" => marker}} =          Pleroma.Marker.upsert( diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 24d1959f8..04dc6f445 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -282,18 +282,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        capture_log(fn ->          {:ok, %{id: activity_id}} =            CommonAPI.post(insert(:user), %{ -            status: "check out https://shitposter.club/notice/2827873" +            status: "check out http://mastodon.example.org/@admin/99541947525187367"            })          results =            conn -          |> get("/api/v1/search?q=https://shitposter.club/notice/2827873") +          |> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")            |> json_response_and_validate_schema(200) -        [status, %{"id" => ^activity_id}] = results["statuses"] - -        assert status["uri"] == -                 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" +        assert [ +                 %{"url" => "http://mastodon.example.org/@admin/99541947525187367"}, +                 %{"id" => ^activity_id} +               ] = results["statuses"]        end)      end diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index f221884e7..633a25e50 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -4,9 +4,9 @@  defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    use Pleroma.Web.ConnCase +  use Oban.Testing, repo: Pleroma.Repo    alias Pleroma.Activity -  alias Pleroma.ActivityExpiration    alias Pleroma.Config    alias Pleroma.Conversation.Participation    alias Pleroma.Object @@ -29,8 +29,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: oauth_access(["write:statuses"])      test "posting a status does not increment reblog_count when relaying", %{conn: conn} do -      Pleroma.Config.put([:instance, :federating], true) -      Pleroma.Config.get([:instance, :allow_relay], true) +      Config.put([:instance, :federating], true) +      Config.get([:instance, :allow_relay], true)        response =          conn @@ -103,7 +103,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        # An activity that will expire:        # 2 hours -      expires_in = 120 * 60 +      expires_in = 2 * 60 * 60 + +      expires_at = DateTime.add(DateTime.utc_now(), expires_in)        conn_four =          conn @@ -113,29 +115,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            "expires_in" => expires_in          }) -      assert fourth_response = -               %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200) - -      assert activity = Activity.get_by_id(fourth_id) -      assert expiration = ActivityExpiration.get_by_activity_id(fourth_id) - -      estimated_expires_at = -        NaiveDateTime.utc_now() -        |> NaiveDateTime.add(expires_in) -        |> NaiveDateTime.truncate(:second) +      assert %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200) -      # This assert will fail if the test takes longer than a minute. I sure hope it never does: -      assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60 +      assert Activity.get_by_id(fourth_id) -      assert fourth_response["pleroma"]["expires_at"] == -               NaiveDateTime.to_iso8601(expiration.scheduled_at) +      assert_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: fourth_id}, +        scheduled_at: expires_at +      )      end      test "it fails to create a status if `expires_in` is less or equal than an hour", %{        conn: conn      } do -      # 1 hour -      expires_in = 60 * 60 +      # 1 minute +      expires_in = 1 * 60        assert %{"error" => "Expiry date is too soon"} =                 conn @@ -146,8 +141,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 })                 |> json_response_and_validate_schema(422) -      # 30 minutes -      expires_in = 30 * 60 +      # 5 minutes +      expires_in = 5 * 60        assert %{"error" => "Expiry date is too soon"} =                 conn @@ -160,8 +155,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      end      test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do -      Pleroma.Config.put([:mrf_keyword, :reject], ["GNO"]) -      Pleroma.Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy]) +      Config.put([:mrf_keyword, :reject], ["GNO"]) +      Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])        assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =                 conn @@ -1146,6 +1141,52 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 |> post("/api/v1/statuses/#{activity_two.id}/pin")                 |> json_response_and_validate_schema(400)      end + +    test "on pin removes deletion job, on unpin reschedule deletion" do +      %{conn: conn} = oauth_access(["write:accounts", "write:statuses"]) +      expires_in = 2 * 60 * 60 + +      expires_at = DateTime.add(DateTime.utc_now(), expires_in) + +      assert %{"id" => id} = +               conn +               |> put_req_header("content-type", "application/json") +               |> post("api/v1/statuses", %{ +                 "status" => "oolong", +                 "expires_in" => expires_in +               }) +               |> json_response_and_validate_schema(200) + +      assert_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: id}, +        scheduled_at: expires_at +      ) + +      assert %{"id" => ^id, "pinned" => true} = +               conn +               |> put_req_header("content-type", "application/json") +               |> post("/api/v1/statuses/#{id}/pin") +               |> json_response_and_validate_schema(200) + +      refute_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: id}, +        scheduled_at: expires_at +      ) + +      assert %{"id" => ^id, "pinned" => false} = +               conn +               |> put_req_header("content-type", "application/json") +               |> post("/api/v1/statuses/#{id}/unpin") +               |> json_response_and_validate_schema(200) + +      assert_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: id}, +        scheduled_at: expires_at +      ) +    end    end    describe "cards" do @@ -1681,19 +1722,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    test "expires_at is nil for another user" do      %{conn: conn, user: user} = oauth_access(["read:statuses"]) +    expires_at = DateTime.add(DateTime.utc_now(), 1_000_000)      {:ok, activity} = CommonAPI.post(user, %{status: "foobar", expires_in: 1_000_000}) -    expires_at = -      activity.id -      |> ActivityExpiration.get_by_activity_id() -      |> Map.get(:scheduled_at) -      |> NaiveDateTime.to_iso8601() - -    assert %{"pleroma" => %{"expires_at" => ^expires_at}} = +    assert %{"pleroma" => %{"expires_at" => a_expires_at}} =               conn               |> get("/api/v1/statuses/#{activity.id}")               |> json_response_and_validate_schema(:ok) +    {:ok, a_expires_at, 0} = DateTime.from_iso8601(a_expires_at) +    assert DateTime.diff(expires_at, a_expires_at) == 0 +      %{conn: conn} = oauth_access(["read:statuses"])      assert %{"pleroma" => %{"expires_at" => nil}} = diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs index 517cabcff..c6e0268fd 100644 --- a/test/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs @@ -114,8 +114,16 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do        {:ok, _reply_from_friend} =          CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee}) -      res_conn = get(conn, "/api/v1/timelines/public") -      [%{"id" => ^activity_id}] = json_response_and_validate_schema(res_conn, 200) +      # Still shows replies from yourself +      {:ok, %{id: reply_from_me}} = +        CommonAPI.post(blocker, %{status: "status", in_reply_to_status_id: reply_from_blockee}) + +      response = +        get(conn, "/api/v1/timelines/public") +        |> json_response_and_validate_schema(200) + +      assert length(response) == 2 +      [%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response      end      test "doesn't return replies if follow is posting with users from blocked domain" do diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 9f22f9dcf..a5f39b215 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    use Pleroma.DataCase +  alias Pleroma.Config    alias Pleroma.User    alias Pleroma.UserRelationship    alias Pleroma.Web.CommonAPI @@ -68,7 +69,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          sensitive: false,          pleroma: %{            actor_type: "Person", -          discoverable: false +          discoverable: true          },          fields: []        }, @@ -166,7 +167,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          sensitive: false,          pleroma: %{            actor_type: "Service", -          discoverable: false +          discoverable: true          },          fields: []        }, @@ -448,7 +449,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do      test "shows unread_count only to the account owner" do        user = insert(:user) -      insert_list(7, :notification, user: user) +      insert_list(7, :notification, user: user, activity: insert(:note_activity))        other_user = insert(:user)        user = User.get_cached_by_ap_id(user.ap_id) @@ -540,8 +541,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do      end    end -  test "uses mediaproxy urls when it's enabled" do +  test "uses mediaproxy urls when it's enabled (regardless of media preview proxy state)" do      clear_config([:media_proxy, :enabled], true) +    clear_config([:media_preview_proxy, :enabled])      user =        insert(:user, @@ -550,20 +552,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          emoji: %{"joker_smile" => "https://evil.website/society.png"}        ) -    AccountView.render("show.json", %{user: user, skip_visibility_check: true}) -    |> Enum.all?(fn -      {key, url} when key in [:avatar, :avatar_static, :header, :header_static] -> -        String.starts_with?(url, Pleroma.Web.base_url()) - -      {:emojis, emojis} -> -        Enum.all?(emojis, fn %{url: url, static_url: static_url} -> -          String.starts_with?(url, Pleroma.Web.base_url()) && -            String.starts_with?(static_url, Pleroma.Web.base_url()) -        end) - -      _ -> -        true -    end) -    |> assert() +    with media_preview_enabled <- [false, true] do +      Config.put([:media_preview_proxy, :enabled], media_preview_enabled) + +      AccountView.render("show.json", %{user: user, skip_visibility_check: true}) +      |> Enum.all?(fn +        {key, url} when key in [:avatar, :avatar_static, :header, :header_static] -> +          String.starts_with?(url, Pleroma.Web.base_url()) + +        {:emojis, emojis} -> +          Enum.all?(emojis, fn %{url: url, static_url: static_url} -> +            String.starts_with?(url, Pleroma.Web.base_url()) && +              String.starts_with?(static_url, Pleroma.Web.base_url()) +          end) + +        _ -> +          true +      end) +      |> assert() +    end    end  end  | 
