2022-12-19 22:45:01 -05:00
|
|
|
defmodule Chessh.Auth.PasswordAuthenticatorTest do
|
|
|
|
use ExUnit.Case
|
2022-12-28 01:50:22 -05:00
|
|
|
alias Chessh.{Player, Repo}
|
2022-12-19 22:45:01 -05:00
|
|
|
|
|
|
|
@valid_user %{username: "logan", password: "password"}
|
|
|
|
|
2022-12-28 01:50:22 -05:00
|
|
|
setup_all do
|
2022-12-29 19:49:42 -05:00
|
|
|
Ecto.Adapters.SQL.Sandbox.checkout(Repo)
|
|
|
|
Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
|
2022-12-19 22:45:01 -05:00
|
|
|
|
|
|
|
{:ok, _user} = Repo.insert(Player.registration_changeset(%Player{}, @valid_user))
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2022-12-28 01:50:22 -05:00
|
|
|
test "Password can authenticate a hashed password" do
|
2022-12-19 22:45:01 -05:00
|
|
|
assert Chessh.Auth.PasswordAuthenticator.authenticate(
|
2022-12-29 19:21:20 -05:00
|
|
|
@valid_user.username,
|
|
|
|
@valid_user.password
|
2022-12-19 22:45:01 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
refute Chessh.Auth.PasswordAuthenticator.authenticate(
|
2022-12-29 19:21:20 -05:00
|
|
|
@valid_user.username,
|
|
|
|
"a_bad_password"
|
2022-12-19 22:45:01 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|