-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* scaffold solution for confirming OTP before enabling OTP; * Add instructions to confirm_otp_token form; * move "Enable Authentication" form to separate "edit" view; reduce "show" view to display link to form if otp is disabled; * use existing edit/update actions on otp_tokens controller for confirming/enabling Two-Factor-Authentication (rather than separate otp_confirm_tokens); * remove token explanation from show page; * update flash message for failed confirmation; * move locales for OTP confirmation form to edit_otp_tokens scope; delete unneeded values; * differentiate title of show and edit pages; move "title" value for edit_otp_tokens to "lead_in"; * revert method name to enable_top!; * revert "h2" for otp_tokens#show to locale file; * use enable_link config locale in otp_tokens#show; * use locales for otp_token field and submit button; switch terminology to "Verification Code"; * match terminology to AWS MFA form; * replace remaining reference to "Verification Code"; * add tests for enabling two-factor authentication via dedicated otp_token#edit action; * update test helpers and initial sign_in test for new Enable Two-Factor Authentication form; * update otp_tokens#update to redirect to show action as before (rather than redirecting via otp_credential_path); * update disable test to confirm correct status displayed; remove accept_confirm block (not needed); * update EnableOtpForm tests to reload user before checking whether OTP was enabled, and to check for actual page content rather than flash message content for reliability; * add populate_otp! method for populating initial secrets; add instructions to README for existing users; * update otp_tokens controller to populate otp secrets as needed; rename method to "populate_otp_secrets!", replace reset_otp_credentials! method with destroy_otp_secrets!, and remove "on create" callbacks for consistency; * update button text and warnings for disabling 2FA; remove instructions for existing users from README (no longer needed); * update tests for change; add otp_failed_attempts to destroy_otp_secrets! method; * rename destroy_otp_secrets! to clear_otp_fields! for consistency (since it includes counters and challenges as well); * simplify populate_otp_secrets! method; * draft CHANGELOG insertion for requiring confirmation token and populating OTP secrets as needed; * rename "otp_token" input to "confirmation_code"; make edit_otp_token scope singular; fix spelling issue in "Enable Two Factor Authentication" link; expand "Changes to Locales" description in CHANGELOG; * Update CHANGELOG.md to fix list indentation issue; --------- Co-authored-by: Laney Stroup <[email protected]>
- Loading branch information
Showing
14 changed files
with
262 additions
and
94 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h2><%= I18n.t('title', :scope => 'devise.otp.edit_otp_token') %></h2> | ||
<p><%= I18n.t('explain', :scope => 'devise.otp.edit_otp_token') %></p> | ||
|
||
<h2><%= I18n.t('lead_in', :scope => 'devise.otp.edit_otp_token') %></h2> | ||
|
||
<p><%= I18n.t('step_1', :scope => 'devise.otp.edit_otp_token') %></p> | ||
|
||
<%= otp_authenticator_token_image(resource) %> | ||
|
||
<p> | ||
<strong><%= I18n.t('manual_provisioning', :scope => 'devise.otp.token_secret') %>:</strong> | ||
<code><%= resource.otp_auth_secret %></code> | ||
</p> | ||
|
||
<p><%= I18n.t('step_2', :scope => 'devise.otp.edit_otp_token') %></p> | ||
|
||
<%= form_with(:url => [resource_name, :otp_token], :method => :put) do |f| %> | ||
|
||
<p> | ||
<%= f.label :confirmation_code, I18n.t('confirmation_code', :scope => 'devise.otp.edit_otp_token') %> | ||
<%= f.text_field :confirmation_code %> | ||
</p> | ||
|
||
<p><%= f.submit I18n.t('submit', :scope => 'devise.otp.edit_otp_token') %></p> | ||
|
||
<% 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 |
---|---|---|
@@ -1,21 +1,10 @@ | ||
<h2><%= I18n.t('title', :scope => 'devise.otp.otp_tokens') %></h2> | ||
<p><%= I18n.t('explain', :scope => 'devise.otp.otp_tokens') %></p> | ||
|
||
<%= form_for(resource, :as => resource_name, :url => [resource_name, :otp_token], :html => { :method => :put, "data-turbo" => false }) do |f| %> | ||
<%= render "devise/shared/error_messages", resource: resource %> | ||
|
||
<h3><%= I18n.t('enable_request', :scope => 'devise.otp.otp_tokens') %></h3> | ||
|
||
<p> | ||
<%= f.label :otp_enabled, I18n.t('status', :scope => 'devise.otp.otp_tokens') %><br /> | ||
<%= f.check_box :otp_enabled %> | ||
</p> | ||
|
||
<p><%= f.submit I18n.t('submit', :scope => 'devise.otp.otp_tokens') %></p> | ||
<% end %> | ||
<p><strong>Status:</strong> <%= resource.otp_enabled? ? "Enabled" : "Disabled" %></p> | ||
|
||
<%- if resource.otp_enabled? %> | ||
<%= render :partial => 'token_secret' if resource.otp_enabled? %> | ||
<%= render :partial => 'trusted_devices' if trusted_devices_enabled? %> | ||
<% else %> | ||
<%= link_to I18n.t('enable_link', :scope => 'devise.otp.otp_tokens'), edit_otp_token_path_for(resource) %> | ||
<% 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require "test_helper" | ||
require "integration_tests_helper" | ||
|
||
class EnableOtpFormTest < ActionDispatch::IntegrationTest | ||
def teardown | ||
Capybara.reset_sessions! | ||
end | ||
|
||
test "a user should be able enable their OTP authentication by entering a confirmation code" do | ||
user = sign_user_in | ||
|
||
visit edit_user_otp_token_path | ||
|
||
user.reload | ||
|
||
fill_in "confirmation_code", with: ROTP::TOTP.new(user.otp_auth_secret).at(Time.now) | ||
|
||
click_button "Continue..." | ||
|
||
assert_equal user_otp_token_path, current_path | ||
assert page.has_content?("Enabled") | ||
|
||
user.reload | ||
assert user.otp_enabled? | ||
end | ||
|
||
test "a user should not be able enable their OTP authentication with an incorrect confirmation code" do | ||
user = sign_user_in | ||
|
||
visit edit_user_otp_token_path | ||
|
||
fill_in "confirmation_code", with: "123456" | ||
|
||
click_button "Continue..." | ||
|
||
assert page.has_content?("To Enable Two-Factor Authentication") | ||
|
||
user.reload | ||
assert_not user.otp_enabled? | ||
end | ||
|
||
test "a user should not be able enable their OTP authentication with a blank confirmation code" do | ||
user = sign_user_in | ||
|
||
visit edit_user_otp_token_path | ||
|
||
fill_in "confirmation_code", with: "" | ||
|
||
click_button "Continue..." | ||
|
||
assert page.has_content?("To Enable Two-Factor Authentication") | ||
|
||
user.reload | ||
assert_not user.otp_enabled? | ||
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
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ def teardown | |
# disable OTP | ||
disable_otp | ||
|
||
assert page.has_content? "Disabled" | ||
|
||
# logout | ||
sign_out | ||
|
||
|
Oops, something went wrong.