Pleroma Authenticator: Also update passwords here.
This commit is contained in:
parent
bfdd90f6d7
commit
8bfd9710ae
|
@ -16,7 +16,8 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticator do
|
||||||
def get_user(%Plug.Conn{} = conn) do
|
def get_user(%Plug.Conn{} = conn) do
|
||||||
with {:ok, {name, password}} <- fetch_credentials(conn),
|
with {:ok, {name, password}} <- fetch_credentials(conn),
|
||||||
{_, %User{} = user} <- {:user, fetch_user(name)},
|
{_, %User{} = user} <- {:user, fetch_user(name)},
|
||||||
{_, true} <- {:checkpw, AuthenticationPlug.checkpw(password, user.password_hash)} do
|
{_, true} <- {:checkpw, AuthenticationPlug.checkpw(password, user.password_hash)},
|
||||||
|
{:ok, user} <- AuthenticationPlug.maybe_update_password(user, password) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
{:error, _reason} = error -> error
|
{:error, _reason} = error -> error
|
||||||
|
|
|
@ -15,11 +15,16 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
|
||||||
{:ok, [user: user, name: name, password: password]}
|
{:ok, [user: user, name: name, password: password]}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get_user/authorization", %{user: user, name: name, password: password} do
|
test "get_user/authorization", %{name: name, password: password} do
|
||||||
|
name = name <> "1"
|
||||||
|
user = insert(:user, nickname: name, password_hash: Bcrypt.hash_pwd_salt(password))
|
||||||
|
|
||||||
params = %{"authorization" => %{"name" => name, "password" => password}}
|
params = %{"authorization" => %{"name" => name, "password" => password}}
|
||||||
res = PleromaAuthenticator.get_user(%Plug.Conn{params: params})
|
res = PleromaAuthenticator.get_user(%Plug.Conn{params: params})
|
||||||
|
|
||||||
assert {:ok, user} == res
|
assert {:ok, returned_user} = res
|
||||||
|
assert returned_user.id == user.id
|
||||||
|
assert "$pbkdf2" <> _ = returned_user.password_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get_user/authorization with invalid password", %{name: name} do
|
test "get_user/authorization with invalid password", %{name: name} do
|
||||||
|
|
Loading…
Reference in New Issue