X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fplugs%2Fauthentication_plug_test.exs;h=5480dab43019921356b9e17f9a80dc347eb0c28f;hb=5e36b750c1f98c440f4edcb9bb5bac5e6f93278f;hp=6f1568ec39588f7c73234c0d363275f1330884b6;hpb=32aa83f3a2a6ab14e36a3452708ea3be94ad4c43;p=akkoma diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs index 6f1568ec3..5480dab43 100644 --- a/test/plugs/authentication_plug_test.exs +++ b/test/plugs/authentication_plug_test.exs @@ -2,17 +2,25 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do use Pleroma.Web.ConnCase, async: true alias Pleroma.Plugs.AuthenticationPlug + alias Pleroma.User defp fetch_nil(_name) do {:ok, nil} end - @user %{ + @user %User{ id: 1, name: "dude", password_hash: Comeonin.Pbkdf2.hashpwsalt("guy") } + @deactivated %User{ + id: 1, + name: "dude", + password_hash: Comeonin.Pbkdf2.hashpwsalt("guy"), + info: %{"deactivated" => true} + } + @session_opts [ store: :cookie, key: "_test", @@ -129,6 +137,27 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do assert conn.halted == false end end + + describe "with a correct authorization header for an deactiviated user" do + test "it halts the appication", %{conn: conn} do + opts = %{ + optional: false, + fetcher: fn _ -> @deactivated end + } + + header = basic_auth_enc("dude", "guy") + + conn = conn + |> Plug.Session.call(Plug.Session.init(@session_opts)) + |> fetch_session + |> put_req_header("authorization", header) + |> AuthenticationPlug.call(opts) + + assert conn.status == 403 + assert conn.halted == true + end + end + describe "with a user_id in the session for an existing user" do test "it assigns the user", %{conn: conn} do opts = %{ @@ -150,4 +179,15 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do assert conn.halted == false end end + + describe "with an assigned user" do + test "it does nothing, returning the incoming conn", %{conn: conn} do + conn = conn + |> assign(:user, @user) + + conn_result = AuthenticationPlug.call(conn, %{}) + + assert conn == conn_result + end + end end