logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

pleroma_authenticator_test.exs (1767B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Web.Auth.PleromaAuthenticator
  7. import Pleroma.Factory
  8. setup do
  9. password = "testpassword"
  10. name = "AgentSmith"
  11. user =
  12. insert(:user,
  13. nickname: name,
  14. password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)
  15. )
  16. {:ok, [user: user, name: name, password: password]}
  17. end
  18. test "get_user/authorization", %{name: name, password: password} do
  19. name = name <> "1"
  20. user = insert(:user, nickname: name, password_hash: Bcrypt.hash_pwd_salt(password))
  21. params = %{"authorization" => %{"name" => name, "password" => password}}
  22. res = PleromaAuthenticator.get_user(%Plug.Conn{params: params})
  23. assert {:ok, returned_user} = res
  24. assert returned_user.id == user.id
  25. assert "$pbkdf2" <> _ = returned_user.password_hash
  26. end
  27. test "get_user/authorization with invalid password", %{name: name} do
  28. params = %{"authorization" => %{"name" => name, "password" => "password"}}
  29. res = PleromaAuthenticator.get_user(%Plug.Conn{params: params})
  30. assert {:error, {:checkpw, false}} == res
  31. end
  32. test "get_user/grant_type_password", %{user: user, name: name, password: password} do
  33. params = %{"grant_type" => "password", "username" => name, "password" => password}
  34. res = PleromaAuthenticator.get_user(%Plug.Conn{params: params})
  35. assert {:ok, user} == res
  36. end
  37. test "error credintails" do
  38. res = PleromaAuthenticator.get_user(%Plug.Conn{params: %{}})
  39. assert {:error, :invalid_credentials} == res
  40. end
  41. end