1 defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
2 use Pleroma.Web.ConnCase, async: true
4 alias Pleroma.Plugs.LegacyAuthenticationPlug
10 # password is "password"
15 "$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1"
21 test "it does nothing if a user is assigned", %{conn: conn, user: user} do
24 |> assign(:auth_credentials, %{username: "dude", password: "password"})
25 |> assign(:auth_user, user)
26 |> assign(:user, %User{})
30 |> LegacyAuthenticationPlug.call(%{})
32 assert ret_conn == conn
35 test "it authenticates the auth_user if present and password is correct and resets the password",
42 |> assign(:auth_credentials, %{username: "dude", password: "password"})
43 |> assign(:auth_user, user)
47 reset_password: fn user, %{password: password, password_confirmation: password} ->
48 send(self(), :reset_password)
52 |> LegacyAuthenticationPlug.call(%{})
55 assert_received :reset_password
56 assert conn.assigns.user == user
59 test "it does nothing if the password is wrong", %{
65 |> assign(:auth_credentials, %{username: "dude", password: "wrong_password"})
66 |> assign(:auth_user, user)
70 |> LegacyAuthenticationPlug.call(%{})
72 assert conn == ret_conn
75 test "with no credentials or user it does nothing", %{conn: conn} do
78 |> LegacyAuthenticationPlug.call(%{})
80 assert ret_conn == conn