Commit cc68b0df authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'sh-add-login-types-qa' into 'master'

GitLab QA: Add GITLAB_USER_TYPE to support different login types (e.g. standard, LDAP)

See merge request gitlab-org/gitlab-ce!17048
parents 3d153622 dc8cf732
......@@ -78,6 +78,12 @@ 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 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 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
......
......@@ -39,6 +39,14 @@ module QA
end
end
def sign_in_using_credentials
if Runtime::User.ldap_user?
sign_in_using_ldap_credentials
else
sign_in_using_gitlab_credentials
end
end
def sign_in_using_ldap_credentials
using_wait_time 0 do
set_initial_password_if_present
......@@ -51,7 +59,7 @@ module QA
end
end
def sign_in_using_credentials
def sign_in_using_gitlab_credentials
using_wait_time 0 do
set_initial_password_if_present
......
......@@ -17,6 +17,16 @@ module QA
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
(ENV['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
......
......@@ -10,6 +10,10 @@ module QA
def password
Runtime::Env.user_password || '5iveL!fe'
end
def ldap_user?
Runtime::Env.user_type == 'ldap'
end
end
end
end
......@@ -55,4 +55,25 @@ describe QA::Runtime::Env do
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
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