logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

legacy_authentication_plug_test.exs (2083B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
  5. use Pleroma.Web.ConnCase
  6. import Pleroma.Factory
  7. alias Pleroma.Plugs.LegacyAuthenticationPlug
  8. alias Pleroma.Plugs.OAuthScopesPlug
  9. alias Pleroma.Plugs.PlugHelper
  10. alias Pleroma.User
  11. setup do
  12. user =
  13. insert(:user,
  14. password: "password",
  15. password_hash:
  16. "$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1"
  17. )
  18. %{user: user}
  19. end
  20. test "it does nothing if a user is assigned", %{conn: conn, user: user} do
  21. conn =
  22. conn
  23. |> assign(:auth_credentials, %{username: "dude", password: "password"})
  24. |> assign(:auth_user, user)
  25. |> assign(:user, %User{})
  26. ret_conn =
  27. conn
  28. |> LegacyAuthenticationPlug.call(%{})
  29. assert ret_conn == conn
  30. end
  31. @tag :skip_on_mac
  32. test "if `auth_user` is present and password is correct, " <>
  33. "it authenticates the user, resets the password, marks OAuthScopesPlug as skipped",
  34. %{
  35. conn: conn,
  36. user: user
  37. } do
  38. conn =
  39. conn
  40. |> assign(:auth_credentials, %{username: "dude", password: "password"})
  41. |> assign(:auth_user, user)
  42. conn = LegacyAuthenticationPlug.call(conn, %{})
  43. assert conn.assigns.user.id == user.id
  44. assert PlugHelper.plug_skipped?(conn, OAuthScopesPlug)
  45. end
  46. @tag :skip_on_mac
  47. test "it does nothing if the password is wrong", %{
  48. conn: conn,
  49. user: user
  50. } do
  51. conn =
  52. conn
  53. |> assign(:auth_credentials, %{username: "dude", password: "wrong_password"})
  54. |> assign(:auth_user, user)
  55. ret_conn =
  56. conn
  57. |> LegacyAuthenticationPlug.call(%{})
  58. assert conn == ret_conn
  59. end
  60. test "with no credentials or user it does nothing", %{conn: conn} do
  61. ret_conn =
  62. conn
  63. |> LegacyAuthenticationPlug.call(%{})
  64. assert ret_conn == conn
  65. end
  66. end