Commit 28e80dbc authored by Mark Lapierre's avatar Mark Lapierre

Enable signing in as admin when adding a license

Adds the ability to use admin credentials to add a license so that when
testing an LDAP user on EE the LDAP user does not have to be an admin.

Admin credentials default to GDK's root user. Can be overriden via
ADMIN_USERNAME and ADMIN_PASSWORD environment variables.
parent 1cdab683
...@@ -78,13 +78,7 @@ If your user doesn't have permission to default sandbox group ...@@ -78,13 +78,7 @@ If your user doesn't have permission to default sandbox group
GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sandbox bin/qa Test::Instance::All https://gitlab.example.com GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sandbox bin/qa Test::Instance::All https://gitlab.example.com
``` ```
In addition, the `GITLAB_USER_TYPE` can be set to "ldap" to sign in as an LDAP user: All [supported environment variables are here](https://gitlab.com/gitlab-org/gitlab-qa/blob/master/docs/what_tests_can_be_run.md#supported-environment-variables).
```
GITLAB_USER_TYPE=ldap GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sandbox bin/qa Test::Instance::All https://gitlab.example.com
```
All [supported environment variables are here](https://gitlab.com/gitlab-org/gitlab-qa#supported-environment-variables).
### Building a Docker image to test ### Building a Docker image to test
......
...@@ -59,6 +59,19 @@ module QA ...@@ -59,6 +59,19 @@ module QA
Page::Menu::Main.act { has_personal_area? } Page::Menu::Main.act { has_personal_area? }
end end
def sign_in_using_admin_credentials
admin = QA::Factory::Resource::User.new.tap do |user|
user.username = QA::Runtime::User.admin_username
user.password = QA::Runtime::User.admin_password
end
using_wait_time 0 do
sign_in_using_gitlab_credentials(admin)
end
Page::Menu::Main.act { has_personal_area? }
end
def self.path def self.path
'/users/sign_in' '/users/sign_in'
end end
......
...@@ -3,8 +3,6 @@ module QA ...@@ -3,8 +3,6 @@ module QA
module Env module Env
extend self extend self
attr_writer :user_type
# set to 'false' to have Chrome run visibly instead of headless # set to 'false' to have Chrome run visibly instead of headless
def chrome_headless? def chrome_headless?
(ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i) != 0 (ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i) != 0
...@@ -19,18 +17,6 @@ module QA ...@@ -19,18 +17,6 @@ module QA
ENV['PERSONAL_ACCESS_TOKEN'] ENV['PERSONAL_ACCESS_TOKEN']
end end
# By default, "standard" denotes a standard GitLab user login.
# Set this to "ldap" if the user should be logged in via LDAP.
def user_type
return @user_type if defined?(@user_type) # rubocop:disable Gitlab/ModuleWithInstanceVariables
ENV.fetch('GITLAB_USER_TYPE', 'standard').tap do |type|
unless %w(ldap standard).include?(type)
raise ArgumentError.new("Invalid user type '#{type}': must be 'ldap' or 'standard'")
end
end
end
def user_username def user_username
ENV['GITLAB_USERNAME'] ENV['GITLAB_USERNAME']
end end
...@@ -39,6 +25,14 @@ module QA ...@@ -39,6 +25,14 @@ module QA
ENV['GITLAB_PASSWORD'] ENV['GITLAB_PASSWORD']
end end
def admin_username
ENV['GITLAB_ADMIN_USERNAME']
end
def admin_password
ENV['GITLAB_ADMIN_PASSWORD']
end
def forker? def forker?
forker_username && forker_password forker_username && forker_password
end end
......
...@@ -7,25 +7,37 @@ module QA ...@@ -7,25 +7,37 @@ module QA
'root' 'root'
end end
def default_password
'5iveL!fe'
end
def username def username
Runtime::Env.user_username || default_username Runtime::Env.user_username || default_username
end end
def password def password
Runtime::Env.user_password || '5iveL!fe' Runtime::Env.user_password || default_password
end end
def ldap_user? def ldap_user?
Runtime::Env.user_type == 'ldap' Runtime::Env.ldap_username && Runtime::Env.ldap_password
end end
def ldap_username def ldap_username
Runtime::Env.ldap_username || name Runtime::Env.ldap_username || username
end end
def ldap_password def ldap_password
Runtime::Env.ldap_password || password Runtime::Env.ldap_password || password
end end
def admin_username
Runtime::Env.admin_username || default_username
end
def admin_password
Runtime::Env.admin_password || default_password
end
end end
end end
end end
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
module QA module QA
context :manage, :orchestrated, :ldap do context :manage, :orchestrated, :ldap do
describe 'LDAP login' do describe 'LDAP login' do
before do
Runtime::Env.user_type = 'ldap'
end
it 'user logs into GitLab using LDAP credentials' do it 'user logs into GitLab using LDAP credentials' do
Runtime::Browser.visit(:gitlab, Page::Main::Login) Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials } Page::Main::Login.act { sign_in_using_credentials }
......
...@@ -56,27 +56,6 @@ describe QA::Runtime::Env do ...@@ -56,27 +56,6 @@ describe QA::Runtime::Env do
end end
end end
describe '.user_type' do
it 'returns standard if not defined' do
expect(described_class.user_type).to eq('standard')
end
it 'returns standard as defined' do
stub_env('GITLAB_USER_TYPE', 'standard')
expect(described_class.user_type).to eq('standard')
end
it 'returns ldap as defined' do
stub_env('GITLAB_USER_TYPE', 'ldap')
expect(described_class.user_type).to eq('ldap')
end
it 'returns an error if invalid user type' do
stub_env('GITLAB_USER_TYPE', 'foobar')
expect { described_class.user_type }.to raise_error(ArgumentError)
end
end
describe '.forker?' do describe '.forker?' do
it 'returns false if no forker credentials are defined' do it 'returns false if no forker credentials are defined' do
expect(described_class).not_to be_forker expect(described_class).not_to be_forker
......
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