logo

pleroma

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

authenticator_test.exs (1351B)


  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.Web.Auth.AuthenticatorTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Web.Auth.Authenticator
  7. import Pleroma.Factory
  8. describe "fetch_user/1" do
  9. test "returns user by name" do
  10. user = insert(:user)
  11. assert Authenticator.fetch_user(user.nickname) == user
  12. end
  13. test "returns user by email" do
  14. user = insert(:user)
  15. assert Authenticator.fetch_user(user.email) == user
  16. end
  17. test "returns nil" do
  18. assert Authenticator.fetch_user("email") == nil
  19. end
  20. end
  21. describe "fetch_credentials/1" do
  22. test "returns name and password from authorization params" do
  23. params = %{"authorization" => %{"name" => "test", "password" => "test-pass"}}
  24. assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
  25. end
  26. test "returns name and password with grant_type 'password'" do
  27. params = %{"grant_type" => "password", "username" => "test", "password" => "test-pass"}
  28. assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
  29. end
  30. test "returns error" do
  31. assert Authenticator.fetch_credentials(%{}) == {:error, :invalid_credentials}
  32. end
  33. end
  34. end