forked from jeremyevans/rodauth
-
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.
Skip displaying links for disabled routes
- Loading branch information
1 parent
f1cfcbf
commit 067d83e
Showing
11 changed files
with
270 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,37 @@ | |
page.body.must_include "Password Authentication Passed: bar" | ||
end | ||
|
||
it "should not display confirm password link on login page if route is disabled" do | ||
route = "confirm-password" | ||
rodauth do | ||
enable :login, :confirm_password, :email_auth, :recovery_codes | ||
confirm_password_route { route } | ||
auto_add_recovery_codes? true | ||
after_login { auto_add_missing_recovery_codes } | ||
end | ||
roda do |r| | ||
r.rodauth | ||
r.root{view :content=>"Home"} | ||
end | ||
|
||
visit '/login' | ||
fill_in 'Login', with: '[email protected]' | ||
click_button 'Login' | ||
click_button 'Send Login Link Via Email' | ||
link = email_link(/(\/email-auth\?key=.+)$/) | ||
|
||
visit link | ||
click_button 'Login' | ||
|
||
visit '/multifactor-auth' | ||
click_on 'Enter Password' | ||
page.current_path.must_equal '/confirm-password' | ||
|
||
route = nil | ||
visit '/multifactor-auth' | ||
page.current_path.must_equal '/recovery-auth' | ||
end | ||
|
||
[:jwt, :json].each do |json| | ||
it "should support confirming passwords via #{json}" do | ||
rodauth do | ||
|
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 |
---|---|---|
|
@@ -99,6 +99,25 @@ | |
page.html.must_include("Logged In: [email protected]") | ||
end | ||
|
||
it "should not display create account link on login page if route is disabled" do | ||
route = 'create-account' | ||
rodauth do | ||
enable :create_account, :login | ||
create_account_route { route } | ||
end | ||
roda do |r| | ||
r.rodauth | ||
end | ||
|
||
visit '/login' | ||
click_on 'Create a New Account' | ||
page.current_path.must_equal '/create-account' | ||
|
||
route = nil | ||
visit '/login' | ||
page.html.wont_include "Create a New Account" | ||
end | ||
|
||
[:jwt, :json].each do |json| | ||
it "should support creating accounts via #{json}" do | ||
rodauth do | ||
|
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 |
---|---|---|
|
@@ -1679,6 +1679,94 @@ def reset_otp_last_use | |
page.html.must_include 'With OTP' | ||
end | ||
|
||
it "should not display links for routes that were disabled" do | ||
otp_auth_route = 'otp-auth' | ||
otp_setup_route = 'otp-setup' | ||
otp_disable_route = 'otp-disable' | ||
recovery_auth_route = 'recovery-auth' | ||
recovery_codes_route = 'recovery-codes' | ||
sms_request_route = 'sms-request' | ||
sms_setup_route = 'sms-setup' | ||
sms_disable_route = 'sms-disable' | ||
sms_message = nil | ||
rodauth do | ||
enable :login, :logout, :otp, :recovery_codes, :sms_codes | ||
auto_add_recovery_codes? true | ||
sms_send { |phone, msg| sms_message = msg } | ||
otp_auth_route { otp_auth_route } | ||
otp_setup_route { otp_setup_route } | ||
otp_disable_route { otp_disable_route } | ||
recovery_auth_route { recovery_auth_route } | ||
recovery_codes_route { recovery_codes_route } | ||
sms_request_route { sms_request_route } | ||
sms_setup_route { sms_setup_route } | ||
sms_disable_route { sms_disable_route } | ||
end | ||
roda do |r| | ||
r.rodauth | ||
r.get('auth-links') { rodauth.two_factor_auth_links.map { |link| link[1] }.to_s } | ||
r.get('setup-links') { rodauth.two_factor_setup_links.map { |link| link[1] }.to_s } | ||
r.get('remove-links') { rodauth.two_factor_remove_links.map { |link| link[1] }.to_s } | ||
r.root{view :content=>"Home"} | ||
end | ||
|
||
visit '/login' | ||
fill_in 'Login', :with=>"[email protected]" | ||
fill_in 'Password', :with=>"0123456789" | ||
click_on 'Login' | ||
page.find('#notice_flash').text.must_equal "You have been logged in" | ||
|
||
otp_setup_route = nil | ||
visit '/setup-links' | ||
page.html.must_equal '[]' | ||
|
||
otp_setup_route = 'otp-setup' | ||
visit '/multifactor-auth' | ||
secret = page.html.match(/Secret: ([a-z2-7]{#{secret_length}})/)[1] | ||
totp = ROTP::TOTP.new(secret) | ||
fill_in 'Password', :with=>'0123456789' | ||
fill_in 'Authentication Code', :with=>totp.now | ||
click_on 'Setup TOTP Authentication' | ||
page.find('#notice_flash').text.must_equal 'TOTP authentication is now setup' | ||
|
||
recovery_codes_route = nil | ||
sms_setup_route = nil | ||
visit '/setup-links' | ||
page.html.must_equal '[]' | ||
|
||
recovery_codes_route = 'recovery-codes' | ||
sms_setup_route = 'sms-setup' | ||
visit '/setup-links' | ||
page.html.must_equal '["/sms-setup", "/recovery-codes"]' | ||
|
||
visit '/sms-setup' | ||
fill_in 'Password', :with=>'0123456789' | ||
fill_in 'Phone Number', :with=>'(123) 456-7890' | ||
click_button 'Setup SMS Backup Number' | ||
page.find('#notice_flash').text.must_equal 'SMS authentication needs confirmation' | ||
sms_code = sms_message[/\d{12}\z/] | ||
fill_in 'SMS Code', :with=>sms_code | ||
click_button 'Confirm SMS Backup Number' | ||
page.find('#notice_flash').text.must_equal 'SMS authentication has been setup' | ||
|
||
visit '/auth-links' | ||
page.html.must_equal '["/otp-auth", "/sms-request", "/recovery-auth"]' | ||
|
||
otp_auth_route = nil | ||
recovery_auth_route = nil | ||
sms_request_route = nil | ||
visit '/auth-links' | ||
page.html.must_equal '[]' | ||
|
||
visit '/remove-links' | ||
page.html.must_equal '["/otp-disable", "/sms-disable"]' | ||
|
||
otp_disable_route = nil | ||
sms_disable_route = nil | ||
visit '/remove-links' | ||
page.html.must_equal '[]' | ||
end | ||
|
||
it "should allow using otp via internal requests" do | ||
rodauth do | ||
enable :login, :logout, :otp, :internal_request | ||
|
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 |
---|---|---|
|
@@ -300,6 +300,32 @@ def bcrypt_password.==(other) | |
page.find('#notice_flash').text.must_equal "Your account has been verified" | ||
end | ||
|
||
it "should not display verify account resend link on login page when route is disabled" do | ||
route = "verify-account-resend" | ||
rodauth do | ||
enable :login, :create_account, :verify_account | ||
verify_account_resend_route { route } | ||
end | ||
roda do |r| | ||
r.rodauth | ||
r.root{view :content=>"Home"} | ||
end | ||
|
||
visit '/create-account' | ||
fill_in 'Login', :with=>'[email protected]' | ||
click_button 'Create Account' | ||
page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account" | ||
page.current_path.must_equal '/' | ||
|
||
Mail::TestMailer.deliveries.clear | ||
visit '/login' | ||
page.html.must_include "Resend Verify Account Information" | ||
|
||
route = nil | ||
visit '/login' | ||
page.html.wont_include "Resend Verify Account Information" | ||
end | ||
|
||
[:jwt, :json].each do |json| | ||
it "should support verifying accounts via #{json}" do | ||
rodauth do | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#{rodauth.login_form_footer_links_heading} | ||
<ul class="rodauth-links rodauth-login-footer-links"> | ||
#{rodauth.login_form_footer_links.sort.map do |_, link, text| | ||
#{rodauth.login_form_footer_links.map do |_, link, text| | ||
"<li><a href=\"#{h link}\">#{h text}</a></li>" | ||
end.join("\n")} | ||
</ul> |
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,5 +1,5 @@ | ||
<ul class="rodauth-links rodauth-two-factor-auth-links"> | ||
#{rodauth.two_factor_auth_links.sort.map do |_, link, text| | ||
#{rodauth.two_factor_auth_links.map do |_, link, text| | ||
"<li><a href=\"#{h link}\">#{h text}</a></li>" | ||
end.join} | ||
</ul> |
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