Fix U2fSpec
for PhantomJS versions > 2.
- We weren't explicilty waiting for the page to load while navigating to the "Manage two-factor authentication" page. This was probably incidentally working for PhantomJS 1.x versions.
This commit is contained in:
parent
65572b3b96
commit
2675c9d632
1 changed files with 20 additions and 12 deletions
|
@ -1,8 +1,16 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: true, js: true do
|
||||
include WaitForAjax
|
||||
|
||||
before { allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true) }
|
||||
|
||||
def manage_two_factor_authentication
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
expect(page).to have_content("Setup New U2F Device")
|
||||
wait_for_ajax
|
||||
end
|
||||
|
||||
def register_u2f_device(u2f_device = nil)
|
||||
u2f_device ||= FakeU2fDevice.new(page)
|
||||
u2f_device.respond_to_u2f_registration
|
||||
|
@ -34,7 +42,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
describe 'when 2FA via OTP is enabled' do
|
||||
it 'allows registering a new device' do
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
expect(page.body).to match("You've already enabled two-factor authentication using mobile")
|
||||
|
||||
register_u2f_device
|
||||
|
@ -46,15 +54,15 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
visit profile_account_path
|
||||
|
||||
# First device
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
register_u2f_device
|
||||
expect(page.body).to match('Your U2F device was registered')
|
||||
|
||||
# Second device
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
register_u2f_device
|
||||
expect(page.body).to match('Your U2F device was registered')
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
expect(page.body).to match('You have 2 U2F devices registered')
|
||||
end
|
||||
end
|
||||
|
@ -62,7 +70,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
it 'allows the same device to be registered for multiple users' do
|
||||
# First user
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
u2f_device = register_u2f_device
|
||||
expect(page.body).to match('Your U2F device was registered')
|
||||
logout
|
||||
|
@ -71,7 +79,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
user = login_as(:user)
|
||||
user.update_attribute(:otp_required_for_login, true)
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
register_u2f_device(u2f_device)
|
||||
expect(page.body).to match('Your U2F device was registered')
|
||||
|
||||
|
@ -81,7 +89,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
context "when there are form errors" do
|
||||
it "doesn't register the device if there are errors" do
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
|
||||
# Have the "u2f device" respond with bad data
|
||||
page.execute_script("u2f.register = function(_,_,_,callback) { callback('bad response'); };")
|
||||
|
@ -96,7 +104,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
|
||||
it "allows retrying registration" do
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
|
||||
# Failed registration
|
||||
page.execute_script("u2f.register = function(_,_,_,callback) { callback('bad response'); };")
|
||||
|
@ -122,7 +130,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
login_as(user)
|
||||
user.update_attribute(:otp_required_for_login, true)
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
@u2f_device = register_u2f_device
|
||||
logout
|
||||
end
|
||||
|
@ -161,7 +169,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
current_user = login_as(:user)
|
||||
current_user.update_attribute(:otp_required_for_login, true)
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
register_u2f_device
|
||||
logout
|
||||
|
||||
|
@ -182,7 +190,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
current_user = login_as(:user)
|
||||
current_user.update_attribute(:otp_required_for_login, true)
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
register_u2f_device(@u2f_device)
|
||||
logout
|
||||
|
||||
|
@ -248,7 +256,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
|
|||
user = login_as(:user)
|
||||
user.update_attribute(:otp_required_for_login, true)
|
||||
visit profile_account_path
|
||||
click_on 'Manage Two-Factor Authentication'
|
||||
manage_two_factor_authentication
|
||||
expect(page).to have_content("Your U2F device needs to be set up.")
|
||||
register_u2f_device
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue