-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add tests for reset token functionality;
- add test to ensure that disable preserves existing token secrets; - move existing token tests to disable_token for clarity;
- Loading branch information
Showing
4 changed files
with
103 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "test_helper" | ||
require "integration_tests_helper" | ||
|
||
class DisableTokenTest < ActionDispatch::IntegrationTest | ||
|
||
def setup | ||
# log in 1fa | ||
@user = enable_otp_and_sign_in | ||
assert_equal user_otp_credential_path, current_path | ||
|
||
# otp 2fa | ||
fill_in "user_token", with: ROTP::TOTP.new(@user.otp_auth_secret).at(Time.now) | ||
click_button "Submit Token" | ||
assert_equal root_path, current_path | ||
end | ||
|
||
def teardown | ||
Capybara.reset_sessions! | ||
end | ||
|
||
test "disabling OTP after successfully enabling" do | ||
# disable OTP | ||
disable_otp | ||
|
||
assert page.has_content? "Disabled" | ||
|
||
# logout | ||
sign_out | ||
|
||
# log back in 1fa | ||
sign_user_in(@user) | ||
|
||
assert_equal root_path, current_path | ||
end | ||
|
||
test "disabling OTP does not reset token secrets" do | ||
# get otp secrets | ||
@user.reload | ||
auth_secret = @user.otp_auth_secret | ||
recovery_secret = @user.otp_recovery_secret | ||
|
||
# disable OTP | ||
disable_otp | ||
|
||
# compare otp secrets | ||
assert_not_nil @user.otp_auth_secret | ||
assert_equal @user.otp_auth_secret, auth_secret | ||
|
||
assert_not_nil @user.otp_recovery_secret | ||
assert_equal @user.otp_recovery_secret, recovery_secret | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "test_helper" | ||
require "integration_tests_helper" | ||
|
||
class ResetTokenTest < ActionDispatch::IntegrationTest | ||
|
||
def setup | ||
# log in 1fa | ||
@user = enable_otp_and_sign_in | ||
assert_equal user_otp_credential_path, current_path | ||
|
||
# otp 2fa | ||
fill_in "user_token", with: ROTP::TOTP.new(@user.otp_auth_secret).at(Time.now) | ||
click_button "Submit Token" | ||
assert_equal root_path, current_path | ||
end | ||
|
||
|
||
def teardown | ||
Capybara.reset_sessions! | ||
end | ||
|
||
test "redirects to otp_tokens#edit page" do | ||
reset_otp | ||
|
||
assert_equal "/users/otp/token/edit", current_path | ||
end | ||
|
||
test "generates new token secrets" do | ||
# get auth secrets | ||
auth_secret = @user.otp_auth_secret | ||
recovery_secret = @user.otp_recovery_secret | ||
|
||
# reset otp | ||
reset_otp | ||
|
||
# compare auth secrets | ||
@user.reload | ||
assert_not_nil @user.otp_auth_secret | ||
assert_not_equal @user.otp_auth_secret, auth_secret | ||
|
||
assert_not_nil @user.otp_recovery_secret | ||
assert_not_equal @user.otp_recovery_secret, recovery_secret | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
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