logo

pleroma

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

authenticator_test.exs (1322B)


  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.AuthenticatorTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Web.Auth.Helpers
  7. import Pleroma.Factory
  8. describe "fetch_user/1" do
  9. test "returns user by name" do
  10. user = insert(:user)
  11. assert Helpers.fetch_user(user.nickname) == user
  12. end
  13. test "returns user by email" do
  14. user = insert(:user)
  15. assert Helpers.fetch_user(user.email) == user
  16. end
  17. test "returns nil" do
  18. assert Helpers.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 Helpers.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 Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
  29. end
  30. test "returns error" do
  31. assert Helpers.fetch_credentials(%{}) == {:error, :invalid_credentials}
  32. end
  33. end
  34. end