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

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
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:
```
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).
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).
### Building a Docker image to test
......
......@@ -59,6 +59,19 @@ def sign_in_using_credentials(user = nil)
Page::Menu::Main.act { has_personal_area? }
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
'/users/sign_in'
end
......
......@@ -3,8 +3,6 @@ module Runtime
module Env
extend self
attr_writer :user_type
# set to 'false' to have Chrome run visibly instead of headless
def chrome_headless?
(ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i) != 0
......@@ -19,18 +17,6 @@ def personal_access_token
ENV['PERSONAL_ACCESS_TOKEN']
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
ENV['GITLAB_USERNAME']
end
......@@ -39,6 +25,14 @@ def user_password
ENV['GITLAB_PASSWORD']
end
def admin_username
ENV['GITLAB_ADMIN_USERNAME']
end
def admin_password
ENV['GITLAB_ADMIN_PASSWORD']
end
def forker?
forker_username && forker_password
end
......
......@@ -7,25 +7,37 @@ def default_username
'root'
end
def default_password
'5iveL!fe'
end
def username
Runtime::Env.user_username || default_username
end
def password
Runtime::Env.user_password || '5iveL!fe'
Runtime::Env.user_password || default_password
end
def ldap_user?
Runtime::Env.user_type == 'ldap'
Runtime::Env.ldap_username && Runtime::Env.ldap_password
end
def ldap_username
Runtime::Env.ldap_username || name
Runtime::Env.ldap_username || username
end
def ldap_password
Runtime::Env.ldap_password || password
end
def admin_username
Runtime::Env.admin_username || default_username
end
def admin_password
Runtime::Env.admin_password || default_password
end
end
end
end
......@@ -3,10 +3,6 @@
module QA
context :manage, :orchestrated, :ldap do
describe 'LDAP login' do
before do
Runtime::Env.user_type = 'ldap'
end
it 'user logs into GitLab using LDAP credentials' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
......
......@@ -56,27 +56,6 @@
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
it 'returns false if no forker credentials are defined' do
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