diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2017-06-14 04:30:07 +0000 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-07-06 06:30:05 +0000 |
commit | e936db963e2adb549533cfedcac6f342d7e5e32e (patch) | |
tree | b07c14d363bbbf175bc48518268f73a220afc0f1 /spec/features/oauth_login_spec.rb | |
parent | 633793cf47b8b02bffc65976cd97c21601661504 (diff) | |
download | gitlab-ce-e936db963e2adb549533cfedcac6f342d7e5e32e.tar.gz |
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
Diffstat (limited to 'spec/features/oauth_login_spec.rb')
-rw-r--r-- | spec/features/oauth_login_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/features/oauth_login_spec.rb b/spec/features/oauth_login_spec.rb new file mode 100644 index 00000000000..f960dacdcac --- /dev/null +++ b/spec/features/oauth_login_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +feature 'OAuth Login', feature: true, js: true do + def enter_code(code) + fill_in 'user_otp_attempt', with: code + click_button 'Verify code' + end + + def provider_config(provider) + OpenStruct.new(name: provider.to_s, app_id: 'app_id', app_secret: 'app_secret') + end + + def stub_omniauth_config(provider) + OmniAuth.config.add_mock(provider, OmniAuth::AuthHash.new({ provider: provider.to_s, uid: "12345" })) + Rails.application.env_config['devise.mapping'] = Devise.mappings[:user] + Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[provider] + end + + providers = [:github, :twitter, :bitbucket, :gitlab, :google_oauth2, :facebook] + + before do + OmniAuth.config.full_host = ->(request) { request['REQUEST_URI'].sub(request['REQUEST_PATH'], '') } + + messages = { + enabled: true, + allow_single_sign_on: providers.map(&:to_s), + providers: providers.map { |provider| provider_config(provider) } + } + + allow(Gitlab.config.omniauth).to receive_messages(messages) + end + + providers.each do |provider| + context "when the user logs in using the #{provider} provider" do + context "when two-factor authentication is disabled" do + 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 + save_screenshot + end + end + + context "when two-factor authentication is enabled" do + 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 + end + end +end |