From f2badd4424a362f30409113142bfca750ec61214 Mon Sep 17 00:00:00 2001 From: Vivian Lim Date: Sat, 23 Jun 2018 22:21:39 -0700 Subject: [PATCH 1/4] return empty array for api/qvitter/mutes.json queries instead of html --- lib/pleroma/web/router.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 13bd393ab..a502ba4d5 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -269,6 +269,7 @@ def user_fetcher(username) do get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array) get("/mutes/users/ids", TwitterAPI.Controller, :empty_array) + get("/qvitter/mutes.json", TwitterAPI.Controller, :empty_array) get("/externalprofile/show", TwitterAPI.Controller, :external_profile) end From 631600394694c1f90d0ecfc1432e46c1c54ca748 Mon Sep 17 00:00:00 2001 From: Vivian Lim Date: Sat, 23 Jun 2018 23:05:54 -0700 Subject: [PATCH 2/4] fixes- found that TwitterAPI.Controller adds .json suffix already --- lib/pleroma/web/router.ex | 2 +- .../twitter_api_controller_test.exs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index a502ba4d5..b65850aaa 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -269,7 +269,7 @@ def user_fetcher(username) do get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array) get("/mutes/users/ids", TwitterAPI.Controller, :empty_array) - get("/qvitter/mutes.json", TwitterAPI.Controller, :empty_array) + get("/qvitter/mutes", TwitterAPI.Controller, :empty_array) get("/externalprofile/show", TwitterAPI.Controller, :external_profile) end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 806227110..edc8cbff8 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -491,6 +491,25 @@ test "with credentials", %{conn: conn, user: current_user} do end end + describe "GET /api/qvitter/mutes.json" do + setup [:valid_user] + + test "unimplemented mutes without valid credentials", %{conn: conn} do + conn = get(conn, "/api/qvitter/mutes.json") + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> get("/api/qvitter/mutes.json") + current_user = Repo.get(User, current_user.id) + + assert "[]" = json_response(conn, 200) + end + end + describe "POST /api/favorites/create/:id" do setup [:valid_user] From 1299bccc7de1562775de23245bf9922c16329e9a Mon Sep 17 00:00:00 2001 From: Vivian Lim Date: Sat, 23 Jun 2018 23:20:30 -0700 Subject: [PATCH 3/4] return unquoted empty array from /api/qvitter/mutes.json --- lib/pleroma/web/router.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++++ test/web/twitter_api/twitter_api_controller_test.exs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index b65850aaa..4ebb2c368 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -269,7 +269,7 @@ def user_fetcher(username) do get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array) get("/mutes/users/ids", TwitterAPI.Controller, :empty_array) - get("/qvitter/mutes", TwitterAPI.Controller, :empty_array) + get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array) get("/externalprofile/show", TwitterAPI.Controller, :external_profile) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ff5921807..8f5b3c786 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -404,6 +404,10 @@ def empty_array(conn, _params) do json(conn, Jason.encode!([])) end + def raw_empty_array(conn, _params) do + json(conn, []) + end + def update_profile(%{assigns: %{user: user}} = conn, params) do params = if bio = params["description"] do diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index edc8cbff8..5fcd23d90 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -506,7 +506,7 @@ test "unimplemented mutes with credentials", %{conn: conn, user: current_user} d |> get("/api/qvitter/mutes.json") current_user = Repo.get(User, current_user.id) - assert "[]" = json_response(conn, 200) + assert [] = json_response(conn, 200) end end From 6160a1b3c07c49cf81e2353cc25a123e75843581 Mon Sep 17 00:00:00 2001 From: Vivian Lim Date: Sun, 24 Jun 2018 15:24:41 -0700 Subject: [PATCH 4/4] mix format --- lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 2 +- test/web/twitter_api/twitter_api_controller_test.exs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 0a047013a..7fecb8a4f 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do @accept Keyword.get(@mrf_policy, :accept) defp check_accept(actor_info, object) do - if length(@accept) > 0 and not actor_info.host in @accept do + if length(@accept) > 0 and not (actor_info.host in @accept) do {:reject, nil} else {:ok, object} diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 5fcd23d90..3a035e298 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -504,6 +504,7 @@ test "unimplemented mutes with credentials", %{conn: conn, user: current_user} d conn |> with_credentials(current_user.nickname, "test") |> get("/api/qvitter/mutes.json") + current_user = Repo.get(User, current_user.id) assert [] = json_response(conn, 200)