summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-02-10 14:20:44 -0800
committerStan Hu <stanhu@gmail.com>2018-02-11 05:59:33 -0800
commitdc8cf732078dc03af52e4821683ea1c04946091e (patch)
treee650e989b486fc09dc1ab100087600f2206fcb92
parent498ade4801a822f8704390b10d178af9fe7987cb (diff)
downloadgitlab-ce-sh-add-login-types-qa.tar.gz
GitLab QA: Add GITLAB_USER_TYPE to support different login types (e.g. standard, LDAP)sh-add-login-types-qa
GITLAB_USERNAME and GITLAB_PASSWORD may be specified for an LDAP login, but QA scenarios may need to know which type it is in order to log in successfully.
-rw-r--r--qa/README.md6
-rw-r--r--qa/qa/page/main/login.rb10
-rw-r--r--qa/qa/runtime/env.rb10
-rw-r--r--qa/qa/runtime/user.rb4
-rw-r--r--qa/spec/runtime/env_spec.rb21
5 files changed, 50 insertions, 1 deletions
diff --git a/qa/README.md b/qa/README.md
index 44f3e262f4d..3a99a30d379 100644
--- a/qa/README.md
+++ b/qa/README.md
@@ -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
diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb
index fd49b27cb1a..a8a5601dbe6 100644
--- a/qa/qa/page/main/login.rb
+++ b/qa/qa/page/main/login.rb
@@ -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
diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb
index 115d5ee58d1..5401372e225 100644
--- a/qa/qa/runtime/env.rb
+++ b/qa/qa/runtime/env.rb
@@ -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
diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb
index 6b377f6b287..39e6adf9522 100644
--- a/qa/qa/runtime/user.rb
+++ b/qa/qa/runtime/user.rb
@@ -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
diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb
index 103573db6be..2b6365dbc41 100644
--- a/qa/spec/runtime/env_spec.rb
+++ b/qa/spec/runtime/env_spec.rb
@@ -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