2019-05-01 07:28:04 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-05-01 07:28:04 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.Auth.AuthenticatorTest do
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.Web.ConnCase, async: false
|
2019-05-01 07:28:04 -06:00
|
|
|
|
2021-06-07 17:07:54 -06:00
|
|
|
alias Pleroma.Web.Auth.Helpers
|
2019-05-01 07:28:04 -06:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "fetch_user/1" do
|
|
|
|
test "returns user by name" do
|
|
|
|
user = insert(:user)
|
2021-06-07 17:07:54 -06:00
|
|
|
assert Helpers.fetch_user(user.nickname) == user
|
2019-05-01 07:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "returns user by email" do
|
|
|
|
user = insert(:user)
|
2021-06-07 17:07:54 -06:00
|
|
|
assert Helpers.fetch_user(user.email) == user
|
2019-05-01 07:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "returns nil" do
|
2021-06-07 17:07:54 -06:00
|
|
|
assert Helpers.fetch_user("email") == nil
|
2019-05-01 07:28:04 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "fetch_credentials/1" do
|
|
|
|
test "returns name and password from authorization params" do
|
|
|
|
params = %{"authorization" => %{"name" => "test", "password" => "test-pass"}}
|
2021-06-07 17:07:54 -06:00
|
|
|
assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
2019-05-01 07:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "returns name and password with grant_type 'password'" do
|
|
|
|
params = %{"grant_type" => "password", "username" => "test", "password" => "test-pass"}
|
2021-06-07 17:07:54 -06:00
|
|
|
assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
2019-05-01 07:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "returns error" do
|
2021-06-07 17:07:54 -06:00
|
|
|
assert Helpers.fetch_credentials(%{}) == {:error, :invalid_credentials}
|
2019-05-01 07:28:04 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|