1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.Plugs.LegacyAuthenticationPlug
14 # password is "password"
19 "$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1"
25 test "it does nothing if a user is assigned", %{conn: conn, user: user} do
28 |> assign(:auth_credentials, %{username: "dude", password: "password"})
29 |> assign(:auth_user, user)
30 |> assign(:user, %User{})
34 |> LegacyAuthenticationPlug.call(%{})
36 assert ret_conn == conn
39 test "it authenticates the auth_user if present and password is correct and resets the password",
46 |> assign(:auth_credentials, %{username: "dude", password: "password"})
47 |> assign(:auth_user, user)
51 {:crypt, [], [crypt: fn _password, password_hash -> password_hash end]},
54 reset_password: fn user, %{password: password, password_confirmation: password} ->
59 LegacyAuthenticationPlug.call(conn, %{})
62 assert conn.assigns.user == user
65 test "it does nothing if the password is wrong", %{
71 |> assign(:auth_credentials, %{username: "dude", password: "wrong_password"})
72 |> assign(:auth_user, user)
76 |> LegacyAuthenticationPlug.call(%{})
78 assert conn == ret_conn
81 test "with no credentials or user it does nothing", %{conn: conn} do
84 |> LegacyAuthenticationPlug.call(%{})
86 assert ret_conn == conn