Skip to content

Commit

Permalink
create tests for password_prompt/2 for #63 >> 100%!!
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed May 8, 2020
1 parent f1830fb commit a3dff03
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/auth_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ defmodule AuthWeb.AuthController do
see:
"""
def password_create(conn, params) do
IO.inspect(params, label: "password_create > params:271")
# IO.inspect(params, label: "password_create > params:271")
p = params["person"]
email = Auth.Person.decrypt_email(p["email"])
person = Auth.Person.upsert_person(%{email: email, password: p["password"]})
Expand All @@ -305,10 +305,12 @@ defmodule AuthWeb.AuthController do
TODO:
"""
def password_prompt(conn, params) do # verify the password
IO.inspect(params, label: "password_prompt params:294")
# IO.inspect(params, label: "password_prompt params:294")
p = params["person"]
email = Auth.Person.decrypt_email(p["email"])
# IO.inspect(email, label: "email:311")
person = Auth.Person.get_person_by_email(email)
# IO.inspect(person, label: "person:312")

case Argon2.verify_pass(p["password"], person.password_hash) do
true ->
Expand Down
41 changes: 41 additions & 0 deletions test/auth_web/controllers/auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,45 @@ defmodule AuthWeb.AuthControllerTest do
conn = get(conn, link, %{})
assert html_response(conn, 302) =~ "redirected"
end

test "password_prompt/2 verify VALID password", %{conn: conn} do
data = %{
email: "[email protected]",
auth_provider: "email",
status: 1,
password: "thiswillbehashed"
}
Auth.Person.upsert_person(data)
state = AuthPlug.Helpers.get_baseurl_from_conn(conn)
<> "/profile?auth_client_id=" <> AuthPlug.Token.client_id()

params = %{ "person" => %{
"email" => AuthWeb.ApikeyController.encrypt_encode(data.email),
"password" => "thiswillbehashed",
"state" => state
}}
conn = post(conn, "/auth/password/verify", params)
# IO.inspect(conn, label: "conn")
assert html_response(conn, 302) =~ "redirected"
end

test "password_prompt/2 verify INVALID password", %{conn: conn} do
data = %{
email: "[email protected]",
auth_provider: "email",
status: 1,
password: "thiswillbehashed"
}
Auth.Person.upsert_person(data)
state = AuthPlug.Helpers.get_baseurl_from_conn(conn)
<> "/profile?auth_client_id=" <> AuthPlug.Token.client_id()

params = %{ "person" => %{
"email" => AuthWeb.ApikeyController.encrypt_encode(data.email),
"password" => "fail",
"state" => state
}}
conn = post(conn, "/auth/password/verify", params)
assert html_response(conn, 200) =~ "password is incorrect"
end
end

0 comments on commit a3dff03

Please sign in to comment.