Merge pull request 'metrics' (#375) from stats into develop
[akkoma] / test / pleroma / web / auth / authenticator_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Auth.AuthenticatorTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Web.Auth.Helpers
9 import Pleroma.Factory
10
11 describe "fetch_user/1" do
12 test "returns user by name" do
13 user = insert(:user)
14 assert Helpers.fetch_user(user.nickname) == user
15 end
16
17 test "returns user by email" do
18 user = insert(:user)
19 assert Helpers.fetch_user(user.email) == user
20 end
21
22 test "returns nil" do
23 assert Helpers.fetch_user("email") == nil
24 end
25 end
26
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"}}
31 end
32
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"}}
36 end
37
38 test "returns error" do
39 assert Helpers.fetch_credentials(%{}) == {:error, :invalid_credentials}
40 end
41 end
42 end