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'
|
|
|
|
|
2017-06-30 12:36:36 -04:00
|
|
|
feature 'OAuth Login', js: true 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
|
|
|
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"))
|
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
|
|
|
Rails.application.env_config['devise.mapping'] = Devise.mappings[:user]
|
2017-06-30 12:36:36 -04:00
|
|
|
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[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 02:23:20 -04:00
|
|
|
:facebook, :cas3, :auth0]
|
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
|
|
|
|
|
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
|
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
|
|
|
|
stub_omniauth_config(provider)
|
|
|
|
user = create(:omniauth_user, extern_uid: 'my-uid', provider: provider.to_s)
|
|
|
|
login_via(provider.to_s, user, 'my-uid')
|
|
|
|
|
|
|
|
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
|
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
|
|
|
|
stub_omniauth_config(provider)
|
|
|
|
user = create(:omniauth_user, :two_factor, extern_uid: 'my-uid', provider: provider.to_s)
|
|
|
|
login_via(provider.to_s, user, 'my-uid')
|
|
|
|
|
|
|
|
enter_code(user.current_otp)
|
|
|
|
expect(current_path).to eq root_path
|
|
|
|
end
|
|
|
|
end
|
2017-06-15 00:40:47 -04:00
|
|
|
|
|
|
|
context 'when "remember me" is 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 'remembers the user after a browser restart' do
|
|
|
|
stub_omniauth_config(provider)
|
|
|
|
user = create(:omniauth_user, extern_uid: 'my-uid', provider: provider.to_s)
|
|
|
|
login_via(provider.to_s, user, 'my-uid', remember_me: true)
|
|
|
|
|
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
|
2017-06-15 00:40:47 -04:00
|
|
|
it 'remembers the user after a browser restart' do
|
|
|
|
stub_omniauth_config(provider)
|
|
|
|
user = create(:omniauth_user, :two_factor, extern_uid: 'my-uid', provider: provider.to_s)
|
|
|
|
login_via(provider.to_s, user, 'my-uid', remember_me: true)
|
|
|
|
enter_code(user.current_otp)
|
|
|
|
|
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
|
|
|
|
stub_omniauth_config(provider)
|
|
|
|
user = create(:omniauth_user, extern_uid: 'my-uid', provider: provider.to_s)
|
|
|
|
login_via(provider.to_s, user, 'my-uid', remember_me: false)
|
|
|
|
|
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
|
|
|
|
it 'does not remember the user after a browser restart' do
|
2017-06-15 00:40:47 -04:00
|
|
|
stub_omniauth_config(provider)
|
|
|
|
user = create(:omniauth_user, :two_factor, extern_uid: 'my-uid', provider: provider.to_s)
|
|
|
|
login_via(provider.to_s, user, 'my-uid', remember_me: false)
|
|
|
|
enter_code(user.current_otp)
|
|
|
|
|
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
|