diff options
| author | rinpatch <rinpatch@sdf.org> | 2019-05-18 13:37:38 +0300 |
|---|---|---|
| committer | rinpatch <rinpatch@sdf.org> | 2019-05-18 13:37:38 +0300 |
| commit | 5ece901af3e887664653c79c5e61618cc5cf0ecf (patch) | |
| tree | 93fc7c3bdb70348d5ef91fa9f7db3293b17f9854 /test/plugs/ensure_public_or_authenticated_plug_test.exs | |
| parent | fd920c897339b9cedea042dd6698d14380cedae7 (diff) | |
| parent | 8e9a764dfcde315afd055c8e63543bfca24cc41b (diff) | |
| download | pleroma-5ece901af3e887664653c79c5e61618cc5cf0ecf.tar.gz pleroma-5ece901af3e887664653c79c5e61618cc5cf0ecf.zip | |
Resolve merge conflicts and remove IO.inspects
Diffstat (limited to 'test/plugs/ensure_public_or_authenticated_plug_test.exs')
| -rw-r--r-- | test/plugs/ensure_public_or_authenticated_plug_test.exs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/plugs/ensure_public_or_authenticated_plug_test.exs b/test/plugs/ensure_public_or_authenticated_plug_test.exs new file mode 100644 index 000000000..ce5d77ff7 --- /dev/null +++ b/test/plugs/ensure_public_or_authenticated_plug_test.exs @@ -0,0 +1,55 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do + use Pleroma.Web.ConnCase, async: true + + alias Pleroma.Config + alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug + alias Pleroma.User + + test "it halts if not public and no user is assigned", %{conn: conn} do + set_public_to(false) + + conn = + conn + |> EnsurePublicOrAuthenticatedPlug.call(%{}) + + assert conn.status == 403 + assert conn.halted == true + end + + test "it continues if public", %{conn: conn} do + set_public_to(true) + + ret_conn = + conn + |> EnsurePublicOrAuthenticatedPlug.call(%{}) + + assert ret_conn == conn + end + + test "it continues if a user is assigned, even if not public", %{conn: conn} do + set_public_to(false) + + conn = + conn + |> assign(:user, %User{}) + + ret_conn = + conn + |> EnsurePublicOrAuthenticatedPlug.call(%{}) + + assert ret_conn == conn + end + + defp set_public_to(value) do + orig = Config.get!([:instance, :public]) + Config.put([:instance, :public], value) + + on_exit(fn -> + Config.put([:instance, :public], orig) + end) + end +end |
