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
12 changed files
with
139 additions
and
116 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
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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
defmodule Openmaize.ConfirmEmailTest do | ||
use ExUnit.Case | ||
use Openmaize.TestCase | ||
use Plug.Test | ||
|
||
import Ecto.Changeset | ||
alias Openmaize.{ConfirmEmail, TestRepo, TestUser} | ||
alias Openmaize.{ConfirmEmail, TestRepo, TestUser, UserHelpers} | ||
|
||
@valid_link "email=fred%2B1%40mail.com&key=lg8UXGNMpb5LUGEDm62PrwW8c20qZmIw" | ||
@invalid_link "email=wrong%40mail.com&key=lg8UXGNMpb5LUGEDm62PrwW8c20qZmIw" | ||
@incomplete_link "email=wrong%40mail.com" | ||
|
||
setup do | ||
{:ok, _user} = TestRepo.get_by(TestUser, email: "[email protected]") | ||
|> change(%{confirmed_at: nil}) | ||
|> Openmaize.TestRepo.update | ||
UserHelpers.add_user() | ||
:ok | ||
end | ||
|
||
|
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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
defmodule Openmaize.LoginTest do | ||
use ExUnit.Case | ||
use Openmaize.TestCase | ||
use Plug.Test | ||
|
||
alias Openmaize.{DummyCrypto, TestRepo, TestUser} | ||
alias Openmaize.{DummyCrypto, TestRepo, TestUser, UserHelpers} | ||
|
||
setup do | ||
{:ok, _} = UserHelpers.add_user() | ||
{:ok, _} = UserHelpers.add_confirmed() | ||
:ok | ||
end | ||
|
||
def login(name, password, uniq \\ :email, user_params \\ "email") do | ||
conn(:post, "/login", | ||
|
@@ -20,14 +26,14 @@ defmodule Openmaize.LoginTest do | |
|
||
test "login succeeds with username" do | ||
conn = login("ray", "h4rd2gU3$$", :username, "username") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
%{username: username} = conn.private[:openmaize_user] | ||
assert username == "ray" | ||
end | ||
|
||
test "login succeeds with email" do | ||
conn = login("[email protected]", "h4rd2gU3$$") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
%{email: email} = conn.private[:openmaize_user] | ||
assert email == "[email protected]" | ||
end | ||
|
||
test "login fails when crypto mod changes" do | ||
|
@@ -60,14 +66,14 @@ defmodule Openmaize.LoginTest do | |
|
||
test "function unique_id with email" do | ||
conn = login("[email protected]", "h4rd2gU3$$", &phone_name/1, "email") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
%{email: email} = conn.private[:openmaize_user] | ||
assert email == "[email protected]" | ||
end | ||
|
||
test "function unique_id with phone" do | ||
conn = login("081555555", "h4rd2gU3$$", &phone_name/1, "email") | ||
%{id: id} = conn.private[:openmaize_user] | ||
assert id == 4 | ||
%{email: email} = conn.private[:openmaize_user] | ||
assert email == "[email protected]" | ||
end | ||
|
||
test "output to current_user does not contain password_hash or otp_secret" 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
defmodule Openmaize.ResetPasswordTest do | ||
use ExUnit.Case | ||
use Openmaize.TestCase | ||
use Plug.Test | ||
|
||
import Ecto.Changeset | ||
alias Comeonin.Bcrypt | ||
alias Openmaize.{ResetPassword, TestRepo, TestUser} | ||
alias Openmaize.{ResetPassword, TestRepo, TestUser, UserHelpers} | ||
|
||
setup do | ||
{:ok, _user} = TestRepo.get_by(TestUser, email: "[email protected]") | ||
|> change(%{reset_token: "lg8UXGNMpb5LUGEDm62PrwW8c20qZmIw", | ||
reset_sent_at: Ecto.DateTime.utc}) | ||
|> Openmaize.TestRepo.update | ||
UserHelpers.add_reset_user("lg8UXGNMpb5LUGEDm62PrwW8c20qZmIw") | ||
:ok | ||
end | ||
|
||
def call_reset(password, opts) do | ||
conn(:post, "/password_reset", | ||
%{"password_reset" => %{"email" => "dim@mail.com", | ||
%{"password_reset" => %{"email" => "frank@mail.com", | ||
"key" => "lg8UXGNMpb5LUGEDm62PrwW8c20qZmIw", | ||
"password" => password}}) | ||
|> ResetPassword.call(opts) | ||
end | ||
|
||
def password_changed(password) do | ||
user = TestRepo.get_by(TestUser, email: "dim@mail.com") | ||
user = TestRepo.get_by(TestUser, email: "frank@mail.com") | ||
Bcrypt.checkpw(password, user.password_hash) | ||
end | ||
|
||
|
@@ -47,7 +44,7 @@ defmodule Openmaize.ResetPasswordTest do | |
end | ||
|
||
test "reset password fails when reset_sent_at is nil" do | ||
user = TestRepo.get_by(TestUser, email: "dim@mail.com") | ||
user = TestRepo.get_by(TestUser, email: "frank@mail.com") | ||
change(user, %{reset_sent_at: nil}) | ||
|> Openmaize.TestRepo.update | ||
conn = call_reset("password", {TestRepo, TestUser, {120, &IO.puts/1}}) | ||
|
Oops, something went wrong.