diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/migrations/disable_job_token_scope_when_unused_spec.rb | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/migrations/disable_job_token_scope_when_unused_spec.rb')
-rw-r--r-- | spec/migrations/disable_job_token_scope_when_unused_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/migrations/disable_job_token_scope_when_unused_spec.rb b/spec/migrations/disable_job_token_scope_when_unused_spec.rb new file mode 100644 index 00000000000..d969c98aa0f --- /dev/null +++ b/spec/migrations/disable_job_token_scope_when_unused_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe DisableJobTokenScopeWhenUnused do + let(:ci_cd_settings) { table(:project_ci_cd_settings) } + let(:links) { table(:ci_job_token_project_scope_links) } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + + let(:namespace) { namespaces.create!(name: 'test', path: 'path', type: 'Group') } + + let(:project_with_used_scope) { projects.create!(namespace_id: namespace.id) } + let!(:used_scope_settings) { ci_cd_settings.create!(project_id: project_with_used_scope.id, job_token_scope_enabled: true) } + let(:target_project) { projects.create!(namespace_id: namespace.id) } + let!(:link) { links.create!(source_project_id: project_with_used_scope.id, target_project_id: target_project.id) } + + let(:project_with_unused_scope) { projects.create!(namespace_id: namespace.id) } + let!(:unused_scope_settings) { ci_cd_settings.create!(project_id: project_with_unused_scope.id, job_token_scope_enabled: true) } + + let(:project_with_disabled_scope) { projects.create!(namespace_id: namespace.id) } + let!(:disabled_scope_settings) { ci_cd_settings.create!(project_id: project_with_disabled_scope.id, job_token_scope_enabled: false) } + + describe '#up' do + it 'sets job_token_scope_enabled to false for projects not having job token scope configured' do + migrate! + + expect(unused_scope_settings.reload.job_token_scope_enabled).to be_falsey + end + + it 'keeps the scope enabled for projects that are using it' do + migrate! + + expect(used_scope_settings.reload.job_token_scope_enabled).to be_truthy + end + + it 'keeps the scope disabled for projects having it disabled' do + migrate! + + expect(disabled_scope_settings.reload.job_token_scope_enabled).to be_falsey + end + end +end |