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'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
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,
|
2017-07-06 23:25:18 -04:00
|
|
|
:facebook, :cas3, :auth0, :authentiq]
|
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
|
|
|
|
2017-06-19 03:55:09 -04:00
|
|
|
before(:all) do
|
2017-06-30 12:36:36 -04:00
|
|
|
# The OmniAuth `full_host` parameter doesn't get set correctly (it gets set to something like `http://localhost`
|
|
|
|
# here), and causes integration tests to fail with 404s. We set the `full_host` by removing the request path (and
|
|
|
|
# anything after it) from the request URI.
|
|
|
|
@omniauth_config_full_host = OmniAuth.config.full_host
|
2017-06-15 00:40:47 -04:00
|
|
|
OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(/#{request['REQUEST_PATH']}.*/, '') }
|
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-30 12:36:36 -04:00
|
|
|
after(:all) do
|
|
|
|
OmniAuth.config.full_host = @omniauth_config_full_host
|
|
|
|
end
|
|
|
|
|
2018-04-18 10:03:27 -04:00
|
|
|
def login_with_provider(provider, enter_two_factor: false)
|
|
|
|
login_via(provider.to_s, user, uid, remember_me: remember_me)
|
|
|
|
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) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_omniauth_config(provider)
|
|
|
|
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
|
2018-04-18 10:03:27 -04:00
|
|
|
login_with_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
|
|
|
|
|
|
|
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
|
2018-04-18 10:03:27 -04:00
|
|
|
login_with_provider(provider, 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
|
|
|
|
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
|
2018-04-18 10:03:27 -04:00
|
|
|
login_with_provider(provider)
|
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
|
2018-04-18 10:03:27 -04:00
|
|
|
login_with_provider(provider, enter_two_factor: true)
|
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
|
2018-04-18 10:03:27 -04:00
|
|
|
login_with_provider(provider)
|
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
|
2018-04-18 10:03:27 -04:00
|
|
|
login_with_provider(provider, enter_two_factor: true)
|
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
|