summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Lapierre <mlapierre@gitlab.com>2018-12-27 07:54:15 -0500
committerMark Lapierre <mlapierre@gitlab.com>2018-12-27 07:54:15 -0500
commita4958020b4445a6231f5e7ea811dccb31175ff1b (patch)
tree3cf76c5d2de550d9c28f9042cd1580298a67d606
parent77909a88460bbc864a5f95f3fa66053eb6cab5a8 (diff)
downloadgitlab-ce-qa-allow-gitlab-qa-pat-env-var.tar.gz
Allow token env var from gitlab-qaqa-allow-gitlab-qa-pat-env-var
gitlab-qa accepts an env var named GITLAB_QA_ACCESS_TOKEN, but here we only accepted PERSONAL_ACCESS_TOKEN. This change allows either to be used.
-rw-r--r--qa/qa/runtime/env.rb2
-rw-r--r--qa/spec/runtime/env_spec.rb21
2 files changed, 22 insertions, 1 deletions
diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb
index dae5aa3f794..566db7a988d 100644
--- a/qa/qa/runtime/env.rb
+++ b/qa/qa/runtime/env.rb
@@ -53,7 +53,7 @@ module QA
# specifies token that can be used for the api
def personal_access_token
- @personal_access_token ||= ENV['PERSONAL_ACCESS_TOKEN']
+ @personal_access_token ||= ENV['PERSONAL_ACCESS_TOKEN'] || ENV['GITLAB_QA_ACCESS_TOKEN']
end
def user_username
diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb
index ded51d5bb7c..f3f6d13035f 100644
--- a/qa/spec/runtime/env_spec.rb
+++ b/qa/spec/runtime/env_spec.rb
@@ -100,6 +100,27 @@ describe QA::Runtime::Env do
end
end
+ context 'when GITLAB_QA_ACCESS_TOKEN is set' do
+ before do
+ stub_env('GITLAB_QA_ACCESS_TOKEN', 'a_token_too')
+ end
+
+ it 'returns specified token from env' do
+ expect(described_class.personal_access_token).to eq 'a_token_too'
+ end
+ end
+
+ context 'when both PERSONAL_ACCESS_TOKEN and GITLAB_QA_ACCESS_TOKEN are set' do
+ before do
+ stub_env('PERSONAL_ACCESS_TOKEN', 'a_token')
+ stub_env('GITLAB_QA_ACCESS_TOKEN', 'a_token_too')
+ end
+
+ it 'returns token specified by PERSONAL_ACCESS_TOKEN from env' do
+ expect(described_class.personal_access_token).to eq 'a_token'
+ end
+ end
+
context 'when @personal_access_token is set' do
before do
described_class.personal_access_token = 'another_token'