1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.LegacyAuthenticationPlugTest do
6 use Pleroma.Web.ConnCase
11 alias Pleroma.Web.Plugs.LegacyAuthenticationPlug
12 alias Pleroma.Web.Plugs.OAuthScopesPlug
13 alias Pleroma.Web.Plugs.PlugHelper
20 "$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1"
26 test "it does nothing if a user is assigned", %{conn: conn, user: user} do
29 |> assign(:auth_credentials, %{username: "dude", password: "password"})
30 |> assign(:auth_user, user)
31 |> assign(:user, %User{})
35 |> LegacyAuthenticationPlug.call(%{})
37 assert ret_conn == conn
41 test "if `auth_user` is present and password is correct, " <>
42 "it authenticates the user, resets the password, marks OAuthScopesPlug as skipped",
49 |> assign(:auth_credentials, %{username: "dude", password: "password"})
50 |> assign(:auth_user, user)
52 conn = LegacyAuthenticationPlug.call(conn, %{})
54 assert conn.assigns.user.id == user.id
55 assert PlugHelper.plug_skipped?(conn, OAuthScopesPlug)
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