-
Notifications
You must be signed in to change notification settings - Fork 1
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 #33 from epochtalk/role-controller-acls
Role controller acls
- Loading branch information
Showing
5 changed files
with
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,14 +80,14 @@ defmodule EpochtalkServer.MixProject do | |
"seed.roles": ["run priv/repo/seed_roles.exs"], | ||
"seed.rp": ["run priv/repo/seed_roles_permissions.exs"], | ||
"seed.user": ["run priv/repo/seed_user.exs"], | ||
"seed.test_users": ["run priv/repo/seed_test_users.exs"], | ||
test: [ | ||
"ecto.drop", | ||
"ecto.create --quiet", | ||
"ecto.migrate --quiet", | ||
"seed.test_banned_address", | ||
"seed.all", | ||
"seed.user test [email protected] password", | ||
"seed.user admin [email protected] password admin", | ||
"seed.test_users", | ||
"test" | ||
] | ||
] | ||
|
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,26 @@ | ||
alias EpochtalkServer.Models.User | ||
|
||
test_user_username = "test" | ||
test_user_email = "[email protected]" | ||
test_user_password = "password" | ||
|
||
test_admin_user_username = "admin" | ||
test_admin_user_email = "[email protected]" | ||
test_admin_user_password = "password" | ||
test_admin_user_admin = true | ||
|
||
User.create(%{username: test_user_username, email: test_user_email, password: test_user_password}) | ||
|> case do | ||
{:ok, _} -> IO.puts("Successfully seeded test user") | ||
{:error, error} -> | ||
IO.puts("Error seeding test user") | ||
IO.inspect(error) | ||
end | ||
|
||
User.create(%{username: test_admin_user_username, email: test_admin_user_email, password: test_admin_user_password}, test_admin_user_admin) | ||
|> case do | ||
{:ok, _} -> IO.puts("Successfully seeded test admin user") | ||
{:error, error} -> | ||
IO.puts("Error seeding test admin user") | ||
IO.inspect(error) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,16 @@ defmodule EpochtalkServerWeb.ConnCase do | |
password: @test_password | ||
} | ||
|
||
# admin username/email/password from user seed in `mix test` (see mix.exs) | ||
@test_admin_username "admin" | ||
@test_admin_email "[email protected]" | ||
@test_admin_password "password" | ||
@test_admin_user_attrs %{ | ||
username: @test_admin_username, | ||
email: @test_admin_email, | ||
password: @test_admin_password | ||
} | ||
|
||
use ExUnit.CaseTemplate | ||
|
||
using do | ||
|
@@ -53,6 +63,7 @@ defmodule EpochtalkServerWeb.ConnCase do | |
end | ||
|
||
{:ok, user} = User.by_username(@test_username) | ||
{:ok, admin_user} = User.by_username(@test_admin_username) | ||
conn = Phoenix.ConnTest.build_conn() | ||
|
||
# log user in if necessary | ||
|
@@ -65,6 +76,16 @@ defmodule EpochtalkServerWeb.ConnCase do | |
{:ok, | ||
conn: authed_conn, authed_user: user, token: token, authed_user_attrs: @test_user_attrs} | ||
|
||
:admin -> | ||
remember_me = false | ||
{:ok, admin_user, token, authed_conn} = Session.create(admin_user, remember_me, conn) | ||
|
||
{:ok, | ||
conn: authed_conn, | ||
authed_user: admin_user, | ||
token: token, | ||
authed_user_attrs: @test_admin_user_attrs} | ||
|
||
# :authenticated not set, return default conn | ||
_ -> | ||
{:ok, conn: conn, user: user, user_attrs: @test_user_attrs} | ||
|