-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add after_session_confirm hook (#237)
- Loading branch information
1 parent
061599b
commit d4df0b3
Showing
4 changed files
with
67 additions
and
0 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 |
---|---|---|
|
@@ -221,6 +221,44 @@ class << User | |
assert_nil pwless_session(User) | ||
end | ||
|
||
test("PATCH /:passwordless_for/sign_in/:id -> after_session_confirm with request object") do | ||
user = create_user(email: "[email protected]") | ||
passwordless_session = create_pwless_session(authenticatable: user, token: "valid_token") | ||
|
||
confirm_called = false | ||
|
||
with_config(after_session_confirm: ->(session, request) { | ||
confirm_called = true | ||
assert_equal user, session.authenticatable | ||
assert_kind_of ActionDispatch::Request, request | ||
}) do | ||
patch( | ||
"/users/sign_in/#{passwordless_session.identifier}", | ||
params: {passwordless: {token: "valid_token"}} | ||
) | ||
end | ||
|
||
assert_equal 303, status | ||
assert confirm_called, "after_session_confirm hook was not called" | ||
end | ||
|
||
test("PATCH /:passwordless_for/sign_in/:id -> after_session_confirm not called on invalid token") do | ||
user = create_user(email: "[email protected]") | ||
passwordless_session = create_pwless_session(authenticatable: user, token: "valid_token") | ||
|
||
confirm_called = false | ||
|
||
with_config(after_session_confirm: ->(_) { confirm_called = true }) do | ||
patch( | ||
"/users/sign_in/#{passwordless_session.identifier}", | ||
params: {passwordless: {token: "invalid_token"}} | ||
) | ||
end | ||
|
||
assert_equal 403, status | ||
assert_not confirm_called, "after_session_confirm hook was called with invalid token" | ||
end | ||
|
||
test("DELETE /:passwordless_for/sign_out") do | ||
user = User.create(email: "a@a") | ||
passwordless_session = create_pwless_session(authenticatable: user, token: "hi") | ||
|