summaryrefslogtreecommitdiff
path: root/spec/features/u2f_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/features/u2f_spec.rb')
-rw-r--r--spec/features/u2f_spec.rb99
1 files changed, 50 insertions, 49 deletions
diff --git a/spec/features/u2f_spec.rb b/spec/features/u2f_spec.rb
index a8d00bb8e5a..f3662cb184f 100644
--- a/spec/features/u2f_spec.rb
+++ b/spec/features/u2f_spec.rb
@@ -1,24 +1,23 @@
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) }
+feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do
+ before do
+ allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true)
+ end
def manage_two_factor_authentication
- click_on 'Manage Two-Factor Authentication'
- expect(page).to have_content("Setup New U2F Device")
- wait_for_ajax
+ click_on 'Manage two-factor authentication'
+ expect(page).to have_content("Setup new U2F device")
+ wait_for_requests
end
- def register_u2f_device(u2f_device = nil)
- name = FFaker::Name.first_name
+ def register_u2f_device(u2f_device = nil, name: 'My device')
u2f_device ||= FakeU2fDevice.new(page, name)
u2f_device.respond_to_u2f_registration
- click_on 'Setup New U2F Device'
+ click_on 'Setup new U2F device'
expect(page).to have_content('Your device was successfully set up')
fill_in "Pick a name", with: name
- click_on 'Register U2F Device'
+ click_on 'Register U2F device'
u2f_device
end
@@ -26,18 +25,20 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
let(:user) { create(:user) }
before do
- login_as(user)
+ gitlab_sign_in(user)
user.update_attribute(:otp_required_for_login, true)
end
describe 'when 2FA via OTP is disabled' do
- before { user.update_attribute(:otp_required_for_login, false) }
+ before do
+ user.update_attribute(:otp_required_for_login, false)
+ end
it 'does not allow registering a new device' do
visit profile_account_path
- click_on 'Enable Two-Factor Authentication'
+ click_on 'Enable two-factor authentication'
- expect(page).to have_button('Setup New U2F Device', disabled: true)
+ expect(page).to have_button('Setup new U2F device', disabled: true)
end
end
@@ -62,7 +63,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
expect(page).to have_content('Your U2F device was registered')
# Second device
- second_device = register_u2f_device
+ second_device = register_u2f_device(name: 'My other device')
expect(page).to have_content('Your U2F device was registered')
expect(page).to have_content(first_device.name)
@@ -76,7 +77,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
expect(page).to have_content("You've already enabled two-factor authentication using mobile")
first_u2f_device = register_u2f_device
- second_u2f_device = register_u2f_device
+ second_u2f_device = register_u2f_device(name: 'My other device')
click_on "Delete", match: :first
@@ -92,14 +93,14 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
manage_two_factor_authentication
u2f_device = register_u2f_device
expect(page).to have_content('Your U2F device was registered')
- logout
+ gitlab_sign_out
# Second user
- user = login_as(:user)
+ user = gitlab_sign_in(:user)
user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
- register_u2f_device(u2f_device)
+ register_u2f_device(u2f_device, name: 'My other device')
expect(page).to have_content('Your U2F device was registered')
expect(U2fRegistration.count).to eq(2)
@@ -112,9 +113,9 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
# Have the "u2f device" respond with bad data
page.execute_script("u2f.register = function(_,_,_,callback) { callback('bad response'); };")
- click_on 'Setup New U2F Device'
+ click_on 'Setup new U2F device'
expect(page).to have_content('Your device was successfully set up')
- click_on 'Register U2F Device'
+ click_on 'Register U2F device'
expect(U2fRegistration.count).to eq(0)
expect(page).to have_content("The form contains the following error")
@@ -127,9 +128,9 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
# Failed registration
page.execute_script("u2f.register = function(_,_,_,callback) { callback('bad response'); };")
- click_on 'Setup New U2F Device'
+ click_on 'Setup new U2F device'
expect(page).to have_content('Your device was successfully set up')
- click_on 'Register U2F Device'
+ click_on 'Register U2F device'
expect(page).to have_content("The form contains the following error")
# Successful registration
@@ -146,18 +147,18 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
before do
# Register and logout
- login_as(user)
+ gitlab_sign_in(user)
user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
@u2f_device = register_u2f_device
- logout
+ gitlab_sign_out
end
describe "when 2FA via OTP is disabled" do
it "allows logging in with the U2F device" do
user.update_attribute(:otp_required_for_login, false)
- login_with(user)
+ gitlab_sign_in(user)
@u2f_device.respond_to_u2f_authentication
@@ -169,7 +170,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
describe "when 2FA via OTP is enabled" do
it "allows logging in with the U2F device" do
user.update_attribute(:otp_required_for_login, true)
- login_with(user)
+ gitlab_sign_in(user)
@u2f_device.respond_to_u2f_authentication
@@ -179,7 +180,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
end
it 'persists remember_me value via hidden field' do
- login_with(user, remember: true)
+ gitlab_sign_in(user, remember: true)
@u2f_device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device')
@@ -194,15 +195,15 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
describe "but not the current user" do
it "does not allow logging in with that particular device" do
# Register current user with the different U2F device
- current_user = login_as(:user)
+ current_user = gitlab_sign_in(:user)
current_user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
- register_u2f_device
- logout
+ register_u2f_device(name: 'My other device')
+ gitlab_sign_out
# Try authenticating user with the old U2F device
- login_as(current_user)
+ gitlab_sign_in(current_user)
@u2f_device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device')
expect(page).to have_content('Authentication via U2F device failed')
@@ -212,15 +213,15 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
describe "and also the current user" do
it "allows logging in with that particular device" do
# Register current user with the same U2F device
- current_user = login_as(:user)
+ current_user = gitlab_sign_in(:user)
current_user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
register_u2f_device(@u2f_device)
- logout
+ gitlab_sign_out
# Try authenticating user with the same U2F device
- login_as(current_user)
+ gitlab_sign_in(current_user)
@u2f_device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device')
@@ -231,8 +232,8 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
describe "when a given U2F device has not been registered" do
it "does not allow logging in with that particular device" do
- unregistered_device = FakeU2fDevice.new(page, FFaker::Name.first_name)
- login_as(user)
+ unregistered_device = FakeU2fDevice.new(page, 'My device')
+ gitlab_sign_in(user)
unregistered_device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device')
@@ -243,7 +244,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
describe "when more than one device has been registered by the same user" do
it "allows logging in with either device" do
# Register first device
- user = login_as(:user)
+ user = gitlab_sign_in(:user)
user.update_attribute(:otp_required_for_login, true)
visit profile_two_factor_auth_path
expect(page).to have_content("Your U2F device needs to be set up.")
@@ -252,18 +253,18 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
# Register second device
visit profile_two_factor_auth_path
expect(page).to have_content("Your U2F device needs to be set up.")
- second_device = register_u2f_device
- logout
+ second_device = register_u2f_device(name: 'My other device')
+ gitlab_sign_out
# Authenticate as both devices
[first_device, second_device].each do |device|
- login_as(user)
+ gitlab_sign_in(user)
device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device')
expect(page).to have_css('.sign-out-link', visible: false)
- logout
+ gitlab_sign_out
end
end
end
@@ -272,7 +273,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
let(:user) { create(:user) }
before do
- user = login_as(:user)
+ user = gitlab_sign_in(:user)
user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
@@ -299,15 +300,15 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
before do
# Register and logout
- login_as(user)
+ gitlab_sign_in(user)
user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
end
describe 'when no u2f device is registered' do
before do
- logout
- login_with(user)
+ gitlab_sign_out
+ gitlab_sign_in(user)
end
it 'shows the fallback otp code UI' do
@@ -319,8 +320,8 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
before do
manage_two_factor_authentication
@u2f_device = register_u2f_device
- logout
- login_with(user)
+ gitlab_sign_out
+ gitlab_sign_in(user)
end
it 'provides a button that shows the fallback otp code UI' do