forked from AkkomaGang/akkoma
Fixed formatting and test
This commit is contained in:
parent
5bfb7b4ce6
commit
98b36d359a
2 changed files with 3 additions and 8 deletions
|
@ -189,7 +189,7 @@ defp shortname(name) do
|
||||||
|
|
||||||
def confirm_current_password(user, params) do
|
def confirm_current_password(user, params) do
|
||||||
with %User{local: true} = db_user <- Repo.get(User, user.id),
|
with %User{local: true} = db_user <- Repo.get(User, user.id),
|
||||||
true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do
|
true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do
|
||||||
{:ok, db_user}
|
{:ok, db_user}
|
||||||
else
|
else
|
||||||
_ -> {:error, "Invalid password."}
|
_ -> {:error, "Invalid password."}
|
||||||
|
|
|
@ -18,19 +18,14 @@ test "it adds attachment links to a given text and attachment set" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "it confirms the password given is the current users password" do
|
describe "it confirms the password given is the current users password" do
|
||||||
test "with no credentials" do
|
test "incorrect password given" do
|
||||||
assert Utils.confirm_current_password(nil, %{"password" => "test"}) ==
|
|
||||||
{:error, "Invalid credentials."}
|
|
||||||
end
|
|
||||||
|
|
||||||
test "with incorrect password given" do
|
|
||||||
{:ok, user} = UserBuilder.insert()
|
{:ok, user} = UserBuilder.insert()
|
||||||
|
|
||||||
assert Utils.confirm_current_password(user, %{"password" => ""}) ==
|
assert Utils.confirm_current_password(user, %{"password" => ""}) ==
|
||||||
{:error, "Invalid password."}
|
{:error, "Invalid password."}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with correct password given" do
|
test "correct password given" do
|
||||||
{:ok, user} = UserBuilder.insert()
|
{:ok, user} = UserBuilder.insert()
|
||||||
assert Utils.confirm_current_password(user, %{"password" => "test"}) == {:ok, user}
|
assert Utils.confirm_current_password(user, %{"password" => "test"}) == {:ok, user}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue