diff options
Diffstat (limited to 'test/web/mastodon_api')
| -rw-r--r-- | test/web/mastodon_api/controllers/account_controller_test.exs | 68 | ||||
| -rw-r--r-- | test/web/mastodon_api/controllers/marker_controller_test.exs | 10 | ||||
| -rw-r--r-- | test/web/mastodon_api/controllers/subscription_controller_test.exs | 13 | ||||
| -rw-r--r-- | test/web/mastodon_api/controllers/suggestion_controller_test.exs | 26 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/account_view_test.exs | 16 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/marker_view_test.exs | 8 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/subscription_view_test.exs (renamed from test/web/mastodon_api/views/push_subscription_view_test.exs) | 6 | 
7 files changed, 87 insertions, 60 deletions
| diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index 133d7f642..32a9d85a8 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -1028,6 +1028,74 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        assert json_response(res, 403) == %{"error" => "Invalid credentials"}      end + +    test "registration from trusted app" do +      clear_config([Pleroma.Captcha, :enabled], true) +      app = insert(:oauth_app, trusted: true, scopes: ["read", "write", "follow", "push"]) + +      conn = +        build_conn() +        |> post("/oauth/token", %{ +          "grant_type" => "client_credentials", +          "client_id" => app.client_id, +          "client_secret" => app.client_secret +        }) + +      assert %{"access_token" => token, "token_type" => "Bearer"} = json_response(conn, 200) + +      response = +        build_conn() +        |> Plug.Conn.put_req_header("authorization", "Bearer " <> token) +        |> put_req_header("content-type", "multipart/form-data") +        |> post("/api/v1/accounts", %{ +          nickname: "nickanme", +          agreement: true, +          email: "email@example.com", +          fullname: "Lain", +          username: "Lain", +          password: "some_password", +          confirm: "some_password" +        }) +        |> json_response(200) + +      assert %{ +               "access_token" => access_token, +               "created_at" => _, +               "scope" => ["read", "write", "follow", "push"], +               "token_type" => "Bearer" +             } = response + +      response = +        build_conn() +        |> Plug.Conn.put_req_header("authorization", "Bearer " <> access_token) +        |> get("/api/v1/accounts/verify_credentials") +        |> json_response(200) + +      assert %{ +               "acct" => "Lain", +               "bot" => false, +               "display_name" => "Lain", +               "follow_requests_count" => 0, +               "followers_count" => 0, +               "following_count" => 0, +               "locked" => false, +               "note" => "", +               "source" => %{ +                 "fields" => [], +                 "note" => "", +                 "pleroma" => %{ +                   "actor_type" => "Person", +                   "discoverable" => false, +                   "no_rich_text" => false, +                   "show_role" => true +                 }, +                 "privacy" => "public", +                 "sensitive" => false +               }, +               "statuses_count" => 0, +               "username" => "Lain" +             } = response +    end    end    describe "create account by app / rate limit" do diff --git a/test/web/mastodon_api/controllers/marker_controller_test.exs b/test/web/mastodon_api/controllers/marker_controller_test.exs index 7280abd10..919f295bd 100644 --- a/test/web/mastodon_api/controllers/marker_controller_test.exs +++ b/test/web/mastodon_api/controllers/marker_controller_test.exs @@ -11,7 +11,6 @@ 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)        {:ok, %{"notifications" => marker}} =          Pleroma.Marker.upsert( @@ -30,8 +29,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69420",                   "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at), -                 "version" => 0, -                 "pleroma" => %{"unread_count" => 7} +                 "version" => 0                 }               }      end @@ -72,8 +70,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69420",                   "updated_at" => _, -                 "version" => 0, -                 "pleroma" => %{"unread_count" => 0} +                 "version" => 0                 }               } = response      end @@ -102,8 +99,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69888",                   "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at), -                 "version" => 0, -                 "pleroma" => %{"unread_count" => 0} +                 "version" => 0                 }               }      end diff --git a/test/web/mastodon_api/controllers/subscription_controller_test.exs b/test/web/mastodon_api/controllers/subscription_controller_test.exs index 987158a74..5682498c0 100644 --- a/test/web/mastodon_api/controllers/subscription_controller_test.exs +++ b/test/web/mastodon_api/controllers/subscription_controller_test.exs @@ -35,7 +35,10 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do      quote do        vapid_details = Application.get_env(:web_push_encryption, :vapid_details, [])        Application.put_env(:web_push_encryption, :vapid_details, []) -      assert "Something went wrong" == unquote(yield) + +      assert %{"error" => "Web push subscription is disabled on this Pleroma instance"} == +               unquote(yield) +        Application.put_env(:web_push_encryption, :vapid_details, vapid_details)      end    end @@ -45,7 +48,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do        assert_error_when_disable_push do          conn          |> post("/api/v1/push/subscription", %{}) -        |> json_response(500) +        |> json_response(403)        end      end @@ -74,7 +77,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do        assert_error_when_disable_push do          conn          |> get("/api/v1/push/subscription", %{}) -        |> json_response(500) +        |> json_response(403)        end      end @@ -127,7 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do        assert_error_when_disable_push do          conn          |> put("/api/v1/push/subscription", %{data: %{"alerts" => %{"mention" => false}}}) -        |> json_response(500) +        |> json_response(403)        end      end @@ -155,7 +158,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do        assert_error_when_disable_push do          conn          |> delete("/api/v1/push/subscription", %{}) -        |> json_response(500) +        |> json_response(403)        end      end diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs index c697a39f8..8d0e70db8 100644 --- a/test/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -7,34 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do    alias Pleroma.Config -  import Pleroma.Factory -  import Tesla.Mock -    setup do: oauth_access(["read"]) -  setup %{user: user} do -    other_user = insert(:user) -    host = Config.get([Pleroma.Web.Endpoint, :url, :host]) -    url500 = "http://test500?#{host}&#{user.nickname}" -    url200 = "http://test200?#{host}&#{user.nickname}" - -    mock(fn -      %{method: :get, url: ^url500} -> -        %Tesla.Env{status: 500, body: "bad request"} - -      %{method: :get, url: ^url200} -> -        %Tesla.Env{ -          status: 200, -          body: -            ~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{ -              other_user.ap_id -            }","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}]) -        } -    end) - -    [other_user: other_user] -  end -    test "returns empty result", %{conn: conn} do      res =        conn diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 4435f69ff..85fa4f6a2 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -19,16 +19,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    end    test "Represent a user account" do -    source_data = %{ -      "tag" => [ -        %{ -          "type" => "Emoji", -          "icon" => %{"url" => "/file.png"}, -          "name" => ":karjalanpiirakka:" -        } -      ] -    } -      background_image = %{        "url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]      } @@ -37,13 +27,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        insert(:user, %{          follower_count: 3,          note_count: 5, -        source_data: source_data,          background: background_image,          nickname: "shp@shitposter.club",          name: ":karjalanpiirakka: shp",          bio:            "<script src=\"invalid-html\"></script><span>valid html</span>. a<br>b<br/>c<br >d<br />f", -        inserted_at: ~N[2017-08-15 15:47:06.597036] +        inserted_at: ~N[2017-08-15 15:47:06.597036], +        emoji: %{"karjalanpiirakka" => "/file.png"}        })      expected = %{ @@ -117,7 +107,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        insert(:user, %{          follower_count: 3,          note_count: 5, -        source_data: %{},          actor_type: "Service",          nickname: "shp@shitposter.club",          inserted_at: ~N[2017-08-15 15:47:06.597036] @@ -311,7 +300,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        insert(:user, %{          follower_count: 0,          note_count: 5, -        source_data: %{},          actor_type: "Service",          nickname: "shp@shitposter.club",          inserted_at: ~N[2017-08-15 15:47:06.597036] diff --git a/test/web/mastodon_api/views/marker_view_test.exs b/test/web/mastodon_api/views/marker_view_test.exs index 48a0a6d33..893cf8857 100644 --- a/test/web/mastodon_api/views/marker_view_test.exs +++ b/test/web/mastodon_api/views/marker_view_test.exs @@ -8,21 +8,19 @@ defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do    import Pleroma.Factory    test "returns markers" do -    marker1 = insert(:marker, timeline: "notifications", last_read_id: "17", unread_count: 5) +    marker1 = insert(:marker, timeline: "notifications", last_read_id: "17")      marker2 = insert(:marker, timeline: "home", last_read_id: "42")      assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{               "home" => %{                 last_read_id: "42",                 updated_at: NaiveDateTime.to_iso8601(marker2.updated_at), -               version: 0, -               pleroma: %{unread_count: 0} +               version: 0               },               "notifications" => %{                 last_read_id: "17",                 updated_at: NaiveDateTime.to_iso8601(marker1.updated_at), -               version: 0, -               pleroma: %{unread_count: 5} +               version: 0               }             }    end diff --git a/test/web/mastodon_api/views/push_subscription_view_test.exs b/test/web/mastodon_api/views/subscription_view_test.exs index 10c6082a5..981524c0e 100644 --- a/test/web/mastodon_api/views/push_subscription_view_test.exs +++ b/test/web/mastodon_api/views/subscription_view_test.exs @@ -2,10 +2,10 @@  # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do +defmodule Pleroma.Web.MastodonAPI.SubscriptionViewTest do    use Pleroma.DataCase    import Pleroma.Factory -  alias Pleroma.Web.MastodonAPI.PushSubscriptionView, as: View +  alias Pleroma.Web.MastodonAPI.SubscriptionView, as: View    alias Pleroma.Web.Push    test "Represent a subscription" do @@ -18,6 +18,6 @@ defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do        server_key: Keyword.get(Push.vapid_config(), :public_key)      } -    assert expected == View.render("push_subscription.json", %{subscription: subscription}) +    assert expected == View.render("show.json", %{subscription: subscription})    end  end | 
