Commit 20722281 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'qa-github-oauth-login-test-2' into 'master'

Add e2e QA test for logging in using Github OAuth

See merge request gitlab-org/gitlab-ce!24817
parents fec135cb e8f8adfe
......@@ -16,6 +16,13 @@ module AuthHelper
PROVIDERS_WITH_ICONS.include?(name.to_s)
end
def qa_class_for_provider(provider)
{
saml: 'qa-saml-login-button',
github: 'qa-github-login-button'
}[provider.to_sym]
end
def auth_providers
Gitlab::Auth::OAuth::Provider.providers
end
......
......@@ -5,7 +5,7 @@
.d-flex.justify-content-between.flex-wrap
- providers.each do |provider|
- has_icon = provider_has_icon?(provider)
= link_to omniauth_authorize_path(:user, provider), method: :post, class: 'btn d-flex align-items-center omniauth-btn text-left oauth-login qa-saml-login-button', id: "oauth-login-#{provider}" do
= link_to omniauth_authorize_path(:user, provider), method: :post, class: "btn d-flex align-items-center omniauth-btn text-left oauth-login #{qa_class_for_provider(provider)}", id: "oauth-login-#{provider}" do
- if has_icon
= provider_image_tag(provider)
%span
......
......@@ -99,6 +99,7 @@ module QA
autoload :LDAPNoTLS, 'qa/scenario/test/integration/ldap_no_tls'
autoload :LDAPTLS, 'qa/scenario/test/integration/ldap_tls'
autoload :InstanceSAML, 'qa/scenario/test/integration/instance_saml'
autoload :OAuth, 'qa/scenario/test/integration/oauth'
autoload :Kubernetes, 'qa/scenario/test/integration/kubernetes'
autoload :Mattermost, 'qa/scenario/test/integration/mattermost'
autoload :ObjectStorage, 'qa/scenario/test/integration/object_storage'
......@@ -342,6 +343,13 @@ module QA
autoload :Login, 'qa/vendor/saml_idp/page/login'
end
end
module Github
module Page
autoload :Base, 'qa/vendor/github/page/base'
autoload :Login, 'qa/vendor/github/page/login'
end
end
end
# Classes that provide support to other parts of the framework.
......
......@@ -31,8 +31,9 @@ module QA
element :register_tab
end
view 'app/views/devise/shared/_omniauth_box.html.haml' do
view 'app/helpers/auth_helper.rb' do
element :saml_login_button
element :github_login_button
end
view 'app/views/layouts/devise.html.haml' do
......@@ -132,6 +133,16 @@ module QA
click_element :standard_tab
end
def sign_in_with_github
set_initial_password_if_present
click_element :github_login_button
end
def sign_in_with_saml
set_initial_password_if_present
click_element :saml_login_button
end
private
def sign_in_using_ldap_credentials
......@@ -142,11 +153,6 @@ module QA
click_element :sign_in_button
end
def sign_in_with_saml
set_initial_password_if_present
click_element :saml_login_button
end
def sign_in_using_gitlab_credentials(user)
switch_to_sign_in_tab if has_sign_in_tab?
switch_to_standard_tab if has_standard_tab?
......
......@@ -100,6 +100,14 @@ module QA
ENV['GITLAB_ADMIN_PASSWORD']
end
def github_username
ENV['GITHUB_USERNAME']
end
def github_password
ENV['GITHUB_PASSWORD']
end
def forker?
!!(forker_username && forker_password)
end
......
# frozen_string_literal: true
module QA
module Scenario
module Test
module Integration
class OAuth < Test::Instance::All
tags :oauth
end
end
end
end
end
# frozen_string_literal: true
module QA
context 'Manage', :orchestrated, :oauth do
describe 'OAuth login' do
it 'User logs in to GitLab with GitHub OAuth' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_with_github)
Vendor::Github::Page::Login.perform(&:login)
expect(page).to have_content('Welcome to GitLab')
end
end
end
end
# frozen_string_literal: true
module QA
module Vendor
module Github
module Page
class Base
include Capybara::DSL
include Scenario::Actable
end
end
end
end
end
# frozen_string_literal: true
require 'capybara/dsl'
module QA
module Vendor
module Github
module Page
class Login < Page::Base
def login
fill_in 'login', with: QA::Runtime::Env.github_username
fill_in 'password', with: QA::Runtime::Env.github_password
click_on 'Sign in'
unless has_no_text?("Authorize GitLab-OAuth")
click_on 'Authorize gitlab-qa' if has_button?('Authorize gitlab-qa')
end
end
end
end
end
end
end
# frozen_string_literal: true
describe QA::Scenario::Test::Integration::OAuth do
context '#perform' do
it_behaves_like 'a QA scenario class' do
let(:tags) { [:oauth] }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment