This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
40 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ defmodule <%= base %>.UserTest do | |
|
||
alias <%= base %>.User | ||
|
||
@valid_attrs %{username: "fred", email: "fred@mail.com", password: "mangoes&gooseberries"} | ||
@valid_attrs %{email: "fred@mail.com", username: "fred", password: "mangoes&gooseberries"} | ||
@invalid_attrs %{email: "[email protected]", password: "mangoes&gooseberries"} | ||
|
||
test "changeset with valid attributes" do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,28 @@ defmodule Openmaize.LoginTest do | |
|
||
alias Openmaize.{DummyCrypto, TestRepo, TestUser} | ||
|
||
def login(name, password, uniq \\ :username, user_params \\ "username") do | ||
def login(name, password, uniq \\ :email, user_params \\ "email") do | ||
conn(:post, "/login", | ||
%{"session" => %{user_params => name, "password" => password}}) | ||
|> Openmaize.Login.call({uniq, user_params, TestRepo, TestUser}) | ||
end | ||
|
||
def phone_name(%{"username" => username, "password" => password}) do | ||
{Regex.match?(~r/^[0-9]+$/, username) and :phone || :username, username, password} | ||
def phone_name(%{"email" => email, "password" => password}) do | ||
{Regex.match?(~r/^[0-9]+$/, email) and :phone || :email, email, password} | ||
end | ||
|
||
test "init function" do | ||
assert Openmaize.Login.init([]) == {:username, "username", Openmaize.Repo, Openmaize.User} | ||
assert Openmaize.Login.init([]) == {:email, "email", Openmaize.Repo, Openmaize.User} | ||
end | ||
|
||
test "login succeeds with username" do | ||
conn = login("ray", "h4rd2gU3$$") | ||
conn = login("ray", "h4rd2gU3$$", :username, "username") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
end | ||
|
||
test "login succeeds with email" do | ||
conn = login("[email protected]", "h4rd2gU3$$", :email, "email") | ||
conn = login("[email protected]", "h4rd2gU3$$") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
end | ||
|
@@ -44,34 +44,34 @@ defmodule Openmaize.LoginTest do | |
end | ||
|
||
test "login fails when account is not yet confirmed" do | ||
conn = login("fred", "mangoes&g0oseberries") | ||
conn = login("fred", "mangoes&g0oseberries", :username, "username") | ||
assert conn.private[:openmaize_error] =~ "have to confirm your account" | ||
end | ||
|
||
test "login fails for invalid username" do | ||
conn = login("dick", "h4rd2gU3$$") | ||
conn = login("dick", "h4rd2gU3$$", :username, "username") | ||
assert conn.private[:openmaize_error] =~ "Invalid credentials" | ||
end | ||
|
||
test "login fails for invalid email" do | ||
conn = login("[email protected]", "h4rd2gU3$$", :email, "email") | ||
conn = login("[email protected]", "h4rd2gU3$$") | ||
assert conn.private[:openmaize_error] =~ "Invalid credentials" | ||
end | ||
|
||
test "function unique_id with username" do | ||
conn = login("ray", "h4rd2gU3$$", &phone_name/1, "username") | ||
test "function unique_id with email" do | ||
conn = login("ray@mail.com", "h4rd2gU3$$", &phone_name/1, "email") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
end | ||
|
||
test "function unique_id with phone" do | ||
conn = login("081555555", "h4rd2gU3$$", &phone_name/1, "username") | ||
conn = login("081555555", "h4rd2gU3$$", &phone_name/1, "email") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
end | ||
|
||
test "output to current_user does not contain password_hash or otp_secret" do | ||
conn = login("ray", "h4rd2gU3$$") | ||
conn = login("ray", "h4rd2gU3$$", :username, "username") | ||
user = conn.private[:openmaize_user] | ||
refute Map.has_key?(user, :password_hash) | ||
refute Map.has_key?(user, :otp_secret) | ||
|