auth_test_support v0.0.1 AuthTestSupport
A collection of common funcitonality to use in your Phoenix test suites.
use AuthTestSupport
in your test files.
Summary
Functions
Assert that the current connection is authenticated as a given account
Sign in to the session
Macros
Macro that generates a test for asserting that RESTful actions require authorization
Functions
Assert that the current connection is authenticated as a given account
Will run the following assertions:
- assert that
:account_id
value in the session is notnil
and is equal to theaccount
’s primary key value - assert that
:account_type
value in the sesion is notnil
and is equal to theaccount
’s struct
Macros
Macro that generates a test for asserting that RESTful actions require authorization
The assertion being run will expect that unauthorized route access will return a 401
Options:
:roles
takes an keyword list of role names. Keyword values can be a function reference that to manipulate theconn
object:only
only the actions in the keyword list given. Keyword values can be a map for passing custom params to the action:except
all actions (index, show, create, update, destroy
) except those in the keyword list. Keyword value behave similiar toonly
Examples
require_authorization :profile_path
require_authorization :profile_path, roles: [:no_auth, auth: &auth_conn/1]
defp auth_conn(conn) do
sign_in(conn, username: "user@example.com", password: "password")
end
require_authorization :profile_path, only: [create: %{foo: "bar"}]
Each call to require_authorization
only generates a single test, not multiple tests. This saves on compilation time.