[#1560] Enforced authentication for non-federating instances in StaticFEController.

This commit is contained in:
Ivan Tashkinov 2020-03-11 14:05:56 +03:00
commit 5b696a8ac1
3 changed files with 33 additions and 10 deletions

View file

@ -26,6 +26,8 @@ defmodule Pleroma.Web.ConnCase do
use Pleroma.Tests.Helpers
import Pleroma.Web.Router.Helpers
alias Pleroma.Config
# The default endpoint for testing
@endpoint Pleroma.Web.Endpoint
@ -50,7 +52,10 @@ defmodule Pleroma.Web.ConnCase do
end
defp ensure_federating_or_authenticated(conn, url, user) do
Pleroma.Config.put([:instance, :federating], false)
initial_setting = Config.get([:instance, :federating])
on_exit(fn -> Config.put([:instance, :federating], initial_setting) end)
Config.put([:instance, :federating], false)
conn
|> get(url)
@ -61,7 +66,7 @@ defmodule Pleroma.Web.ConnCase do
|> get(url)
|> response(200)
Pleroma.Config.put([:instance, :federating], true)
Config.put([:instance, :federating], true)
conn
|> get(url)

View file

@ -12,6 +12,10 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
Config.put([:static_fe, :enabled], true)
end
clear_config([:instance, :federating]) do
Config.put([:instance, :federating], true)
end
setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
user = insert(:user)
@ -70,6 +74,10 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
refute html =~ ">test20<"
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)
end
end
describe "notice html" do
@ -153,5 +161,11 @@ 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
{:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
end
end
end