X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsupport%2Fconn_case.ex;h=06487420158ebed5412c15aa05800f4823207e6e;hb=f7e623c11c4b6f4f323a4317e9489092be73f9cd;hp=95bc2492a77c9a42a6686ccc19055d84010c9c79;hpb=7973cbdb9fa9120306cb5a265a477eeccd315ee6;p=akkoma
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index 95bc2492a..064874201 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ConnCase do
@@ -26,18 +26,20 @@ 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
# Sets up OAuth access with specified scopes
- defp oauth_access(scopes, opts \\ %{}) do
+ defp oauth_access(scopes, opts \\ []) do
user =
- Map.get_lazy(opts, :user, fn ->
+ Keyword.get_lazy(opts, :user, fn ->
Pleroma.Factory.insert(:user)
end)
token =
- Map.get_lazy(opts, :oauth_token, fn ->
+ Keyword.get_lazy(opts, :oauth_token, fn ->
Pleroma.Factory.insert(:oauth_token, user: user, scopes: scopes)
end)
@@ -48,6 +50,28 @@ defmodule Pleroma.Web.ConnCase do
%{user: user, token: token, conn: conn}
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