Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-25 15:07:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-25 15:07:45 +0300
commit7b1fa4c1a1b784c2f78405dca82e56a009f1e773 (patch)
treed56557b05ce90b8e4e20f514c835579a3c1e9d85 /spec/lib
parent06b4bed158fc0772cf4363e65baef9ca9357c07b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/api/entities/ml/mlflow/run_info_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/external/file/local_spec.rb73
-rw-r--r--spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb29
-rw-r--r--spec/lib/gitlab/ci/config/external/mapper_spec.rb11
-rw-r--r--spec/lib/gitlab/ci/config/external/processor_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb2
-rw-r--r--spec/lib/gitlab/utils_spec.rb20
7 files changed, 129 insertions, 16 deletions
diff --git a/spec/lib/api/entities/ml/mlflow/run_info_spec.rb b/spec/lib/api/entities/ml/mlflow/run_info_spec.rb
index db8f106c9fe..b64a1555332 100644
--- a/spec/lib/api/entities/ml/mlflow/run_info_spec.rb
+++ b/spec/lib/api/entities/ml/mlflow/run_info_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe API::Entities::Ml::Mlflow::RunInfo do
+RSpec.describe API::Entities::Ml::Mlflow::RunInfo, feature_category: :mlops do
let_it_be(:candidate) { create(:ml_candidates) }
subject { described_class.new(candidate, packages_url: 'http://example.com').as_json }
diff --git a/spec/lib/gitlab/ci/config/external/file/local_spec.rb b/spec/lib/gitlab/ci/config/external/file/local_spec.rb
index a77acb45978..cf1892d467c 100644
--- a/spec/lib/gitlab/ci/config/external/file/local_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/file/local_spec.rb
@@ -30,6 +30,60 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local, feature_category: :pip
.to receive(:check_execution_time!)
end
+ describe '.initialize' do
+ context 'when a local is specified' do
+ let(:params) { { local: 'file' } }
+
+ it 'sets the location' do
+ expect(local_file.location).to eq('file')
+ end
+
+ context 'when the local is prefixed with a slash' do
+ let(:params) { { local: '/file' } }
+
+ it 'removes the slash' do
+ expect(local_file.location).to eq('file')
+ end
+
+ context 'when the FF ci_batch_request_for_local_and_project_includes is disabled' do
+ before do
+ stub_feature_flags(ci_batch_request_for_local_and_project_includes: false)
+ end
+
+ it 'does not remove the slash' do
+ expect(local_file.location).to eq('/file')
+ end
+ end
+ end
+
+ context 'when the local is prefixed with multiple slashes' do
+ let(:params) { { local: '//file' } }
+
+ it 'removes slashes' do
+ expect(local_file.location).to eq('file')
+ end
+
+ context 'when the FF ci_batch_request_for_local_and_project_includes is disabled' do
+ before do
+ stub_feature_flags(ci_batch_request_for_local_and_project_includes: false)
+ end
+
+ it 'does not remove slashes' do
+ expect(local_file.location).to eq('//file')
+ end
+ end
+ end
+ end
+
+ context 'with a missing local' do
+ let(:params) { { local: nil } }
+
+ it 'sets the location to an empty string' do
+ expect(local_file.location).to eq('')
+ end
+ end
+ end
+
describe '#matching?' do
context 'when a local is specified' do
let(:params) { { local: 'file' } }
@@ -91,7 +145,7 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local, feature_category: :pip
it 'returns false and adds an error message about an empty file' do
allow_any_instance_of(described_class).to receive(:fetch_local_content).and_return("")
local_file.validate!
- expect(local_file.errors).to include("Local file `/lib/gitlab/ci/templates/xxxxxx/existent-file.yml` is empty!")
+ expect(local_file.errors).to include("Local file `lib/gitlab/ci/templates/xxxxxx/existent-file.yml` is empty!")
end
end
@@ -101,7 +155,18 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local, feature_category: :pip
it 'returns false and adds an error message stating that included file does not exist' do
expect(valid?).to be_falsy
- expect(local_file.errors).to include("Sha #{sha} is not valid!")
+ expect(local_file.errors).to include("Local file `lib/gitlab/ci/templates/existent-file.yml` does not exist!")
+ end
+
+ context 'when the FF ci_batch_request_for_local_and_project_includes is disabled' do
+ before do
+ stub_feature_flags(ci_batch_request_for_local_and_project_includes: false)
+ end
+
+ it 'returns false and adds an error message stating that sha does not exist' do
+ expect(valid?).to be_falsy
+ expect(local_file.errors).to include("Sha #{sha} is not valid!")
+ end
end
end
end
@@ -147,7 +212,7 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local, feature_category: :pip
end
it 'returns an error message' do
- expect(local_file.error_message).to eq("Local file `/lib/gitlab/ci/templates/xxxxxxxxxxx.yml` does not exist!")
+ expect(local_file.error_message).to eq("Local file `lib/gitlab/ci/templates/xxxxxxxxxxx.yml` does not exist!")
end
end
@@ -203,7 +268,7 @@ RSpec.describe Gitlab::Ci::Config::External::File::Local, feature_category: :pip
context_project: project.full_path,
context_sha: sha,
type: :local,
- location: '/lib/gitlab/ci/templates/existent-file.yml',
+ location: 'lib/gitlab/ci/templates/existent-file.yml',
blob: "http://localhost/#{project.full_path}/-/blob/#{sha}/lib/gitlab/ci/templates/existent-file.yml",
raw: "http://localhost/#{project.full_path}/-/raw/#{sha}/lib/gitlab/ci/templates/existent-file.yml",
extra: {}
diff --git a/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb b/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb
index 7c7252c6b0e..fa67b134406 100644
--- a/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb
@@ -25,6 +25,10 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper::Verifier, feature_category:
my_test:
script: echo Hello World
YAML
+ 'myfolder/file3.yml' => <<~YAML,
+ my_deploy:
+ script: echo Hello World
+ YAML
'nested_configs.yml' => <<~YAML
include:
- local: myfolder/file1.yml
@@ -58,16 +62,35 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper::Verifier, feature_category:
let(:files) do
[
Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file1.yml' }, context),
- Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file2.yml' }, context)
+ Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file2.yml' }, context),
+ Gitlab::Ci::Config::External::File::Local.new({ local: 'myfolder/file3.yml' }, context)
]
end
it 'returns an array of file objects' do
- expect(process.map(&:location)).to contain_exactly('myfolder/file1.yml', 'myfolder/file2.yml')
+ expect(process.map(&:location)).to contain_exactly(
+ 'myfolder/file1.yml', 'myfolder/file2.yml', 'myfolder/file3.yml'
+ )
end
it 'adds files to the expandset' do
- expect { process }.to change { context.expandset.count }.by(2)
+ expect { process }.to change { context.expandset.count }.by(3)
+ end
+
+ it 'calls Gitaly only once for all files', :request_store do
+ # 1 for project.commit.id, 1 for the files
+ expect { process }.to change { Gitlab::GitalyClient.get_request_count }.by(2)
+ end
+
+ context 'when the FF ci_batch_request_for_local_and_project_includes is disabled' do
+ before do
+ stub_feature_flags(ci_batch_request_for_local_and_project_includes: false)
+ end
+
+ it 'calls Gitaly for each file', :request_store do
+ # 1 for project.commit.id, 3 for the files
+ expect { process }.to change { Gitlab::GitalyClient.get_request_count }.by(4)
+ end
end
end
diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
index 9d0e57d4292..b397bfa38ee 100644
--- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb
@@ -2,8 +2,7 @@
require 'spec_helper'
-# This will be use with the FF ci_refactoring_external_mapper_verifier in the next MR.
-# It can be removed when the FF is removed.
+# This will be moved from a `shared_context` to a `describe` once every feature flag is removed.
RSpec.shared_context 'gitlab_ci_config_external_mapper' do
include StubRequests
include RepoHelpers
@@ -467,4 +466,12 @@ end
RSpec.describe Gitlab::Ci::Config::External::Mapper, feature_category: :pipeline_authoring do
it_behaves_like 'gitlab_ci_config_external_mapper'
+
+ context 'when the FF ci_batch_request_for_local_and_project_includes is disabled' do
+ before do
+ stub_feature_flags(ci_batch_request_for_local_and_project_includes: false)
+ end
+
+ it_behaves_like 'gitlab_ci_config_external_mapper'
+ end
end
diff --git a/spec/lib/gitlab/ci/config/external/processor_spec.rb b/spec/lib/gitlab/ci/config/external/processor_spec.rb
index c9efaf2e1af..e0080b252c6 100644
--- a/spec/lib/gitlab/ci/config/external/processor_spec.rb
+++ b/spec/lib/gitlab/ci/config/external/processor_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe Gitlab::Ci::Config::External::Processor, feature_category: :pipel
it 'raises an error' do
expect { processor.perform }.to raise_error(
described_class::IncludeError,
- "Local file `/lib/gitlab/ci/templates/non-existent-file.yml` does not exist!"
+ "Local file `lib/gitlab/ci/templates/non-existent-file.yml` does not exist!"
)
end
end
@@ -221,7 +221,7 @@ RSpec.describe Gitlab::Ci::Config::External::Processor, feature_category: :pipel
it 'raises an error' do
expect { processor.perform }.to raise_error(
described_class::IncludeError,
- "Included file `/lib/gitlab/ci/templates/template.yml` does not have valid YAML syntax!"
+ "Included file `lib/gitlab/ci/templates/template.yml` does not have valid YAML syntax!"
)
end
end
@@ -313,7 +313,7 @@ RSpec.describe Gitlab::Ci::Config::External::Processor, feature_category: :pipel
expect(context.includes).to contain_exactly(
{ type: :local,
- location: '/local/file.yml',
+ location: 'local/file.yml',
blob: "http://localhost/#{project.full_path}/-/blob/#{sha}/local/file.yml",
raw: "http://localhost/#{project.full_path}/-/raw/#{sha}/local/file.yml",
extra: {},
@@ -341,7 +341,7 @@ RSpec.describe Gitlab::Ci::Config::External::Processor, feature_category: :pipel
context_project: project.full_path,
context_sha: sha },
{ type: :local,
- location: '/templates/my-build.yml',
+ location: 'templates/my-build.yml',
blob: "http://localhost/#{another_project.full_path}/-/blob/#{another_project.commit.sha}/templates/my-build.yml",
raw: "http://localhost/#{another_project.full_path}/-/raw/#{another_project.commit.sha}/templates/my-build.yml",
extra: {},
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index b9f65ff749d..360686ce65c 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -1503,7 +1503,7 @@ module Gitlab
end
context "when the included internal file is not present" do
- it_behaves_like 'returns errors', "Local file `/local.gitlab-ci.yml` does not exist!"
+ it_behaves_like 'returns errors', "Local file `local.gitlab-ci.yml` does not exist!"
end
end
end
diff --git a/spec/lib/gitlab/utils_spec.rb b/spec/lib/gitlab/utils_spec.rb
index 80b2ec63af9..102d608072b 100644
--- a/spec/lib/gitlab/utils_spec.rb
+++ b/spec/lib/gitlab/utils_spec.rb
@@ -7,7 +7,8 @@ RSpec.describe Gitlab::Utils do
delegate :to_boolean, :boolean_to_yes_no, :slugify, :which,
:ensure_array_from_string, :to_exclusive_sentence, :bytes_to_megabytes,
- :append_path, :check_path_traversal!, :allowlisted?, :check_allowed_absolute_path!, :decode_path, :ms_to_round_sec, :check_allowed_absolute_path_and_path_traversal!, to: :described_class
+ :append_path, :remove_leading_slashes, :check_path_traversal!, :allowlisted?, :check_allowed_absolute_path!,
+ :decode_path, :ms_to_round_sec, :check_allowed_absolute_path_and_path_traversal!, to: :described_class
describe '.check_path_traversal!' do
it 'detects path traversal in string without any separators' do
@@ -378,6 +379,23 @@ RSpec.describe Gitlab::Utils do
end
end
+ describe '.remove_leading_slashes' do
+ where(:str, :result) do
+ '/foo/bar' | 'foo/bar'
+ '//foo/bar' | 'foo/bar'
+ '/foo/bar/' | 'foo/bar/'
+ 'foo/bar' | 'foo/bar'
+ '' | ''
+ nil | ''
+ end
+
+ with_them do
+ it 'removes leading slashes' do
+ expect(remove_leading_slashes(str)).to eq(result)
+ end
+ end
+ end
+
describe '.ensure_utf8_size' do
context 'string is has less bytes than expected' do
it 'backfills string with null characters' do