Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.9KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 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.User
  9. setup do
  10. user =
  11. insert(:user,
  12. password: "password",
  13. password_hash:
  14. "$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1"
  15. )
  16. %{user: user}
  17. end
  18. test "it does nothing if a user is assigned", %{conn: conn, user: user} do
  19. conn =
  20. conn
  21. |> assign(:auth_credentials, %{username: "dude", password: "password"})
  22. |> assign(:auth_user, user)
  23. |> assign(:user, %User{})
  24. ret_conn =
  25. conn
  26. |> LegacyAuthenticationPlug.call(%{})
  27. assert ret_conn == conn
  28. end
  29. @tag :skip_on_mac
  30. test "it authenticates the auth_user if present and password is correct and resets the password",
  31. %{
  32. conn: conn,
  33. user: user
  34. } do
  35. conn =
  36. conn
  37. |> assign(:auth_credentials, %{username: "dude", password: "password"})
  38. |> assign(:auth_user, user)
  39. conn = LegacyAuthenticationPlug.call(conn, %{})
  40. assert conn.assigns.user.id == user.id
  41. end
  42. @tag :skip_on_mac
  43. test "it does nothing if the password is wrong", %{
  44. conn: conn,
  45. user: user
  46. } do
  47. conn =
  48. conn
  49. |> assign(:auth_credentials, %{username: "dude", password: "wrong_password"})
  50. |> assign(:auth_user, user)
  51. ret_conn =
  52. conn
  53. |> LegacyAuthenticationPlug.call(%{})
  54. assert conn == ret_conn
  55. end
  56. test "with no credentials or user it does nothing", %{conn: conn} do
  57. ret_conn =
  58. conn
  59. |> LegacyAuthenticationPlug.call(%{})
  60. assert ret_conn == conn
  61. end
  62. end