aboutsummaryrefslogtreecommitdiff
path: root/test/web
diff options
context:
space:
mode:
Diffstat (limited to 'test/web')
-rw-r--r--test/web/controller/frontend/admin_controller_test.exs12
-rw-r--r--test/web/controller/frontend/headless_controller_test.exs16
-rw-r--r--test/web/controller/frontend/kenoma_controller_test.exs16
-rw-r--r--test/web/controller/frontend/mastodon_controller_test.exs85
-rw-r--r--test/web/controller/frontend/pleroma_controller_test.exs24
-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.exs4
-rw-r--r--test/web/feed/user_controller_test.exs12
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs2
9 files changed, 185 insertions, 27 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..96061c15a
--- /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, []))
+ 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..90271c384
--- /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, []))
+ 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..8dbc18354
--- /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.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..030ecf97f
--- /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, []))
+ 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, "nonexistinguser"))
+ assert html_response(conn, 200) =~ "<!--server-generated-meta-->"
+
+ conn = get(conn, frontend_path(conn, :index_with_meta, 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 430683ea0..71da358a3 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>"
@@ -94,7 +101,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[&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;]
@@ -108,7 +115,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"
@@ -134,7 +141,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
@@ -143,7 +150,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest 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
@@ -165,7 +172,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
@@ -173,7 +180,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 3919ef93a..6331f8087 100644
--- a/test/web/fallback_test.exs
+++ b/test/web/fallback_test.exs
@@ -30,10 +30,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 "GET /*path", %{conn: conn} do
assert conn
|> get("/foo")
diff --git a/test/web/feed/user_controller_test.exs b/test/web/feed/user_controller_test.exs
index 05ad427c2..e66234f25 100644
--- a/test/web/feed/user_controller_test.exs
+++ b/test/web/feed/user_controller_test.exs
@@ -170,11 +170,13 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> get("/users/#{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 bb349cb19..ff535df75 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -94,7 +94,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