diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-17 09:08:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-17 09:08:14 +0300 |
commit | 213a83a3e346e3f805d3311eb6469fbf54ec58a4 (patch) | |
tree | 0384b27525521f928339b6edd6c16e1eeb95d15c /spec | |
parent | 40fb10f78e8f42631cc00ea87126782a3a79c5e6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/ci/jwt_v2_spec.rb | 74 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/project_config_spec.rb | 18 |
2 files changed, 89 insertions, 3 deletions
diff --git a/spec/lib/gitlab/ci/jwt_v2_spec.rb b/spec/lib/gitlab/ci/jwt_v2_spec.rb index 528be4b5da7..15be67329a8 100644 --- a/spec/lib/gitlab/ci/jwt_v2_spec.rb +++ b/spec/lib/gitlab/ci/jwt_v2_spec.rb @@ -111,6 +111,80 @@ RSpec.describe Gitlab::Ci::JwtV2, feature_category: :continuous_integration do expect(payload[:sha]).to eq(pipeline.sha) end end + + describe 'ci_config_ref_uri' do + let(:project_config) do + instance_double( + Gitlab::Ci::ProjectConfig, + url: 'gitlab.com/gitlab-org/gitlab//.gitlab-ci.yml', + source: :repository_source + ) + end + + before do + allow(Gitlab::Ci::ProjectConfig).to receive(:new).with( + project: project, + sha: pipeline.sha, + pipeline_source: pipeline.source.to_sym, + pipeline_source_bridge: pipeline.source_bridge + ).and_return(project_config) + end + + it 'joins project_config.url and pipeline.source_ref_path with @' do + expect(payload[:ci_config_ref_uri]).to eq('gitlab.com/gitlab-org/gitlab//.gitlab-ci.yml' \ + '@refs/heads/auto-deploy-2020-03-19') + end + + context 'when project config is nil' do + before do + allow(Gitlab::Ci::ProjectConfig).to receive(:new).and_return(nil) + end + + it 'is nil' do + expect(payload[:ci_config_ref_uri]).to be_nil + end + end + + context 'when ProjectConfig#url raises an error' do + before do + allow(project_config).to receive(:url).and_raise(RuntimeError) + end + + it 'raises the same error' do + expect { payload }.to raise_error(RuntimeError) + end + + context 'in production' do + before do + stub_rails_env('production') + end + + it 'is nil' do + expect(payload[:ci_config_ref_uri]).to be_nil + end + end + end + + context 'when ci_jwt_v2_ci_config_ref_uri_claim flag is disabled' do + before do + stub_feature_flags(ci_jwt_v2_ref_uri_claim: false) + end + + it 'is nil' do + expect(payload[:ci_config_ref_uri]).to be_nil + end + end + + context 'when config source is not repository' do + before do + allow(project_config).to receive(:source).and_return(:auto_devops_source) + end + + it 'is nil' do + expect(payload[:ci_config_ref_uri]).to be_nil + end + end + end end end end diff --git a/spec/lib/gitlab/ci/project_config_spec.rb b/spec/lib/gitlab/ci/project_config_spec.rb index c4b179c9ef5..13ef0939ddd 100644 --- a/spec/lib/gitlab/ci/project_config_spec.rb +++ b/spec/lib/gitlab/ci/project_config_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::ProjectConfig do - let(:project) { create(:project, :empty_repo, ci_config_path: ci_config_path) } +RSpec.describe Gitlab::Ci::ProjectConfig, feature_category: :pipeline_composition do + let_it_be(:project) { create(:project, :empty_repo) } let(:sha) { '123456' } let(:content) { nil } let(:source) { :push } @@ -14,9 +14,13 @@ RSpec.describe Gitlab::Ci::ProjectConfig do custom_content: content, pipeline_source: source, pipeline_source_bridge: bridge) end + before do + project.ci_config_path = ci_config_path + end + context 'when bridge job is passed in as parameter' do let(:ci_config_path) { nil } - let(:bridge) { create(:ci_bridge) } + let(:bridge) { build_stubbed(:ci_bridge) } before do allow(bridge).to receive(:yaml_for_downstream).and_return('the-yaml') @@ -25,6 +29,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns the content already available in command' do expect(config.source).to eq(:bridge_source) expect(config.content).to eq('the-yaml') + expect(config.url).to be_nil end end @@ -48,6 +53,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns root config including the local custom file' do expect(config.source).to eq(:repository_source) expect(config.content).to eq(config_content_result) + expect(config.url).to eq("localhost/#{project.full_path}//path/to/config.yml") end end @@ -64,6 +70,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns root config including the remote config' do expect(config.source).to eq(:remote_source) expect(config.content).to eq(config_content_result) + expect(config.url).to be_nil end end @@ -81,6 +88,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns root config including the path to another repository' do expect(config.source).to eq(:external_project_source) expect(config.content).to eq(config_content_result) + expect(config.url).to be_nil end context 'when path specifies a refname' do @@ -122,6 +130,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns root config including the canonical CI config file' do expect(config.source).to eq(:repository_source) expect(config.content).to eq(config_content_result) + expect(config.url).to eq("localhost/#{project.full_path}//.gitlab-ci.yml") end end @@ -142,6 +151,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns root config including the auto-devops template' do expect(config.source).to eq(:auto_devops_source) expect(config.content).to eq(config_content_result) + expect(config.url).to be_nil end end @@ -159,6 +169,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns the parameter content' do expect(config.source).to eq(:parameter_source) expect(config.content).to eq(content) + expect(config.url).to be_nil end end @@ -172,6 +183,7 @@ RSpec.describe Gitlab::Ci::ProjectConfig do it 'returns nil' do expect(config.source).to be_nil expect(config.content).to be_nil + expect(config.url).to be_nil end end end |