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, async: true
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 reset_password: fn user, %{password: password, password_confirmation: password} ->
52 send(self(), :reset_password)
56 |> LegacyAuthenticationPlug.call(%{})
59 assert_received :reset_password
60 assert conn.assigns.user == user
63 test "it does nothing if the password is wrong", %{
69 |> assign(:auth_credentials, %{username: "dude", password: "wrong_password"})
70 |> assign(:auth_user, user)
74 |> LegacyAuthenticationPlug.call(%{})
76 assert conn == ret_conn
79 test "with no credentials or user it does nothing", %{conn: conn} do
82 |> LegacyAuthenticationPlug.call(%{})
84 assert ret_conn == conn