diff options
Diffstat (limited to 'test/web')
-rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 7 | ||||
-rw-r--r-- | test/web/federator_test.exs | 7 | ||||
-rw-r--r-- | test/web/node_info_test.exs | 32 | ||||
-rw-r--r-- | test/web/plugs/federating_plug_test.exs | 33 | ||||
-rw-r--r-- | test/web/twitter_api/twitter_api_controller_test.exs | 50 |
5 files changed, 121 insertions, 8 deletions
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 5b46bbe76..1c24b348c 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -4,12 +4,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do alias Pleroma.Web.ActivityPub.{UserView, ObjectView} alias Pleroma.{Repo, User} alias Pleroma.Activity - alias Pleroma.Config describe "/relay" do test "with the relay active, it returns the relay user", %{conn: conn} do - Config.put([:instance, :allow_relay], true) - res = conn |> get(activity_pub_path(conn, :relay)) @@ -19,12 +16,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end test "with the relay disabled, it returns 404", %{conn: conn} do - Config.put([:instance, :allow_relay], false) + Pleroma.Config.put([:instance, :allow_relay], false) res = conn |> get(activity_pub_path(conn, :relay)) |> json_response(404) + + Pleroma.Config.put([:instance, :allow_relay], true) end end diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 966702935..c709d1181 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -1,7 +1,6 @@ defmodule Pleroma.Web.FederatorTest do alias Pleroma.Web.Federator alias Pleroma.Web.CommonAPI - alias Pleroma.Config use Pleroma.DataCase import Pleroma.Factory import Mock @@ -40,8 +39,6 @@ defmodule Pleroma.Web.FederatorTest do activity: activity, relay_mock: relay_mock } do - Config.put([:instance, :allow_relay], true) - with_mocks([relay_mock]) do Federator.handle(:publish, activity) end @@ -53,13 +50,15 @@ defmodule Pleroma.Web.FederatorTest do activity: activity, relay_mock: relay_mock } do - Config.put([:instance, :allow_relay], false) + Pleroma.Config.put([:instance, :allow_relay], false) with_mocks([relay_mock]) do Federator.handle(:publish, activity) end refute_received :relay_publish + + Pleroma.Config.put([:instance, :allow_relay], true) end end end diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index d48f40e47..a6376453c 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -14,4 +14,36 @@ defmodule Pleroma.Web.NodeInfoTest do assert user.ap_id in result["metadata"]["staffAccounts"] end + + test "returns 404 when federation is disabled" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/.well-known/nodeinfo") + |> json_response(404) + + conn + |> get("/nodeinfo/2.0.json") + |> json_response(404) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 when federation is enabled" do + conn + |> get("/.well-known/nodeinfo") + |> json_response(200) + + conn + |> get("/nodeinfo/2.0.json") + |> json_response(200) + end end diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs new file mode 100644 index 000000000..1455a1c46 --- /dev/null +++ b/test/web/plugs/federating_plug_test.exs @@ -0,0 +1,33 @@ +defmodule Pleroma.Web.FederatingPlugTest do + use Pleroma.Web.ConnCase + + test "returns and halt the conn when federating is disabled" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, false) + + Application.put_env(:pleroma, :instance, instance) + + conn = + build_conn() + |> Pleroma.Web.FederatingPlug.call(%{}) + + assert conn.status == 404 + assert conn.halted + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "does nothing when federating is enabled" do + conn = + build_conn() + |> Pleroma.Web.FederatingPlug.call(%{}) + + refute conn.status + refute conn.halted + end +end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 87bcdaf71..b64f416e3 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -100,6 +100,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert length(response) == 10 end + + test "returns 403 to unauthenticated request when the instance is not public" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/api/statuses/public_timeline.json") + |> json_response(403) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 to unauthenticated request when the instance is public" do + conn + |> get("/api/statuses/public_timeline.json") + |> json_response(200) + end + end + + describe "GET /statuses/public_and_external_timeline.json" do + test "returns 403 to unauthenticated request when the instance is not public" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/api/statuses/public_and_external_timeline.json") + |> json_response(403) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 to unauthenticated request when the instance is public" do + conn + |> get("/api/statuses/public_and_external_timeline.json") + |> json_response(200) + end end describe "GET /statuses/show/:id.json" do |