summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/deploy_tokens.rb8
-rw-r--r--spec/models/ci/build_spec.rb31
-rw-r--r--spec/models/project_spec.rb27
3 files changed, 66 insertions, 0 deletions
diff --git a/spec/factories/deploy_tokens.rb b/spec/factories/deploy_tokens.rb
index 5fea4a9d5a6..52ec588973a 100644
--- a/spec/factories/deploy_tokens.rb
+++ b/spec/factories/deploy_tokens.rb
@@ -10,5 +10,13 @@ FactoryBot.define do
trait :revoked do
revoked true
end
+
+ trait :gitlab_deploy_token do
+ name DeployToken::GITLAB_DEPLOY_TOKEN
+ end
+
+ trait :expired do
+ expires_at { Date.today - 1.month }
+ end
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index fcdc31c8984..b68297bfabc 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2035,6 +2035,37 @@ describe Ci::Build do
expect(build).not_to be_persisted
end
end
+
+ context 'for deploy tokens' do
+ let(:deploy_token) { create(:deploy_token, :gitlab_deploy_token) }
+
+ let(:deploy_token_variables) do
+ [
+ { key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN, public: true },
+ { key: 'CI_DEPLOY_PASSWORD', value: deploy_token.token, public: true }
+ ]
+ end
+
+ context 'when gitlab-deploy-token exist' 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
+ 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)
+ end
+ end
+ end
+ end
end
describe '#scoped_variables' do
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 2675c2f52c1..86ad80106af 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -3585,4 +3585,31 @@ describe Project do
it { is_expected.not_to be_valid }
end
end
+
+ describe '#gitlab_deploy_token' do
+ let(:project) { create(:project) }
+
+ subject { project.gitlab_deploy_token }
+
+ context 'when there is a gitlab deploy token associated' do
+ let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, projects: [project]) }
+
+ it { is_expected.to eq(deploy_token) }
+ end
+
+ context 'when there is no a gitlab deploy token associated' do
+ it { is_expected.to be_nil }
+ end
+
+ context 'when there is a gitlab deploy token associated but is has been revoked' do
+ let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :revoked, projects: [project]) }
+ it { is_expected.to be_nil }
+ end
+
+ context 'when there is a gitlab deploy token associated but it has expired' do
+ let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :expired, projects: [project]) }
+
+ it { is_expected.to be_nil }
+ end
+ end
end