-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rjsamson/test-coverage
Auth test coverage
- Loading branch information
Showing
14 changed files
with
126 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Stackfooter.ConsoleControllerTest do | ||
use Stackfooter.ConnCase | ||
|
||
@apikey "4cy7uf63Lw2Sx6652YmLwBKy662weU4q" | ||
|
||
setup config do | ||
reset_api_keys() | ||
|
||
if username = config[:login_as] do | ||
user = insert_user(username: username, api_keys: [@apikey]) | ||
conn = assign(build_conn(), :current_user, user) | ||
|
||
{:ok, conn: conn, user: user} | ||
else | ||
{:ok, conn: build_conn()} | ||
end | ||
end | ||
|
||
@tag login_as: "rjsamson1234" | ||
test "Trade path is authenticated", %{conn: conn, user: _user} do | ||
conn = get(conn, "/console") | ||
assert html_response(conn, 200) =~ "rjsamson1234" | ||
end | ||
|
||
test "Redirects if not authenticated", %{conn: conn} do | ||
conn = get(conn, "/console") | ||
assert redirected_to(conn) == session_path(conn, :new) | ||
end | ||
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Stackfooter.TradeControllerTest do | ||
use Stackfooter.ConnCase | ||
|
||
@apikey "4cy7uf63Lw2Sx6652YmLwBKy662weU4q" | ||
|
||
setup config do | ||
reset_api_keys() | ||
|
||
if username = config[:login_as] do | ||
user = insert_user(username: username, api_keys: [@apikey]) | ||
conn = assign(build_conn(), :current_user, user) | ||
|
||
{:ok, conn: conn, user: user} | ||
else | ||
{:ok, conn: build_conn()} | ||
end | ||
end | ||
|
||
@tag login_as: "rjsamson1234" | ||
test "Trade path is authenticated", %{conn: conn, user: _user} do | ||
conn = get(conn, "/trade") | ||
assert html_response(conn, 200) =~ "rjsamson1234" | ||
end | ||
|
||
test "Redirects if not authenticated", %{conn: conn} do | ||
conn = get(conn, "/trade") | ||
assert redirected_to(conn) == session_path(conn, :new) | ||
end | ||
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
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 |
---|---|---|
@@ -1,11 +1,33 @@ | ||
defmodule Stackfooter.TestHelpers do | ||
def insert_user(attrs \\ %{}) do | ||
default_api_key = Application.get_env(:stackfooter, :bootstrap)[:default_api_key] | ||
default_account = Application.get_env(:stackfooter, :bootstrap)[:default_account] | ||
|
||
params = Dict.merge(%{ | ||
username: "user#{Base.encode16(:crypto.rand_bytes(8))}", | ||
password: "securepassword" | ||
username: default_account, | ||
password: "securepassword", | ||
api_keys: [default_api_key] | ||
}, attrs) | ||
|
||
changeset = Stackfooter.User.changeset(%Stackfooter.User{}, params) | ||
Stackfooter.Repo.insert!(changeset) | ||
user = Stackfooter.Repo.insert!(changeset) | ||
|
||
api_keys = user.api_keys | ||
acct = user.username | ||
|
||
Enum.map(api_keys, fn(key) -> Stackfooter.ApiKeyRegistry.add_key(Stackfooter.ApiKeyRegistry, key, acct) end) | ||
user | ||
end | ||
|
||
def reset_api_keys do | ||
Stackfooter.ApiKeyRegistry.reset_api_keys(Stackfooter.ApiKeyRegistry) | ||
|
||
default_api_key = Application.get_env(:stackfooter, :bootstrap)[:default_api_key] | ||
default_account = Application.get_env(:stackfooter, :bootstrap)[:default_account] | ||
|
||
# Default API key(s) to be added on application start. | ||
# Add more here, and in config/env.secret.exs | ||
|
||
Stackfooter.ApiKeyRegistry.add_key(Stackfooter.ApiKeyRegistry, default_api_key, default_account) | ||
end | ||
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