2019-07-25 01:24:42 -04: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 00:30:07 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'OAuth Login', :js, :allow_forgery_protection do
|
2017-07-09 04:51:59 -04: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 00:30:07 -04: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 12:36:36 -04:00
|
|
|
OmniAuth.config.add_mock(provider, OmniAuth::AuthHash.new(provider: provider.to_s, uid: "12345"))
|
2018-01-09 11:47:31 -05: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 00:30:07 -04:00
|
|
|
end
|
|
|
|
|
2017-06-19 00:40:24 -04:00
|
|
|
providers = [:github, :twitter, :bitbucket, :gitlab, :google_oauth2,
|
2021-11-12 13:12:20 -05:00
|
|
|
:facebook, :cas3, :auth0, :authentiq, :salesforce, :dingtalk]
|
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 00:30:07 -04:00
|
|
|
|
2021-06-30 02:07:17 -04:00
|
|
|
around do |example|
|
2019-07-04 04:53:31 -04:00
|
|
|
with_omniauth_full_host { example.run }
|
2017-06-30 12:36:36 -04:00
|
|
|
end
|
|
|
|
|
2019-09-04 09:18:36 -04: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 10:03:27 -04: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 00:30:07 -04:00
|
|
|
providers.each do |provider|
|
|
|
|
context "when the user logs in using the #{provider} provider" do
|
2018-04-18 10:03:27 -04: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 13:07:48 -05:00
|
|
|
|
2019-09-04 09:18:36 -04:00
|
|
|
provider == :salesforce ? let(:additional_info) { { extra: { email_verified: true } } } : let(:additional_info) { {} }
|
2018-04-18 10:03:27 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_omniauth_config(provider)
|
2019-07-26 03:05:50 -04:00
|
|
|
expect(ActiveSession).to receive(:cleanup).with(user).at_least(:once).and_call_original
|
2018-04-18 10:03:27 -04:00
|
|
|
end
|
|
|
|
|
2017-06-30 12:36:36 -04: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 00:30:07 -04:00
|
|
|
it 'logs the user in' do
|
2019-09-04 09:18:36 -04: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 00:30:07 -04:00
|
|
|
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
context 'when two-factor authentication is enabled' do
|
2018-04-18 10:03:27 -04: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 00:30:07 -04:00
|
|
|
it 'logs the user in' do
|
2019-09-04 09:18:36 -04: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 00:30:07 -04:00
|
|
|
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
2019-08-26 23:46:32 -04:00
|
|
|
|
|
|
|
it 'when bypass-two-factor is enabled' do
|
|
|
|
allow(Gitlab.config.omniauth).to receive_messages(allow_bypass_two_factor: true)
|
2019-09-04 09:18:36 -04:00
|
|
|
login_via(provider.to_s, user, uid, remember_me: false, additional_info: additional_info)
|
2019-08-26 23:46:32 -04: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 09:18:36 -04:00
|
|
|
login_with_provider(provider, enter_two_factor: true, additional_info: additional_info)
|
2019-08-26 23:46:32 -04: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 00:30:07 -04:00
|
|
|
end
|
2017-06-15 00:40:47 -04:00
|
|
|
|
|
|
|
context 'when "remember me" is checked' do
|
2018-04-18 10:03:27 -04:00
|
|
|
let(:remember_me) { true }
|
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
context 'when two-factor authentication is disabled' do
|
2017-06-15 00:40:47 -04:00
|
|
|
it 'remembers the user after a browser restart' do
|
2019-09-04 09:18:36 -04:00
|
|
|
login_with_provider(provider, additional_info: additional_info)
|
2017-06-15 00:40:47 -04:00
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
clear_browser_session
|
2017-06-15 00:40:47 -04:00
|
|
|
|
|
|
|
visit(root_path)
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
context 'when two-factor authentication is enabled' do
|
2018-04-18 10:03:27 -04:00
|
|
|
let(:user) { two_factor_user }
|
|
|
|
|
2017-06-15 00:40:47 -04:00
|
|
|
it 'remembers the user after a browser restart' do
|
2019-09-04 09:18:36 -04:00
|
|
|
login_with_provider(provider, enter_two_factor: true, additional_info: additional_info)
|
2017-06-15 00:40:47 -04:00
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
clear_browser_session
|
2017-06-15 00:40:47 -04: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 12:36:36 -04:00
|
|
|
context 'when two-factor authentication is disabled' do
|
2017-06-15 00:40:47 -04:00
|
|
|
it 'does not remember the user after a browser restart' do
|
2019-09-04 09:18:36 -04:00
|
|
|
login_with_provider(provider, additional_info: additional_info)
|
2017-06-15 00:40:47 -04:00
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
clear_browser_session
|
2017-06-15 00:40:47 -04:00
|
|
|
|
|
|
|
visit(root_path)
|
|
|
|
expect(current_path).to eq new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
context 'when two-factor authentication is enabled' do
|
2018-04-18 10:03:27 -04:00
|
|
|
let(:user) { two_factor_user }
|
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
it 'does not remember the user after a browser restart' do
|
2019-09-04 09:18:36 -04:00
|
|
|
login_with_provider(provider, enter_two_factor: true, additional_info: additional_info)
|
2017-06-15 00:40:47 -04:00
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
clear_browser_session
|
2017-06-15 00:40:47 -04: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 00:30:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|