diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-31 17:31:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-31 17:31:42 +0300 |
commit | d7fe9575a00f0e734977cc15a5af92e8674bb379 (patch) | |
tree | ecf120856d0d336ac38ca18d0d2c8b1a3a5ca1ee /spec/lib/gitlab | |
parent | 63a18ecf9b62aba2e0b8b739521c86cf9ce9c746 (diff) |
Add latest changes from gitlab-org/security/gitlab@16-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab')
10 files changed, 69 insertions, 371 deletions
diff --git a/spec/lib/gitlab/ci/decompressed_gzip_size_validator_spec.rb b/spec/lib/gitlab/ci/decompressed_gzip_size_validator_spec.rb index dad5bd2548b..6ca3f4d415e 100644 --- a/spec/lib/gitlab/ci/decompressed_gzip_size_validator_spec.rb +++ b/spec/lib/gitlab/ci/decompressed_gzip_size_validator_spec.rb @@ -105,16 +105,6 @@ RSpec.describe Gitlab::Ci::DecompressedGzipSizeValidator, feature_category: :imp end end - context 'when archive path has multiple hard links' do - before do - FileUtils.link(filepath, File.join(Dir.mktmpdir, 'hard_link')) - end - - it 'returns false' do - expect(subject).not_to be_valid - end - end - context 'when archive path is not a file' do let(:filepath) { Dir.mktmpdir } let(:filesize) { File.size(filepath) } diff --git a/spec/lib/gitlab/github_import/attachments_downloader_spec.rb b/spec/lib/gitlab/github_import/attachments_downloader_spec.rb index 086aa4be17e..84d6713efdb 100644 --- a/spec/lib/gitlab/github_import/attachments_downloader_spec.rb +++ b/spec/lib/gitlab/github_import/attachments_downloader_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::AttachmentsDownloader, feature_category: :importers do +RSpec.describe Gitlab::GithubImport::AttachmentsDownloader do subject(:downloader) { described_class.new(file_url) } let_it_be(:file_url) { 'https://example.com/avatar.png' } @@ -39,26 +39,6 @@ RSpec.describe Gitlab::GithubImport::AttachmentsDownloader, feature_category: :i end end - context 'when file shares multiple hard links' do - let(:tmpdir) { Dir.mktmpdir } - let(:hard_link) { File.join(tmpdir, 'hard_link') } - - before do - existing_file = File.join(tmpdir, 'file.txt') - FileUtils.touch(existing_file) - FileUtils.link(existing_file, hard_link) - allow(downloader).to receive(:filepath).and_return(hard_link) - end - - it 'raises expected exception' do - expect(Gitlab::Utils::FileInfo).to receive(:linked?).with(hard_link).and_call_original - expect { downloader.perform }.to raise_exception( - described_class::DownloadError, - 'Invalid downloaded file' - ) - end - end - context 'when filename is malicious' do let_it_be(:file_url) { 'https://example.com/ava%2F..%2Ftar.png' } diff --git a/spec/lib/gitlab/import_export/command_line_util_spec.rb b/spec/lib/gitlab/import_export/command_line_util_spec.rb index b2e047f5621..91cfab1688a 100644 --- a/spec/lib/gitlab/import_export/command_line_util_spec.rb +++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb @@ -5,16 +5,13 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importers do include ExportFileHelper + let(:path) { "#{Dir.tmpdir}/symlink_test" } + let(:archive) { 'spec/fixtures/symlink_export.tar.gz' } let(:shared) { Gitlab::ImportExport::Shared.new(nil) } - # Separate where files are written during this test by their kind, to avoid them interfering with each other: - # - `source_dir` Dir to compress files from. - # - `target_dir` Dir to decompress archived files into. - # - `archive_dir` Dir to write any archive files to. - let(:source_dir) { Dir.mktmpdir } - let(:target_dir) { Dir.mktmpdir } + let(:tmpdir) { Dir.mktmpdir } let(:archive_dir) { Dir.mktmpdir } - subject(:mock_class) do + subject do Class.new do include Gitlab::ImportExport::CommandLineUtil @@ -28,59 +25,38 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe end before do - FileUtils.mkdir_p(source_dir) + FileUtils.mkdir_p(path) end after do - FileUtils.rm_rf(source_dir) - FileUtils.rm_rf(target_dir) + FileUtils.rm_rf(path) FileUtils.rm_rf(archive_dir) + FileUtils.remove_entry(tmpdir) end shared_examples 'deletes symlinks' do |compression, decompression| it 'deletes the symlinks', :aggregate_failures do - Dir.mkdir("#{source_dir}/.git") - Dir.mkdir("#{source_dir}/folder") - FileUtils.touch("#{source_dir}/file.txt") - FileUtils.touch("#{source_dir}/folder/file.txt") - FileUtils.touch("#{source_dir}/.gitignore") - FileUtils.touch("#{source_dir}/.git/config") - File.symlink('file.txt', "#{source_dir}/.symlink") - File.symlink('file.txt', "#{source_dir}/.git/.symlink") - File.symlink('file.txt', "#{source_dir}/folder/.symlink") - archive_file = File.join(archive_dir, 'symlink_archive.tar.gz') - subject.public_send(compression, archive: archive_file, dir: source_dir) - subject.public_send(decompression, archive: archive_file, dir: target_dir) - - expect(File).to exist("#{target_dir}/file.txt") - expect(File).to exist("#{target_dir}/folder/file.txt") - expect(File).to exist("#{target_dir}/.gitignore") - expect(File).to exist("#{target_dir}/.git/config") - expect(File).not_to exist("#{target_dir}/.symlink") - expect(File).not_to exist("#{target_dir}/.git/.symlink") - expect(File).not_to exist("#{target_dir}/folder/.symlink") - end - end - - shared_examples 'handles shared hard links' do |compression, decompression| - let(:archive_file) { File.join(archive_dir, 'hard_link_archive.tar.gz') } - - subject(:decompress) { mock_class.public_send(decompression, archive: archive_file, dir: target_dir) } - - before do - Dir.mkdir("#{source_dir}/dir") - FileUtils.touch("#{source_dir}/file.txt") - FileUtils.touch("#{source_dir}/dir/.file.txt") - FileUtils.link("#{source_dir}/file.txt", "#{source_dir}/.hard_linked_file.txt") - - mock_class.public_send(compression, archive: archive_file, dir: source_dir) - end - - it 'raises an exception and deletes the extraction dir', :aggregate_failures do - expect(FileUtils).to receive(:remove_dir).with(target_dir).and_call_original - expect(Dir).to exist(target_dir) - expect { decompress }.to raise_error(described_class::HardLinkError) - expect(Dir).not_to exist(target_dir) + Dir.mkdir("#{tmpdir}/.git") + Dir.mkdir("#{tmpdir}/folder") + FileUtils.touch("#{tmpdir}/file.txt") + FileUtils.touch("#{tmpdir}/folder/file.txt") + FileUtils.touch("#{tmpdir}/.gitignore") + FileUtils.touch("#{tmpdir}/.git/config") + File.symlink('file.txt', "#{tmpdir}/.symlink") + File.symlink('file.txt', "#{tmpdir}/.git/.symlink") + File.symlink('file.txt', "#{tmpdir}/folder/.symlink") + archive = File.join(archive_dir, 'archive') + subject.public_send(compression, archive: archive, dir: tmpdir) + + subject.public_send(decompression, archive: archive, dir: archive_dir) + + expect(File.exist?("#{archive_dir}/file.txt")).to eq(true) + expect(File.exist?("#{archive_dir}/folder/file.txt")).to eq(true) + expect(File.exist?("#{archive_dir}/.gitignore")).to eq(true) + expect(File.exist?("#{archive_dir}/.git/config")).to eq(true) + expect(File.exist?("#{archive_dir}/.symlink")).to eq(false) + expect(File.exist?("#{archive_dir}/.git/.symlink")).to eq(false) + expect(File.exist?("#{archive_dir}/folder/.symlink")).to eq(false) end end @@ -236,8 +212,6 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe end describe '#gzip' do - let(:path) { source_dir } - it 'compresses specified file' do tempfile = Tempfile.new('test', path) filename = File.basename(tempfile.path) @@ -255,16 +229,14 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe end describe '#gunzip' do - let(:path) { source_dir } - it 'decompresses specified file' do filename = 'labels.ndjson.gz' gz_filepath = "spec/fixtures/bulk_imports/gz/#{filename}" - FileUtils.copy_file(gz_filepath, File.join(path, filename)) + FileUtils.copy_file(gz_filepath, File.join(tmpdir, filename)) - subject.gunzip(dir: path, filename: filename) + subject.gunzip(dir: tmpdir, filename: filename) - expect(File.exist?(File.join(path, 'labels.ndjson'))).to eq(true) + expect(File.exist?(File.join(tmpdir, 'labels.ndjson'))).to eq(true) end context 'when exception occurs' do @@ -278,7 +250,7 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe it 'archives a folder without compression' do archive_file = File.join(archive_dir, 'archive.tar') - result = subject.tar_cf(archive: archive_file, dir: source_dir) + result = subject.tar_cf(archive: archive_file, dir: tmpdir) expect(result).to eq(true) expect(File.exist?(archive_file)).to eq(true) @@ -298,35 +270,29 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil, feature_category: :importe end describe '#untar_zxf' do - let(:tar_archive_fixture) { 'spec/fixtures/symlink_export.tar.gz' } - it_behaves_like 'deletes symlinks', :tar_czf, :untar_zxf - it_behaves_like 'handles shared hard links', :tar_czf, :untar_zxf it 'has the right mask for project.json' do - subject.untar_zxf(archive: tar_archive_fixture, dir: target_dir) + subject.untar_zxf(archive: archive, dir: path) - expect(file_permissions("#{target_dir}/project.json")).to eq(0755) # originally 777 + expect(file_permissions("#{path}/project.json")).to eq(0755) # originally 777 end it 'has the right mask for uploads' do - subject.untar_zxf(archive: tar_archive_fixture, dir: target_dir) + subject.untar_zxf(archive: archive, dir: path) - expect(file_permissions("#{target_dir}/uploads")).to eq(0755) # originally 555 + expect(file_permissions("#{path}/uploads")).to eq(0755) # originally 555 end end describe '#untar_xf' do - let(:tar_archive_fixture) { 'spec/fixtures/symlink_export.tar.gz' } - it_behaves_like 'deletes symlinks', :tar_cf, :untar_xf - it_behaves_like 'handles shared hard links', :tar_cf, :untar_xf it 'extracts archive without decompression' do filename = 'archive.tar.gz' archive_file = File.join(archive_dir, 'archive.tar') - FileUtils.copy_file(tar_archive_fixture, File.join(archive_dir, filename)) + FileUtils.copy_file(archive, File.join(archive_dir, filename)) subject.gunzip(dir: archive_dir, filename: filename) result = subject.untar_xf(archive: archive_file, dir: archive_dir) diff --git a/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb b/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb index 8c5823edc51..a6cb74c3c9f 100644 --- a/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb +++ b/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator, feature_category: :importers do +RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator do let_it_be(:filepath) { File.join(Dir.tmpdir, 'decompressed_archive_size_validator_spec.gz') } before(:all) do @@ -121,7 +121,7 @@ RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator, feature_c context 'which archive path is a symlink' do let(:filepath) { File.join(Dir.tmpdir, 'symlink') } - let(:error_message) { 'Archive path is a symlink or hard link' } + let(:error_message) { 'Archive path is a symlink' } before do FileUtils.ln_s(filepath, filepath, force: true) @@ -132,19 +132,6 @@ RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator, feature_c end end - context 'when archive path shares multiple hard links' do - let(:filesize) { 32 } - let(:error_message) { 'Archive path is a symlink or hard link' } - - before do - FileUtils.link(filepath, File.join(Dir.mktmpdir, 'hard_link')) - end - - it 'returns false' do - expect(subject).not_to be_valid - end - end - context 'when archive path is not a file' do let(:filepath) { Dir.mktmpdir } let(:filesize) { File.size(filepath) } diff --git a/spec/lib/gitlab/import_export/file_importer_spec.rb b/spec/lib/gitlab/import_export/file_importer_spec.rb index aff11f7ac30..5a75631ec4d 100644 --- a/spec/lib/gitlab/import_export/file_importer_spec.rb +++ b/spec/lib/gitlab/import_export/file_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::ImportExport::FileImporter, feature_category: :importers do +RSpec.describe Gitlab::ImportExport::FileImporter do include ExportFileHelper let(:shared) { Gitlab::ImportExport::Shared.new(nil) } @@ -113,73 +113,28 @@ RSpec.describe Gitlab::ImportExport::FileImporter, feature_category: :importers end context 'error' do - subject(:import) { described_class.import(importable: build(:project), archive_file: '', shared: shared) } - before do allow_next_instance_of(described_class) do |instance| - allow(instance).to receive(:wait_for_archived_file).and_raise(StandardError, 'foo') + allow(instance).to receive(:wait_for_archived_file).and_raise(StandardError) end + described_class.import(importable: build(:project), archive_file: '', shared: shared) end it 'removes symlinks in root folder' do - import - expect(File.exist?(symlink_file)).to be false end it 'removes hidden symlinks in root folder' do - import - expect(File.exist?(hidden_symlink_file)).to be false end it 'removes symlinks in subfolders' do - import - expect(File.exist?(subfolder_symlink_file)).to be false end it 'does not remove a valid file' do - import - expect(File.exist?(valid_file)).to be true end - - it 'returns false and sets an error on shared' do - result = import - - expect(result).to eq(false) - expect(shared.errors.join).to eq('foo') - end - - context 'when files in the archive share hard links' do - let(:hard_link_file) { "#{shared.export_path}/hard_link_file.txt" } - - before do - FileUtils.link(valid_file, hard_link_file) - end - - it 'returns false and sets an error on shared' do - result = import - - expect(result).to eq(false) - expect(shared.errors.join).to eq('File shares hard link') - end - - it 'removes all files in export path' do - expect(Dir).to exist(shared.export_path) - expect(File).to exist(symlink_file) - expect(File).to exist(hard_link_file) - expect(File).to exist(valid_file) - - import - - expect(File).not_to exist(symlink_file) - expect(File).not_to exist(hard_link_file) - expect(File).not_to exist(valid_file) - expect(Dir).not_to exist(shared.export_path) - end - end end context 'when file exceeds acceptable decompressed size' do @@ -202,10 +157,8 @@ RSpec.describe Gitlab::ImportExport::FileImporter, feature_category: :importers allow(Gitlab::ImportExport::DecompressedArchiveSizeValidator).to receive(:max_bytes).and_return(1) end - it 'returns false and sets an error on shared' do - result = subject.import - - expect(result).to eq(false) + it 'returns false' do + expect(subject.import).to eq(false) expect(shared.errors.join).to eq('Decompressed archive size validation failed.') end end diff --git a/spec/lib/gitlab/import_export/json/ndjson_reader_spec.rb b/spec/lib/gitlab/import_export/json/ndjson_reader_spec.rb index 1f98a9efb7d..98afe01c08b 100644 --- a/spec/lib/gitlab/import_export/json/ndjson_reader_spec.rb +++ b/spec/lib/gitlab/import_export/json/ndjson_reader_spec.rb @@ -35,22 +35,16 @@ RSpec.describe Gitlab::ImportExport::Json::NdjsonReader, feature_category: :impo expect(subject).to eq(root_tree) end - context 'when project.json is symlink or hard link' do - using RSpec::Parameterized::TableSyntax + context 'when project.json is symlink' do + it 'raises error an error' do + Dir.mktmpdir do |tmpdir| + FileUtils.touch(File.join(tmpdir, 'passwd')) + File.symlink(File.join(tmpdir, 'passwd'), File.join(tmpdir, 'project.json')) - where(:link_method) { [:link, :symlink] } + ndjson_reader = described_class.new(tmpdir) - with_them do - it 'raises an error' do - Dir.mktmpdir do |tmpdir| - FileUtils.touch(File.join(tmpdir, 'passwd')) - FileUtils.send(link_method, File.join(tmpdir, 'passwd'), File.join(tmpdir, 'project.json')) - - ndjson_reader = described_class.new(tmpdir) - - expect { ndjson_reader.consume_attributes(importable_path) } - .to raise_error(Gitlab::ImportExport::Error, 'Invalid file') - end + expect { ndjson_reader.consume_attributes(importable_path) } + .to raise_error(Gitlab::ImportExport::Error, 'Invalid file') end end end @@ -103,24 +97,18 @@ RSpec.describe Gitlab::ImportExport::Json::NdjsonReader, feature_category: :impo end end - context 'when relation file is a symlink or hard link' do - using RSpec::Parameterized::TableSyntax - - where(:link_method) { [:link, :symlink] } - - with_them do - it 'yields nothing to the Enumerator' do - Dir.mktmpdir do |tmpdir| - Dir.mkdir(File.join(tmpdir, 'project')) - File.write(File.join(tmpdir, 'passwd'), "{}\n{}") - FileUtils.send(link_method, File.join(tmpdir, 'passwd'), File.join(tmpdir, 'project', 'issues.ndjson')) + context 'when relation file is a symlink' do + it 'yields nothing to the Enumerator' do + Dir.mktmpdir do |tmpdir| + Dir.mkdir(File.join(tmpdir, 'project')) + File.write(File.join(tmpdir, 'passwd'), "{}\n{}") + File.symlink(File.join(tmpdir, 'passwd'), File.join(tmpdir, 'project', 'issues.ndjson')) - ndjson_reader = described_class.new(tmpdir) + ndjson_reader = described_class.new(tmpdir) - result = ndjson_reader.consume_relation(importable_path, 'issues') + result = ndjson_reader.consume_relation(importable_path, 'issues') - expect(result.to_a).to eq([]) - end + expect(result.to_a).to eq([]) end end end diff --git a/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb b/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb index 2b9590da421..cb8ac088493 100644 --- a/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb +++ b/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb @@ -4,17 +4,15 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::RecursiveMergeFolders do describe '.merge' do - it 'merges folder and ignores symlinks and files that share hard links' do + it 'merge folder and ignore symlinks' do Dir.mktmpdir do |tmpdir| source = "#{tmpdir}/source" FileUtils.mkdir_p("#{source}/folder/folder") FileUtils.touch("#{source}/file1.txt") - FileUtils.touch("#{source}/file_that_shares_hard_links.txt") FileUtils.touch("#{source}/folder/file2.txt") FileUtils.touch("#{source}/folder/folder/file3.txt") FileUtils.ln_s("#{source}/file1.txt", "#{source}/symlink-file1.txt") FileUtils.ln_s("#{source}/folder", "#{source}/symlink-folder") - FileUtils.link("#{source}/file_that_shares_hard_links.txt", "#{source}/hard_link.txt") target = "#{tmpdir}/target" FileUtils.mkdir_p("#{target}/folder/folder") diff --git a/spec/lib/gitlab/pages/virtual_host_finder_spec.rb b/spec/lib/gitlab/pages/virtual_host_finder_spec.rb index 49eee772f8d..4b584a45503 100644 --- a/spec/lib/gitlab/pages/virtual_host_finder_spec.rb +++ b/spec/lib/gitlab/pages/virtual_host_finder_spec.rb @@ -9,10 +9,6 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do project.update_pages_deployment!(create(:pages_deployment, project: project)) end - before do - stub_pages_setting(host: 'example.com') - end - it 'returns nil when host is empty' do expect(described_class.new(nil).execute).to be_nil expect(described_class.new('').execute).to be_nil @@ -73,7 +69,7 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do end it 'returns the virual domain with no lookup_paths' do - virtual_domain = described_class.new("#{project.namespace.path}.example.com").execute + virtual_domain = described_class.new("#{project.namespace.path}.#{Settings.pages.host}").execute expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) expect(virtual_domain.cache_key).to match(/pages_domain_for_namespace_#{project.namespace.id}_/) @@ -86,7 +82,7 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do end it 'returns the virual domain with no lookup_paths' do - virtual_domain = described_class.new("#{project.namespace.path}.example.com".downcase).execute + virtual_domain = described_class.new("#{project.namespace.path}.#{Settings.pages.host}".downcase).execute expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) expect(virtual_domain.cache_key).to be_nil @@ -108,7 +104,7 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do end it 'returns the virual domain when there are pages deployed for the project' do - virtual_domain = described_class.new("#{project.namespace.path}.example.com").execute + virtual_domain = described_class.new("#{project.namespace.path}.#{Settings.pages.host}").execute expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) expect(virtual_domain.cache_key).to match(/pages_domain_for_namespace_#{project.namespace.id}_/) @@ -117,7 +113,7 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do end it 'finds domain with case-insensitive' do - virtual_domain = described_class.new("#{project.namespace.path}.Example.com").execute + virtual_domain = described_class.new("#{project.namespace.path}.#{Settings.pages.host.upcase}").execute expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) expect(virtual_domain.cache_key).to match(/pages_domain_for_namespace_#{project.namespace.id}_/) @@ -131,7 +127,7 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do end it 'returns the virual domain when there are pages deployed for the project' do - virtual_domain = described_class.new("#{project.namespace.path}.example.com").execute + virtual_domain = described_class.new("#{project.namespace.path}.#{Settings.pages.host}").execute expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) expect(virtual_domain.cache_key).to be_nil @@ -147,7 +143,7 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do project.project_setting.update!(pages_unique_domain: 'unique-domain') end - subject(:virtual_domain) { described_class.new('unique-domain.example.com').execute } + subject(:virtual_domain) { described_class.new("unique-domain.#{Settings.pages.host.upcase}").execute } context 'when pages unique domain is enabled' do before_all do @@ -175,19 +171,6 @@ RSpec.describe Gitlab::Pages::VirtualHostFinder, feature_category: :pages do expect(virtual_domain.lookup_paths.first.project_id).to eq(project.id) end - context 'when a project path conflicts with a unique domain' do - it 'prioritizes the unique domain project' do - group = create(:group, path: 'unique-domain') - other_project = build(:project, path: 'unique-domain.example.com', group: group) - other_project.save!(validate: false) - other_project.update_pages_deployment!(create(:pages_deployment, project: other_project)) - other_project.mark_pages_as_deployed - - expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) - expect(virtual_domain.lookup_paths.first.project_id).to eq(project.id) - end - end - context 'when :cache_pages_domain_api is disabled' do before do stub_feature_flags(cache_pages_domain_api: false) diff --git a/spec/lib/gitlab/plantuml_spec.rb b/spec/lib/gitlab/plantuml_spec.rb deleted file mode 100644 index c783dd66c48..00000000000 --- a/spec/lib/gitlab/plantuml_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe Gitlab::Plantuml, feature_category: :shared do - describe ".configure" do - subject { described_class.configure } - - let(:plantuml_url) { "http://plantuml.foo.bar" } - - before do - allow(Gitlab::CurrentSettings).to receive(:plantuml_url).and_return(plantuml_url) - end - - context "when PlantUML is enabled" do - before do - allow(Gitlab::CurrentSettings).to receive(:plantuml_enabled).and_return(true) - end - - it "configures the endpoint URL" do - expect(subject.url).to eq(plantuml_url) - end - - it "enables PNG support" do - expect(subject.png_enable).to be_truthy - end - - it "disables SVG support" do - expect(subject.svg_enable).to be_falsey - end - - it "disables TXT support" do - expect(subject.txt_enable).to be_falsey - end - end - - context "when PlantUML is disabled" do - before do - allow(Gitlab::CurrentSettings).to receive(:plantuml_enabled).and_return(false) - end - - it "configures the endpoint URL" do - expect(subject.url).to eq(plantuml_url) - end - - it "enables PNG support" do - expect(subject.png_enable).to be_falsey - end - - it "disables SVG support" do - expect(subject.svg_enable).to be_falsey - end - - it "disables TXT support" do - expect(subject.txt_enable).to be_falsey - end - end - end -end diff --git a/spec/lib/gitlab/utils/file_info_spec.rb b/spec/lib/gitlab/utils/file_info_spec.rb deleted file mode 100644 index 480036b2fd0..00000000000 --- a/spec/lib/gitlab/utils/file_info_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -require 'fast_spec_helper' - -RSpec.describe Gitlab::Utils::FileInfo, feature_category: :shared do - let(:tmpdir) { Dir.mktmpdir } - let(:file_path) { "#{tmpdir}/test.txt" } - - before do - FileUtils.touch(file_path) - end - - after do - FileUtils.rm_rf(tmpdir) - end - - describe '.linked?' do - it 'raises an error when file does not exist' do - expect { subject.linked?('foo') }.to raise_error(Errno::ENOENT) - end - - shared_examples 'identifies a linked file' do - it 'returns false when file or dir is not a link' do - expect(subject.linked?(tmpdir)).to eq(false) - expect(subject.linked?(file)).to eq(false) - end - - it 'returns true when file or dir is symlinked' do - FileUtils.symlink(tmpdir, "#{tmpdir}/symlinked_dir") - FileUtils.symlink(file_path, "#{tmpdir}/symlinked_file.txt") - - expect(subject.linked?("#{tmpdir}/symlinked_dir")).to eq(true) - expect(subject.linked?("#{tmpdir}/symlinked_file.txt")).to eq(true) - end - - it 'returns true when file has more than one hard link' do - FileUtils.link(file_path, "#{tmpdir}/hardlinked_file.txt") - - expect(subject.linked?(file)).to eq(true) - expect(subject.linked?("#{tmpdir}/hardlinked_file.txt")).to eq(true) - end - end - - context 'when file is a File::Stat' do - let(:file) { File.lstat(file_path) } - - it_behaves_like 'identifies a linked file' - end - - context 'when file is path' do - let(:file) { file_path } - - it_behaves_like 'identifies a linked file' - end - end - - describe '.shares_hard_link?' do - it 'raises an error when file does not exist' do - expect { subject.shares_hard_link?('foo') }.to raise_error(Errno::ENOENT) - end - - shared_examples 'identifies a file that shares a hard link' do - it 'returns false when file or dir does not share hard links' do - expect(subject.shares_hard_link?(tmpdir)).to eq(false) - expect(subject.shares_hard_link?(file)).to eq(false) - end - - it 'returns true when file has more than one hard link' do - FileUtils.link(file_path, "#{tmpdir}/hardlinked_file.txt") - - expect(subject.shares_hard_link?(file)).to eq(true) - expect(subject.shares_hard_link?("#{tmpdir}/hardlinked_file.txt")).to eq(true) - end - end - - context 'when file is a File::Stat' do - let(:file) { File.lstat(file_path) } - - it_behaves_like 'identifies a file that shares a hard link' - end - - context 'when file is path' do - let(:file) { file_path } - - it_behaves_like 'identifies a file that shares a hard link' - end - end -end |