diff options
Diffstat (limited to 'test/web')
-rw-r--r-- | test/web/controller/frontend/admin_controller_test.exs | 12 | ||||
-rw-r--r-- | test/web/controller/frontend/headless_controller_test.exs | 16 | ||||
-rw-r--r-- | test/web/controller/frontend/kenoma_controller_test.exs | 16 | ||||
-rw-r--r-- | test/web/controller/frontend/mastodon_controller_test.exs | 85 | ||||
-rw-r--r-- | test/web/controller/frontend/pleroma_controller_test.exs | 24 | ||||
-rw-r--r-- | test/web/controller/frontend/static_controller_test.exs (renamed from test/web/static_fe/static_fe_controller_test.exs) | 41 | ||||
-rw-r--r-- | test/web/fallback_test.exs | 6 | ||||
-rw-r--r-- | test/web/feed/user_controller_test.exs | 14 | ||||
-rw-r--r-- | test/web/ostatus/ostatus_controller_test.exs | 82 |
9 files changed, 225 insertions, 71 deletions
diff --git a/test/web/controller/frontend/admin_controller_test.exs b/test/web/controller/frontend/admin_controller_test.exs new file mode 100644 index 000000000..8375cefdc --- /dev/null +++ b/test/web/controller/frontend/admin_controller_test.exs @@ -0,0 +1,12 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Frontend.AdminControllerTest do + use Pleroma.Web.ConnCase + + test "renders index.html from admin fe", %{conn: conn} do + conn = get(conn, frontend_admin_path(conn, :index, [])) + assert html_response(conn, 200) =~ "test Admin Develop FE" + end +end diff --git a/test/web/controller/frontend/headless_controller_test.exs b/test/web/controller/frontend/headless_controller_test.exs new file mode 100644 index 000000000..db9b8ef27 --- /dev/null +++ b/test/web/controller/frontend/headless_controller_test.exs @@ -0,0 +1,16 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Frontend.HeadlessControllerTest do + use Pleroma.Web.ConnCase + + setup do: clear_config([:frontends, :primary]) + + test "Returns 404", %{conn: conn} do + Pleroma.Config.put([:frontends, :primary], %{"name" => "none", "ref" => ""}) + + conn = get(conn, frontend_path(conn, :index_with_preload, [])) + assert text_response(conn, 404) == "" + end +end diff --git a/test/web/controller/frontend/kenoma_controller_test.exs b/test/web/controller/frontend/kenoma_controller_test.exs new file mode 100644 index 000000000..342d44fc5 --- /dev/null +++ b/test/web/controller/frontend/kenoma_controller_test.exs @@ -0,0 +1,16 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Frontend.KenomaControllerTest do + use Pleroma.Web.ConnCase + + setup do: clear_config([:frontends, :primary]) + + test "renders index.html from kenoma fe", %{conn: conn} do + Pleroma.Config.put([:frontends, :primary], %{"name" => "kenoma", "ref" => "develop"}) + + conn = get(conn, frontend_path(conn, :index_with_preload, [])) + assert html_response(conn, 200) =~ "test Kenoma Develop FE" + end +end diff --git a/test/web/controller/frontend/mastodon_controller_test.exs b/test/web/controller/frontend/mastodon_controller_test.exs new file mode 100644 index 000000000..c45554159 --- /dev/null +++ b/test/web/controller/frontend/mastodon_controller_test.exs @@ -0,0 +1,85 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Frontend.MastodonControllerTest do + use Pleroma.Web.ConnCase + + alias Pleroma.Config + alias Pleroma.User + + import Pleroma.Factory + + setup do: clear_config([:instance, :public]) + + test "put settings", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> assign(:user, user) + |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"])) + |> put(frontend_mastodon_path(conn, :put_settings), %{"data" => %{"programming" => "socks"}}) + + assert _result = json_response(conn, 200) + + user = User.get_cached_by_ap_id(user.ap_id) + assert user.mastofe_settings == %{"programming" => "socks"} + end + + describe "index/2 redirections" do + setup %{conn: conn} do + session_opts = [ + store: :cookie, + key: "_test", + signing_salt: "cooldude" + ] + + conn = + conn + |> Plug.Session.call(Plug.Session.init(session_opts)) + |> fetch_session() + + test_path = frontend_mastodon_path(conn, :index, ["statuses", "test"]) + %{conn: conn, path: test_path} + end + + test "redirects not logged-in users to the login page", %{conn: conn, path: path} do + conn = get(conn, path) + + assert conn.status == 302 + assert redirected_to(conn) == auth_path(conn, :login) + end + + test "redirects not logged-in users to the login page on private instances", %{ + conn: conn, + path: path + } do + Config.put([:instance, :public], false) + + conn = get(conn, path) + + assert conn.status == 302 + assert redirected_to(conn) == auth_path(conn, :login) + end + + test "does not redirect logged in users to the login page", %{conn: conn, path: path} do + token = insert(:oauth_token, scopes: ["read"]) + + conn = + conn + |> assign(:user, token.user) + |> assign(:token, token) + |> get(path) + + assert conn.status == 200 + end + + test "saves referer path to session", %{conn: conn, path: path} do + conn = get(conn, path) + return_to = Plug.Conn.get_session(conn, :return_to) + + assert return_to == path + end + end +end diff --git a/test/web/controller/frontend/pleroma_controller_test.exs b/test/web/controller/frontend/pleroma_controller_test.exs new file mode 100644 index 000000000..2210731a2 --- /dev/null +++ b/test/web/controller/frontend/pleroma_controller_test.exs @@ -0,0 +1,24 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Frontend.PleromaControllerTest do + use Pleroma.Web.ConnCase + + import Pleroma.Factory + + test "renders index.html from pleroma fe", %{conn: conn} do + conn = get(conn, frontend_path(conn, :index_with_preload, [])) + assert html_response(conn, 200) =~ "test Pleroma Develop FE" + end + + test "index_with_meta", %{conn: conn} do + user = insert(:user) + + conn = get(conn, frontend_path(conn, :index_with_meta_and_user, "nonexistinguser")) + assert html_response(conn, 200) =~ "<!--server-generated-meta-->" + + conn = get(conn, frontend_path(conn, :index_with_meta_and_user, user.nickname)) + refute html_response(conn, 200) =~ "<!--server-generated-meta-->" + end +end diff --git a/test/web/static_fe/static_fe_controller_test.exs b/test/web/controller/frontend/static_controller_test.exs index 1598bf675..ac447341b 100644 --- a/test/web/static_fe/static_fe_controller_test.exs +++ b/test/web/controller/frontend/static_controller_test.exs @@ -1,4 +1,8 @@ -defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Frontend.StaticControllerTest do use Pleroma.Web.ConnCase alias Pleroma.Activity @@ -8,7 +12,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do import Pleroma.Factory - setup_all do: clear_config([:static_fe, :enabled], true) + setup_all do: clear_config([:frontends, :static], true) setup do: clear_config([:instance, :federating], true) setup %{conn: conn} do @@ -20,13 +24,13 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do describe "user profile html" do test "just the profile as HTML", %{conn: conn, user: user} do - conn = get(conn, "/users/#{user.nickname}") + conn = get(conn, user_feed_path(conn, :feed_redirect, user.nickname)) assert html_response(conn, 200) =~ user.nickname end test "404 when user not found", %{conn: conn} do - conn = get(conn, "/users/limpopo") + conn = get(conn, user_feed_path(conn, :feed_redirect, "nonexistinguser")) assert html_response(conn, 404) =~ "not found" end @@ -35,7 +39,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do CommonAPI.post(user, %{status: "public"}) CommonAPI.post(user, %{status: "private", visibility: "private"}) - conn = get(conn, "/users/#{user.nickname}") + conn = get(conn, user_feed_path(conn, :feed_redirect, user.nickname)) html = html_response(conn, 200) @@ -44,9 +48,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do end test "pagination", %{conn: conn, user: user} do - Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end) - - conn = get(conn, "/users/#{user.nickname}") + Enum.each(1..30, &CommonAPI.post(user, %{status: "test#{&1}"})) + conn = get(conn, user_feed_path(conn, :feed_redirect, user.nickname)) html = html_response(conn, 200) @@ -60,7 +63,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end) {:ok, a11} = Enum.at(activities, 11) - conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}") + conn = get(conn, user_feed_path(conn, :feed_redirect, user.nickname, max_id: a11.id)) html = html_response(conn, 200) @@ -71,7 +74,11 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do end test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do - ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user) + ensure_federating_or_authenticated( + conn, + user_feed_path(conn, :feed_redirect, user.nickname), + user + ) end end @@ -79,7 +86,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do test "single notice page", %{conn: conn, user: user} do {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"}) - conn = get(conn, "/notice/#{activity.id}") + conn = get(conn, o_status_path(conn, :notice, activity.id)) html = html_response(conn, 200) assert html =~ "<header>" @@ -108,7 +115,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do conn = conn |> put_req_header("accept", "text/html") - |> get("/notice/#{activity.id}") + |> get(o_status_path(conn, :notice, activity.id)) html = html_response(conn, 200) assert html =~ ~s[<script>alert('xss')</script>] @@ -122,7 +129,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do in_reply_to_status_id: activity.id }) - conn = get(conn, "/notice/#{activity.id}") + conn = get(conn, o_status_path(conn, :notice, activity.id)) html = html_response(conn, 200) assert html =~ "the final frontier" @@ -148,7 +155,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do end test "404 when notice not found", %{conn: conn} do - conn = get(conn, "/notice/88c9c317") + conn = get(conn, o_status_path(conn, :notice, "nonexistingnotice")) assert html_response(conn, 404) =~ "not found" end @@ -156,7 +163,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do test "404 for private status", %{conn: conn, user: user} do {:ok, activity} = CommonAPI.post(user, %{status: "don't show me!", visibility: "private"}) - conn = get(conn, "/notice/#{activity.id}") + conn = get(conn, o_status_path(conn, :notice, activity.id)) assert html_response(conn, 404) =~ "not found" end @@ -178,7 +185,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do assert {:ok, activity} = Transmogrifier.handle_incoming(message) - conn = get(conn, "/notice/#{activity.id}") + conn = get(conn, o_status_path(conn, :notice, activity.id)) assert html_response(conn, 302) =~ "redirected" end @@ -186,7 +193,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"}) - ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user) + ensure_federating_or_authenticated(conn, o_status_path(conn, :notice, activity.id), user) end end end diff --git a/test/web/fallback_test.exs b/test/web/fallback_test.exs index a65865860..6f9f4dc6c 100644 --- a/test/web/fallback_test.exs +++ b/test/web/fallback_test.exs @@ -26,7 +26,7 @@ defmodule Pleroma.Web.FallbackTest do user_missing = get(conn, "/foo") user_present = get(conn, "/#{user.nickname}") - assert(html_response(user_missing, 200) =~ "<!--server-generated-meta-->") + assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->" refute html_response(user_present, 200) =~ "<!--server-generated-meta-->" assert html_response(user_present, 200) =~ "initial-results" end @@ -64,10 +64,6 @@ defmodule Pleroma.Web.FallbackTest do |> json_response(404) == %{"error" => "Not implemented"} end - test "GET /pleroma/admin -> /pleroma/admin/", %{conn: conn} do - assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/" - end - test "OPTIONS /*path", %{conn: conn} do assert conn |> options("/foo") diff --git a/test/web/feed/user_controller_test.exs b/test/web/feed/user_controller_test.exs index fa2ed1ea5..ff74487c9 100644 --- a/test/web/feed/user_controller_test.exs +++ b/test/web/feed/user_controller_test.exs @@ -191,14 +191,16 @@ defmodule Pleroma.Web.Feed.UserControllerTest do response = conn - |> get("/users/#{user.nickname}") + |> get(user_feed_path(conn, :feed_redirect, user.nickname)) |> response(200) - assert response == - Fallback.RedirectController.redirector_with_meta( - conn, - %{user: user} - ).resp_body + expected = + conn + |> Map.put(:params, %{user: user}) + |> Pleroma.Web.FrontendController.call(:index_with_meta) + |> Map.get(:resp_body) + + assert response == expected end test "with html format, it returns error when user is not found", %{conn: conn} do diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index ee498f4b5..f492c8ef4 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -28,14 +28,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do conn = put_req_header(conn, "accept", "text/html") {:ok, object} = - %{ + Object.create(%{ "type" => "Note", "content" => "hey", - "id" => Endpoint.url() <> "/users/raymoo/statuses/999999999", - "actor" => Endpoint.url() <> "/users/raymoo", + "id" => o_status_url(Endpoint, :object, "raymoo", 999_999_999), + "actor" => user_feed_url(Endpoint, :feed_redirect, "raymoo"), "to" => [Pleroma.Constants.as_public()] - } - |> Object.create() + }) {:ok, activity, _} = %{ @@ -51,16 +50,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do end test "redirects to /notice/:id for html format", %{conn: conn, activity: activity} do - conn = get(conn, "/users/raymoo/statuses/999999999") - assert redirected_to(conn) == "/notice/#{activity.id}" + conn = get(conn, o_status_path(conn, :object, "raymoo", 999_999_999)) + assert redirected_to(conn) == o_status_path(conn, :notice, activity.id) end test "redirects to /notice/:id for html format for activity", %{ conn: conn, activity: activity } do - conn = get(conn, "/users/raymoo/statuses/999999999/activity") - assert redirected_to(conn) == "/notice/#{activity.id}" + conn = get(conn, o_status_path(conn, :activity, "raymoo", 999_999_999)) + assert redirected_to(conn) == o_status_path(conn, :notice, activity.id) end end @@ -75,10 +74,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do note_activity = insert(:note_activity) object = Object.normalize(note_activity) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"])) - url = "/objects/#{uuid}" - - conn = get(conn, url) - assert redirected_to(conn) == "/notice/#{note_activity.id}" + conn = get(conn, o_status_path(conn, :object, uuid)) + assert redirected_to(conn) == o_status_path(conn, :notice, note_activity.id) end test "404s on private objects", %{conn: conn} do @@ -87,13 +84,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"])) conn - |> get("/objects/#{uuid}") + |> get(o_status_path(conn, :object, uuid)) |> response(404) end test "404s on non-existing objects", %{conn: conn} do conn - |> get("/objects/123") + |> get(o_status_path(conn, :object, 123)) |> response(404) end end @@ -109,8 +106,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do note_activity = insert(:note_activity) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) - conn = get(conn, "/activities/#{uuid}") - assert redirected_to(conn) == "/notice/#{note_activity.id}" + conn = get(conn, o_status_path(conn, :activity, uuid)) + assert redirected_to(conn) == o_status_path(conn, :notice, note_activity.id) end test "404s on private activities", %{conn: conn} do @@ -118,13 +115,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) conn - |> get("/activities/#{uuid}") + |> get(o_status_path(conn, :activity, uuid)) |> response(404) end test "404s on nonexistent activities", %{conn: conn} do conn - |> get("/activities/123") + |> get(o_status_path(conn, :activity, 123)) |> response(404) end end @@ -139,7 +136,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do redirect_url = conn |> put_req_header("accept", "application/activity+json") - |> get("/notice/#{note_activity.id}") + |> get(o_status_path(conn, :notice, note_activity.id)) |> redirected_to() assert redirect_url == expected_redirect_url @@ -150,7 +147,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do conn |> put_req_header("accept", "application/activity+json") - |> get("/notice/#{note_activity.id}") + |> get(o_status_path(conn, :notice, note_activity.id)) |> response(404) end @@ -160,9 +157,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do User.invalidate_cache(user) Pleroma.Repo.delete(user) - conn = - conn - |> get("/notice/#{note_activity.id}") + conn = get(conn, o_status_path(conn, :notice, note_activity.id)) assert response(conn, 500) == ~S({"error":"Something went wrong"}) end @@ -173,11 +168,11 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do resp = conn |> put_req_header("accept", "text/html") - |> get("/notice/#{note_activity.id}") + |> get(o_status_path(conn, :notice, note_activity.id)) |> response(200) assert resp =~ - "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">" + "<meta content=\"#{o_status_url(Endpoint, :notice, note_activity.id)}\" property=\"og:url\">" user = insert(:user) @@ -188,7 +183,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do resp = conn |> put_req_header("accept", "text/html") - |> get("/notice/#{like_activity.id}") + |> get(o_status_path(conn, :notice, like_activity.id)) |> response(200) assert resp =~ "<!--server-generated-meta-->" @@ -196,21 +191,14 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do test "404s a private notice", %{conn: conn} do note_activity = insert(:direct_note_activity) - url = "/notice/#{note_activity.id}" - conn = - conn - |> get(url) + conn = get(conn, o_status_path(conn, :notice, note_activity.id)) assert response(conn, 404) end test "404s a non-existing notice", %{conn: conn} do - url = "/notice/123" - - conn = - conn - |> get(url) + conn = get(conn, o_status_path(conn, :notice, 123)) assert response(conn, 404) end @@ -223,7 +211,11 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do conn = put_req_header(conn, "accept", "text/html") - ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user) + ensure_federating_or_authenticated( + conn, + o_status_path(conn, :notice, note_activity.id), + user + ) end end @@ -254,7 +246,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do end test "renders embed player", %{conn: conn, note_activity: note_activity} do - conn = get(conn, "/notice/#{note_activity.id}/embed_player") + conn = get(conn, o_status_path(conn, :notice_player, note_activity.id)) assert Plug.Conn.get_resp_header(conn, "x-frame-options") == ["ALLOW"] @@ -273,7 +265,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do note_activity = insert(:note_activity, data_attrs: %{"type" => "Like"}) assert conn - |> get("/notice/#{note_activity.id}/embed_player") + |> get(o_status_path(conn, :notice_player, note_activity.id)) |> response(404) end @@ -281,7 +273,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do note_activity = insert(:note_activity, data_attrs: %{"directMessage" => true}) assert conn - |> get("/notice/#{note_activity.id}/embed_player") + |> get(o_status_path(conn, :notice_player, note_activity.id)) |> response(404) end @@ -295,7 +287,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> Pleroma.Repo.update() assert conn - |> get("/notice/#{note_activity.id}/embed_player") + |> get(o_status_path(conn, :notice_player, note_activity.id)) |> response(404) end @@ -321,7 +313,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> Pleroma.Repo.update() conn - |> get("/notice/#{note_activity.id}/embed_player") + |> get(o_status_path(conn, :notice_player, note_activity.id)) |> response(404) end @@ -332,7 +324,11 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do user = insert(:user) conn = put_req_header(conn, "accept", "text/html") - ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user) + ensure_federating_or_authenticated( + conn, + o_status_path(conn, :notice_player, note_activity.id), + user + ) end end end |