-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adrián Quintás
committed
Mar 6, 2018
1 parent
517d9d6
commit 086e519
Showing
1 changed file
with
9 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,22 @@ defmodule JwtTestUtils.AuthConnCase do | |
@fake_user_id "[email protected]" | ||
@auth_header "authorization" | ||
|
||
alias JwtTestUtils.JwtMocker | ||
|
||
@doc """ | ||
Returns a Plug.Conn with a injected header with a JWT token injected. | ||
By default returns always the same token in the "authorization" header. | ||
""" | ||
@spec get_claim(String.t(), String.t()) :: {Plug.Conn.t()} | ||
@spec build_authed_conn(String.t(), String.t()) :: {Plug.Conn.t()} | ||
def build_authed_conn(user_id \\ @fake_user_id, auth_header \\ @auth_header) do | ||
jwt = JwtMocker.generate_json_token(user_id) | ||
conn = Plug.Adapters.Test.Conn.conn(%Conn{}, :get, "/", nil) | ||
|
||
conn = | ||
Plug.Adapters.Test.Conn.conn(%Plug.Conn{}, :get, "/", nil) | ||
|> Plug.Conn.put_private(:plug_skip_csrf_protection, true) | ||
|> Plug.Conn.put_private(:phoenix_recycled, true) | ||
|
||
Plug.Conn.put_req_header(conn, auth_header, jwt) | ||
end | ||
end | ||
|