2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
describe 'OAuth Login', :js, :allow_forgery_protection do
|
2017-07-09 08:51:59 +00:00
|
|
|
include DeviseHelpers
|
|
|
|
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
def enter_code(code)
|
|
|
|
fill_in 'user_otp_attempt', with: code
|
|
|
|
click_button 'Verify code'
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_omniauth_config(provider)
|
2017-06-30 16:36:36 +00:00
|
|
|
OmniAuth.config.add_mock(provider, OmniAuth::AuthHash.new(provider: provider.to_s, uid: "12345"))
|
2018-01-09 16:47:31 +00:00
|
|
|
stub_omniauth_provider(provider)
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
end
|
|
|
|
|
2017-06-19 04:40:24 +00:00
|
|
|
providers = [:github, :twitter, :bitbucket, :gitlab, :google_oauth2,
|
2019-05-07 13:51:34 +00:00
|
|
|
:facebook, :cas3, :auth0, :authentiq, :salesforce]
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
|
2019-07-04 08:53:31 +00:00
|
|
|
around(:all) do |example|
|
|
|
|
with_omniauth_full_host { example.run }
|
2017-06-30 16:36:36 +00:00
|
|
|
end
|
|
|
|
|
2019-09-04 13:18:36 +00:00
|
|
|
def login_with_provider(provider, enter_two_factor: false, additional_info: {})
|
|
|
|
login_via(provider.to_s, user, uid, remember_me: remember_me, additional_info: additional_info)
|
2018-04-18 14:03:27 +00:00
|
|
|
enter_code(user.current_otp) if enter_two_factor
|
|
|
|
end
|
|
|
|
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
providers.each do |provider|
|
|
|
|
context "when the user logs in using the #{provider} provider" do
|
2018-04-18 14:03:27 +00:00
|
|
|
let(:uid) { 'my-uid' }
|
|
|
|
let(:remember_me) { false }
|
|
|
|
let(:user) { create(:omniauth_user, extern_uid: uid, provider: provider.to_s) }
|
|
|
|
let(:two_factor_user) { create(:omniauth_user, :two_factor, extern_uid: uid, provider: provider.to_s) }
|
2019-12-17 18:07:48 +00:00
|
|
|
|
2019-09-04 13:18:36 +00:00
|
|
|
provider == :salesforce ? let(:additional_info) { { extra: { email_verified: true } } } : let(:additional_info) { {} }
|
2018-04-18 14:03:27 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_omniauth_config(provider)
|
2019-07-26 07:05:50 +00:00
|
|
|
expect(ActiveSession).to receive(:cleanup).with(user).at_least(:once).and_call_original
|
2018-04-18 14:03:27 +00:00
|
|
|
end
|
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
context 'when two-factor authentication is disabled' do
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
it 'logs the user in' do
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, additional_info: additional_info)
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
context 'when two-factor authentication is enabled' do
|
2018-04-18 14:03:27 +00:00
|
|
|
let(:user) { two_factor_user }
|
|
|
|
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
it 'logs the user in' do
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, additional_info: additional_info, enter_two_factor: true)
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
2019-08-27 03:46:32 +00:00
|
|
|
|
|
|
|
it 'when bypass-two-factor is enabled' do
|
|
|
|
allow(Gitlab.config.omniauth).to receive_messages(allow_bypass_two_factor: true)
|
2019-09-04 13:18:36 +00:00
|
|
|
login_via(provider.to_s, user, uid, remember_me: false, additional_info: additional_info)
|
2019-08-27 03:46:32 +00:00
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'when bypass-two-factor is disabled' do
|
|
|
|
allow(Gitlab.config.omniauth).to receive_messages(allow_bypass_two_factor: false)
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, enter_two_factor: true, additional_info: additional_info)
|
2019-08-27 03:46:32 +00:00
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
end
|
2017-06-15 04:40:47 +00:00
|
|
|
|
|
|
|
context 'when "remember me" is checked' do
|
2018-04-18 14:03:27 +00:00
|
|
|
let(:remember_me) { true }
|
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
context 'when two-factor authentication is disabled' do
|
2017-06-15 04:40:47 +00:00
|
|
|
it 'remembers the user after a browser restart' do
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, additional_info: additional_info)
|
2017-06-15 04:40:47 +00:00
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
clear_browser_session
|
2017-06-15 04:40:47 +00:00
|
|
|
|
|
|
|
visit(root_path)
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
context 'when two-factor authentication is enabled' do
|
2018-04-18 14:03:27 +00:00
|
|
|
let(:user) { two_factor_user }
|
|
|
|
|
2017-06-15 04:40:47 +00:00
|
|
|
it 'remembers the user after a browser restart' do
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, enter_two_factor: true, additional_info: additional_info)
|
2017-06-15 04:40:47 +00:00
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
clear_browser_session
|
2017-06-15 04:40:47 +00:00
|
|
|
|
|
|
|
visit(root_path)
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when "remember me" is not checked' do
|
2017-06-30 16:36:36 +00:00
|
|
|
context 'when two-factor authentication is disabled' do
|
2017-06-15 04:40:47 +00:00
|
|
|
it 'does not remember the user after a browser restart' do
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, additional_info: additional_info)
|
2017-06-15 04:40:47 +00:00
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
clear_browser_session
|
2017-06-15 04:40:47 +00:00
|
|
|
|
|
|
|
visit(root_path)
|
|
|
|
expect(current_path).to eq new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
context 'when two-factor authentication is enabled' do
|
2018-04-18 14:03:27 +00:00
|
|
|
let(:user) { two_factor_user }
|
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
it 'does not remember the user after a browser restart' do
|
2019-09-04 13:18:36 +00:00
|
|
|
login_with_provider(provider, enter_two_factor: true, additional_info: additional_info)
|
2017-06-15 04:40:47 +00:00
|
|
|
|
2017-06-30 16:36:36 +00:00
|
|
|
clear_browser_session
|
2017-06-15 04:40:47 +00:00
|
|
|
|
|
|
|
visit(root_path)
|
|
|
|
expect(current_path).to eq new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
Add integration tests around OAuth login.
- There was previously a test for `saml` login in `login_spec`, but this didn't
seem to be passing. A lot of things didn't seem right here, and I suspect that
this test hasn't been running. I'll investigate this further.
- It took almost a whole working day to figure out this line:
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') }
As always, it's obvious in retrospect, but it took some digging to figure out
tests were failing and returning 404s during the callback phase.
- Test all OAuth providers - github, twitter, bitbucket, gitlab, google, and facebook
2017-06-14 04:30:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|