diff options
Diffstat (limited to 'test/web/mastodon_api/controllers')
4 files changed, 47 insertions, 37 deletions
| diff --git a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs index b693c1a47..2d256f63c 100644 --- a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs +++ b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs @@ -82,9 +82,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do        assert user_data = json_response(conn, 200)        assert user_data["note"] == -               ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a data-user="#{ +               ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{                   user2.id -               }" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..) +               }" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)      end      test "updates the user's locking status", %{conn: conn} do @@ -273,7 +273,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do      test "update fields", %{conn: conn} do        fields = [          %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "<script>bar</script>"}, -        %{"name" => "link", "value" => "cofe.io"} +        %{"name" => "link.io", "value" => "cofe.io"}        ]        account_data = @@ -283,7 +283,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do        assert account_data["fields"] == [                 %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"}, -               %{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)} +               %{ +                 "name" => "link.io", +                 "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>) +               }               ]        assert account_data["source"]["fields"] == [ @@ -291,14 +294,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do                   "name" => "<a href=\"http://google.com\">foo</a>",                   "value" => "<script>bar</script>"                 }, -               %{"name" => "link", "value" => "cofe.io"} +               %{"name" => "link.io", "value" => "cofe.io"}               ] +    end +    test "update fields via x-www-form-urlencoded", %{conn: conn} do        fields =          [            "fields_attributes[1][name]=link", -          "fields_attributes[1][value]=cofe.io", -          "fields_attributes[0][name]=<a href=\"http://google.com\">foo</a>", +          "fields_attributes[1][value]=http://cofe.io", +          "fields_attributes[0][name]=foo",            "fields_attributes[0][value]=bar"          ]          |> Enum.join("&") @@ -310,32 +315,49 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do          |> json_response(200)        assert account["fields"] == [ -               %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"}, -               %{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)} +               %{"name" => "foo", "value" => "bar"}, +               %{ +                 "name" => "link", +                 "value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>) +               }               ]        assert account["source"]["fields"] == [ -               %{ -                 "name" => "<a href=\"http://google.com\">foo</a>", -                 "value" => "bar" -               }, -               %{"name" => "link", "value" => "cofe.io"} +               %{"name" => "foo", "value" => "bar"}, +               %{"name" => "link", "value" => "http://cofe.io"}               ] +    end +    test "update fields with empty name", %{conn: conn} do +      fields = [ +        %{"name" => "foo", "value" => ""}, +        %{"name" => "", "value" => "bar"} +      ] + +      account = +        conn +        |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields}) +        |> json_response(200) + +      assert account["fields"] == [ +               %{"name" => "foo", "value" => ""} +             ] +    end + +    test "update fields when invalid request", %{conn: conn} do        name_limit = Pleroma.Config.get([:instance, :account_field_name_length])        value_limit = Pleroma.Config.get([:instance, :account_field_value_length]) +      long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()        long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join() -      fields = [%{"name" => "<b>foo<b>", "value" => long_value}] +      fields = [%{"name" => "foo", "value" => long_value}]        assert %{"error" => "Invalid request"} ==                 conn                 |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})                 |> json_response(403) -      long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join() -        fields = [%{"name" => long_name, "value" => "bar"}]        assert %{"error" => "Invalid request"} == @@ -346,7 +368,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do        Pleroma.Config.put([:instance, :max_account_fields], 1)        fields = [ -        %{"name" => "<b>foo<b>", "value" => "<i>bar</i>"}, +        %{"name" => "foo", "value" => "bar"},          %{"name" => "link", "value" => "cofe.io"}        ] @@ -354,20 +376,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do                 conn                 |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})                 |> json_response(403) - -      fields = [ -        %{"name" => "foo", "value" => ""}, -        %{"name" => "", "value" => "bar"} -      ] - -      account = -        conn -        |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields}) -        |> json_response(200) - -      assert account["fields"] == [ -               %{"name" => "foo", "value" => ""} -             ]      end    end  end diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index a9fa0ce48..a450a732c 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -794,7 +794,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      test "Account registration via Application", %{conn: conn} do        conn = -        post(conn, "/api/v1/apps", %{ +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/apps", %{            client_name: "client_name",            redirect_uris: "urn:ietf:wg:oauth:2.0:oob",            scopes: "read, write, follow" diff --git a/test/web/mastodon_api/controllers/app_controller_test.exs b/test/web/mastodon_api/controllers/app_controller_test.exs index 77d234d67..e7b11d14e 100644 --- a/test/web/mastodon_api/controllers/app_controller_test.exs +++ b/test/web/mastodon_api/controllers/app_controller_test.exs @@ -16,8 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do      conn =        conn -      |> assign(:user, token.user) -      |> assign(:token, token) +      |> put_req_header("authorization", "Bearer #{token.token}")        |> get("/api/v1/apps/verify_credentials")      app = Repo.preload(token, :app).app @@ -37,6 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do      conn =        conn +      |> put_req_header("content-type", "application/json")        |> assign(:user, user)        |> post("/api/v1/apps", %{          client_name: app_attrs.client_name, diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index 344eabb4a..6f1fab069 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -26,7 +26,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do        |> get("/api/v1/notifications")      expected_response = -      "hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{ +      "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{          user.ap_id        }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>" @@ -45,7 +45,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do      conn = get(conn, "/api/v1/notifications/#{notification.id}")      expected_response = -      "hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{ +      "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{          user.ap_id        }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>" | 
