diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-18 20:25:57 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-20 20:18:41 +0300 |
commit | 0dd6d25c251beffca510094281ac8403fad6d8d0 (patch) | |
tree | f84dc38b75693dc3752c3f2297c34566bd84ba2d | |
parent | f17e83653d9befc02ac0cbfe39a5e2be62cb40ef (diff) |
Rename special deploy token to make it more descriptive
Also:
- Includes more specs
- Improves a bit the documentation
-rw-r--r-- | app/models/ci/build.rb | 2 | ||||
-rw-r--r-- | app/models/deploy_token.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | doc/ci/variables/README.md | 6 | ||||
-rw-r--r-- | spec/factories/deploy_tokens.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 6 |
7 files changed, 18 insertions, 14 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 2a652b01313..f3972e0cd26 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -657,7 +657,7 @@ module Ci def deploy_token_variables Gitlab::Ci::Variables::Collection.new.tap do |variables| - variables.append(key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN) + variables.append(key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN_NAME) variables.append(key: 'CI_DEPLOY_PASSWORD', value: project.gitlab_deploy_token.token) end end diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb index 191f07c527f..4e450d0bdc8 100644 --- a/app/models/deploy_token.rb +++ b/app/models/deploy_token.rb @@ -4,7 +4,7 @@ class DeployToken < ActiveRecord::Base add_authentication_token_field :token AVAILABLE_SCOPES = %i(read_repository read_registry).freeze - GITLAB_DEPLOY_TOKEN = 'gitlab-deploy-token'.freeze + GITLAB_DEPLOY_TOKEN_NAME = 'gitlab-deploy-token'.freeze default_value_for(:expires_at) { Forever.date } diff --git a/app/models/project.rb b/app/models/project.rb index a594f2df662..2684a02caba 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1881,7 +1881,7 @@ class Project < ActiveRecord::Base def gitlab_deploy_token @gitlab_deploy_token ||= - deploy_tokens.active.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN) + deploy_tokens.active.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME) end private diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md index 7338b61fe8b..117918bec50 100644 --- a/doc/ci/variables/README.md +++ b/doc/ci/variables/README.md @@ -87,8 +87,8 @@ future GitLab releases.** | **GITLAB_USER_LOGIN** | 10.0 | all | The login username of the user who started the job | | **GITLAB_USER_NAME** | 10.0 | all | The real name of the user who started the job | | **RESTORE_CACHE_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to restore the cache running a job | -| **CI_DEPLOY_USER** | 10.8 | all | Name of the GitLab Deploy Token. Only present if the Project has a [GitLab Deploy Token][gitlab-deploy-token] related.| -| **CI_DEPLOY_PASSWORD** | 10.8 | all | Token of the Gitlab Deploy Token. Only present if the Project has a [GitLab Deploy Token][gitlab-deploy-token] related.| +| **CI_DEPLOY_USER** | 10.8 | all | Authentication username of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.| +| **CI_DEPLOY_PASSWORD** | 10.8 | all | Authentication password of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.| ## 9.0 Renaming @@ -564,4 +564,4 @@ These variables are also not supported in a contex of a [subgroups]: ../../user/group/subgroups/index.md [builds-policies]: ../yaml/README.md#only-and-except-complex [dynamic-environments]: ../environments.md#dynamic-environments -[gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md +[gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md#gitlab-deploy-token diff --git a/spec/factories/deploy_tokens.rb b/spec/factories/deploy_tokens.rb index 52ec588973a..017e866e69c 100644 --- a/spec/factories/deploy_tokens.rb +++ b/spec/factories/deploy_tokens.rb @@ -12,7 +12,7 @@ FactoryBot.define do end trait :gitlab_deploy_token do - name DeployToken::GITLAB_DEPLOY_TOKEN + name DeployToken::GITLAB_DEPLOY_TOKEN_NAME end trait :expired do diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index b68297bfabc..e70f5b26440 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2041,27 +2041,25 @@ describe Ci::Build do let(:deploy_token_variables) do [ - { key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN, public: true }, + { key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN_NAME, public: true }, { key: 'CI_DEPLOY_PASSWORD', value: deploy_token.token, public: true } ] end - context 'when gitlab-deploy-token exist' do + context 'when gitlab-deploy-token exists' do before do project.deploy_tokens << deploy_token end it 'should include deploy token variables' do - deploy_token_variables.each do |deploy_token_variable| - is_expected.to include(deploy_token_variable) - end + is_expected.to include(*deploy_token_variables) end end context 'when gitlab-deploy-token does not exist' do it 'should not include deploy token variables' do - deploy_token_variables.each do |deploy_token_variable| - is_expected.not_to include(deploy_token_variable) + %w(CI_DEPLOY_USER CI_DEPLOY_PASSWORD).each do |deploy_token_key| + expect(subject.find { |v| v[:key] == deploy_token_key}).to be_nil end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 86ad80106af..f8b2fbf7399 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -3611,5 +3611,11 @@ describe Project do it { is_expected.to be_nil } end + + context 'when there is a gitlab deploy token associated with a different name' do + let!(:deploy_token) { create(:deploy_token, projects: [project]) } + + it { is_expected.to be_nil } + end end end |