diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-14 18:13:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-14 18:13:32 +0300 |
commit | 1123408ec8922d4a6908ef4b85aa0ff4fbea08fe (patch) | |
tree | dfd95769ede53024da1b348176b589ba1fc4c801 /spec/lib/gitlab | |
parent | 2896c7471aa75a7842fe6318a122f83ca6c211bb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/ci/reports/security/finding_key_spec.rb | 61 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 38 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/repository_service_spec.rb | 10 |
4 files changed, 36 insertions, 78 deletions
diff --git a/spec/lib/gitlab/ci/reports/security/finding_key_spec.rb b/spec/lib/gitlab/ci/reports/security/finding_key_spec.rb index 784c1183320..2320f011cf5 100644 --- a/spec/lib/gitlab/ci/reports/security/finding_key_spec.rb +++ b/spec/lib/gitlab/ci/reports/security/finding_key_spec.rb @@ -6,36 +6,47 @@ RSpec.describe Gitlab::Ci::Reports::Security::FindingKey do using RSpec::Parameterized::TableSyntax describe '#==' do - where(:location_fp_1, :location_fp_2, :identifier_fp_1, :identifier_fp_2, :equals?) do - nil | 'different location fp' | 'identifier fp' | 'different identifier fp' | false - 'location fp' | nil | 'identifier fp' | 'different identifier fp' | false - 'location fp' | 'different location fp' | nil | 'different identifier fp' | false - 'location fp' | 'different location fp' | 'identifier fp' | nil | false - nil | nil | 'identifier fp' | 'identifier fp' | false - 'location fp' | 'location fp' | nil | nil | false - nil | nil | nil | nil | false - 'location fp' | 'different location fp' | 'identifier fp' | 'different identifier fp' | false - 'location fp' | 'different location fp' | 'identifier fp' | 'identifier fp' | false - 'location fp' | 'location fp' | 'identifier fp' | 'different identifier fp' | false - 'location fp' | 'location fp' | 'identifier fp' | 'identifier fp' | true - end - - with_them do - let(:finding_key_1) do - build(:ci_reports_security_finding_key, - location_fingerprint: location_fp_1, - identifier_fingerprint: identifier_fp_1) + context 'when the comparison is done between FindingKey instances' do + where(:location_fp_1, :location_fp_2, :identifier_fp_1, :identifier_fp_2, :equals?) do + nil | 'different location fp' | 'identifier fp' | 'different identifier fp' | false + 'location fp' | nil | 'identifier fp' | 'different identifier fp' | false + 'location fp' | 'different location fp' | nil | 'different identifier fp' | false + 'location fp' | 'different location fp' | 'identifier fp' | nil | false + nil | nil | 'identifier fp' | 'identifier fp' | false + 'location fp' | 'location fp' | nil | nil | false + nil | nil | nil | nil | false + 'location fp' | 'different location fp' | 'identifier fp' | 'different identifier fp' | false + 'location fp' | 'different location fp' | 'identifier fp' | 'identifier fp' | false + 'location fp' | 'location fp' | 'identifier fp' | 'different identifier fp' | false + 'location fp' | 'location fp' | 'identifier fp' | 'identifier fp' | true end - let(:finding_key_2) do - build(:ci_reports_security_finding_key, - location_fingerprint: location_fp_2, - identifier_fingerprint: identifier_fp_2) + with_them do + let(:finding_key_1) do + build(:ci_reports_security_finding_key, + location_fingerprint: location_fp_1, + identifier_fingerprint: identifier_fp_1) + end + + let(:finding_key_2) do + build(:ci_reports_security_finding_key, + location_fingerprint: location_fp_2, + identifier_fingerprint: identifier_fp_2) + end + + subject { finding_key_1 == finding_key_2 } + + it { is_expected.to be(equals?) } end + end + + context 'when the comparison is not done between FindingKey instances' do + let(:finding_key) { build(:ci_reports_security_finding_key) } + let(:uuid) { SecureRandom.uuid } - subject { finding_key_1 == finding_key_2 } + subject { finding_key == uuid } - it { is_expected.to be(equals?) } + it { is_expected.to be_falsey } end end end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index f1b6a59abf9..ae6ca728573 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -2252,44 +2252,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end end - describe '#clean_stale_repository_files' do - let(:worktree_id) { 'rebase-1' } - let(:gitlab_worktree_path) { File.join(repository_path, 'gitlab-worktree', worktree_id) } - let(:admin_dir) { File.join(repository_path, 'worktrees') } - - it 'cleans up the files' do - create_worktree = %W[git -C #{repository_path} worktree add --detach #{gitlab_worktree_path} master] - raise 'preparation failed' unless system(*create_worktree, err: '/dev/null') - - FileUtils.touch(gitlab_worktree_path, mtime: Time.now - 8.hours) - # git rev-list --all will fail in git 2.16 if HEAD is pointing to a non-existent object, - # but the HEAD must be 40 characters long or git will ignore it. - File.write(File.join(admin_dir, worktree_id, 'HEAD'), Gitlab::Git::BLANK_SHA) - - expect(rev_list_all).to be(false) - repository.clean_stale_repository_files - - expect(rev_list_all).to be(true) - expect(File.exist?(gitlab_worktree_path)).to be_falsey - end - - def rev_list_all - system(*%W[git -C #{repository_path} rev-list --all], out: '/dev/null', err: '/dev/null') - end - - it 'increments a counter upon an error' do - expect(repository.gitaly_repository_client).to receive(:cleanup).and_raise(Gitlab::Git::CommandError) - - counter = double(:counter) - - expect(counter).to receive(:increment) - expect(Gitlab::Metrics).to receive(:counter).with(:failed_repository_cleanup_total, - 'Number of failed repository cleanup events').and_return(counter) - - repository.clean_stale_repository_files - end - end - describe '#squash' do let(:branch_name) { 'fix' } let(:start_sha) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' } diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 4bf7994f4dd..d6ef1836ad9 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -1008,11 +1008,6 @@ RSpec.describe Gitlab::GitAccess do end end - it 'cleans up the files' do - expect(project.repository).to receive(:clean_stale_repository_files).and_call_original - expect { push_access_check }.not_to raise_error - end - it 'avoids N+1 queries', :request_store do # Run this once to establish a baseline. Cached queries should get # cached, so that when we introduce another change we shouldn't see diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index e5502a883b5..353726b56f6 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -21,16 +21,6 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do end end - describe '#cleanup' do - it 'sends a cleanup message' do - expect_any_instance_of(Gitaly::RepositoryService::Stub) - .to receive(:cleanup) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - - client.cleanup - end - end - describe '#garbage_collect' do it 'sends a garbage_collect message' do expect_any_instance_of(Gitaly::RepositoryService::Stub) |