1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Auth.AuthenticatorTest do
6 use Pleroma.Web.ConnCase, async: true
8 alias Pleroma.Web.Auth.Helpers
11 describe "fetch_user/1" do
12 test "returns user by name" do
14 assert Helpers.fetch_user(user.nickname) == user
17 test "returns user by email" do
19 assert Helpers.fetch_user(user.email) == user
23 assert Helpers.fetch_user("email") == nil
27 describe "fetch_credentials/1" do
28 test "returns name and password from authorization params" do
29 params = %{"authorization" => %{"name" => "test", "password" => "test-pass"}}
30 assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
33 test "returns name and password with grant_type 'password'" do
34 params = %{"grant_type" => "password", "username" => "test", "password" => "test-pass"}
35 assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
38 test "returns error" do
39 assert Helpers.fetch_credentials(%{}) == {:error, :invalid_credentials}