diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/pleroma/web/activity_pub/activity_pub_controller_test.exs | 48 | ||||
| -rw-r--r-- | test/pleroma/web/feed/tag_controller_test.exs | 13 | ||||
| -rw-r--r-- | test/pleroma/web/feed/user_controller_test.exs | 12 | ||||
| -rw-r--r-- | test/pleroma/web/o_status/o_status_controller_test.exs | 24 | ||||
| -rw-r--r-- | test/pleroma/web/static_fe/static_fe_controller_test.exs | 47 | ||||
| -rw-r--r-- | test/support/conn_case.ex | 22 | 
6 files changed, 71 insertions, 95 deletions
diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index b11e2f961..b696a24f4 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -156,21 +156,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert response == "Not found"      end - -    test "it requires authentication if instance is NOT federating", %{ -      conn: conn -    } do -      user = insert(:user) - -      conn = -        put_req_header( -          conn, -          "accept", -          "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" -        ) - -      ensure_federating_or_authenticated(conn, "/users/#{user.nickname}.json", user) -    end    end    describe "mastodon compatibility routes" do @@ -338,18 +323,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert "Not found" == json_response(conn2, :not_found)      end - -    test "it requires authentication if instance is NOT federating", %{ -      conn: conn -    } do -      user = insert(:user) -      note = insert(:note) -      uuid = String.split(note.data["id"], "/") |> List.last() - -      conn = put_req_header(conn, "accept", "application/activity+json") - -      ensure_federating_or_authenticated(conn, "/objects/#{uuid}", user) -    end    end    describe "/activities/:uuid" do @@ -421,18 +394,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert "Not found" == json_response(conn2, :not_found)      end - -    test "it requires authentication if instance is NOT federating", %{ -      conn: conn -    } do -      user = insert(:user) -      activity = insert(:note_activity) -      uuid = String.split(activity.data["id"], "/") |> List.last() - -      conn = put_req_header(conn, "accept", "application/activity+json") - -      ensure_federating_or_authenticated(conn, "/activities/#{uuid}", user) -    end    end    describe "/inbox" do @@ -893,15 +854,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert response(conn, 200) =~ announce_activity.data["object"]      end - -    test "it requires authentication if instance is NOT federating", %{ -      conn: conn -    } do -      user = insert(:user) -      conn = put_req_header(conn, "accept", "application/activity+json") - -      ensure_federating_or_authenticated(conn, "/users/#{user.nickname}/outbox", user) -    end    end    describe "POST /users/:nickname/outbox (C2S)" do diff --git a/test/pleroma/web/feed/tag_controller_test.exs b/test/pleroma/web/feed/tag_controller_test.exs index 868e40965..e4084b0e5 100644 --- a/test/pleroma/web/feed/tag_controller_test.exs +++ b/test/pleroma/web/feed/tag_controller_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do    import Pleroma.Factory    import SweetXml +  alias Pleroma.Config    alias Pleroma.Object    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.Feed.FeedView @@ -15,7 +16,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do    setup do: clear_config([:feed])    test "gets a feed (ATOM)", %{conn: conn} do -    Pleroma.Config.put( +    Config.put(        [:feed, :post_title],        %{max_length: 25, omission: "..."}      ) @@ -82,7 +83,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do    end    test "gets a feed (RSS)", %{conn: conn} do -    Pleroma.Config.put( +    Config.put(        [:feed, :post_title],        %{max_length: 25, omission: "..."}      ) @@ -157,7 +158,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do      response =        conn        |> put_req_header("accept", "application/rss+xml") -      |> get(tag_feed_path(conn, :feed, "pleromaart")) +      |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))        |> response(200)      xml = parse(response) @@ -183,14 +184,12 @@ defmodule Pleroma.Web.Feed.TagControllerTest do    end    describe "private instance" do -    setup do: clear_config([:instance, :public]) +    setup do: clear_config([:instance, :public], false)      test "returns 404 for tags feed", %{conn: conn} do -      Config.put([:instance, :public], false) -        conn        |> put_req_header("accept", "application/rss+xml") -      |> get(tag_feed_path(conn, :feed, "pleromaart")) +      |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))        |> response(404)      end    end diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs index a5dc0894b..eabfe3a63 100644 --- a/test/pleroma/web/feed/user_controller_test.exs +++ b/test/pleroma/web/feed/user_controller_test.exs @@ -13,7 +13,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do    alias Pleroma.User    alias Pleroma.Web.CommonAPI -  setup do: clear_config([:instance, :federating], true) +  setup do: clear_config([:static_fe, :enabled], false)    describe "feed" do      setup do: clear_config([:feed]) @@ -192,6 +192,16 @@ defmodule Pleroma.Web.Feed.UserControllerTest do               |> get(user_feed_path(conn, :feed, user.nickname))               |> response(404)      end + +    test "does not require authentication on non-federating instances", %{conn: conn} do +      clear_config([:instance, :federating], false) +      user = insert(:user) + +      conn +      |> put_req_header("accept", "application/rss+xml") +      |> get("/users/#{user.nickname}/feed.rss") +      |> response(200) +    end    end    # Note: see ActivityPubControllerTest for JSON format tests diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index ee498f4b5..65b2c22db 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do    import Pleroma.Factory -  alias Pleroma.Config    alias Pleroma.Object    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub @@ -21,7 +20,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do      :ok    end -  setup do: clear_config([:instance, :federating], true) +  setup do: clear_config([:static_fe, :enabled], false)    describe "Mastodon compatibility routes" do      setup %{conn: conn} do @@ -215,15 +214,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do        assert response(conn, 404)      end -    test "it requires authentication if instance is NOT federating", %{ +    test "does not require authentication on non-federating instances", %{        conn: conn      } do -      user = insert(:user) +      clear_config([:instance, :federating], false)        note_activity = insert(:note_activity) -      conn = put_req_header(conn, "accept", "text/html") - -      ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user) +      conn +      |> put_req_header("accept", "text/html") +      |> get("/notice/#{note_activity.id}") +      |> response(200)      end    end @@ -325,14 +325,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do        |> response(404)      end -    test "it requires authentication if instance is NOT federating", %{ +    test "does not require authentication on non-federating instances", %{        conn: conn,        note_activity: note_activity      } do -      user = insert(:user) -      conn = put_req_header(conn, "accept", "text/html") +      clear_config([:instance, :federating], false) -      ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user) +      conn +      |> put_req_header("accept", "text/html") +      |> get("/notice/#{note_activity.id}/embed_player") +      |> response(200)      end    end  end diff --git a/test/pleroma/web/static_fe/static_fe_controller_test.exs b/test/pleroma/web/static_fe/static_fe_controller_test.exs index f819a1e52..19506f1d8 100644 --- a/test/pleroma/web/static_fe/static_fe_controller_test.exs +++ b/test/pleroma/web/static_fe/static_fe_controller_test.exs @@ -6,14 +6,12 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do    use Pleroma.Web.ConnCase    alias Pleroma.Activity -  alias Pleroma.Config    alias Pleroma.Web.ActivityPub.Transmogrifier    alias Pleroma.Web.CommonAPI    import Pleroma.Factory    setup_all do: clear_config([:static_fe, :enabled], true) -  setup do: clear_config([:instance, :federating], true)    setup %{conn: conn} do      conn = put_req_header(conn, "accept", "text/html") @@ -74,8 +72,27 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do        refute html =~ ">test29<"      end -    test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do -      ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user) +    test "does not require authentication on non-federating instances", %{ +      conn: conn, +      user: user +    } do +      clear_config([:instance, :federating], false) + +      conn = get(conn, "/users/#{user.nickname}") + +      assert html_response(conn, 200) =~ user.nickname +    end + +    test "returns 404 for local user with `restrict_unauthenticated/profiles/local` setting", %{ +      conn: conn +    } do +      clear_config([:restrict_unauthenticated, :profiles, :local], true) + +      local_user = insert(:user, local: true) + +      conn +      |> get("/users/#{local_user.nickname}") +      |> html_response(404)      end    end @@ -187,10 +204,28 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do        assert html_response(conn, 302) =~ "redirected"      end -    test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do +    test "does not require authentication on non-federating instances", %{ +      conn: conn, +      user: user +    } do +      clear_config([:instance, :federating], false) + +      {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"}) + +      conn = get(conn, "/notice/#{activity.id}") + +      assert html_response(conn, 200) =~ "testing a thing!" +    end + +    test "returns 404 for local public activity with `restrict_unauthenticated/activities/local` setting", +         %{conn: conn, user: user} do +      clear_config([:restrict_unauthenticated, :activities, :local], true) +        {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"}) -      ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user) +      conn +      |> get("/notice/#{activity.id}") +      |> html_response(404)      end    end  end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 9316a82e4..47cb65a80 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -112,28 +112,6 @@ defmodule Pleroma.Web.ConnCase do        defp json_response_and_validate_schema(conn, _status) do          flunk("Response schema not found for #{conn.method} #{conn.request_path} #{conn.status}")        end - -      defp ensure_federating_or_authenticated(conn, url, user) do -        initial_setting = Config.get([:instance, :federating]) -        on_exit(fn -> Config.put([:instance, :federating], initial_setting) end) - -        Config.put([:instance, :federating], false) - -        conn -        |> get(url) -        |> response(403) - -        conn -        |> assign(:user, user) -        |> get(url) -        |> response(200) - -        Config.put([:instance, :federating], true) - -        conn -        |> get(url) -        |> response(200) -      end      end    end  | 
