summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits_spec.rb12
-rw-r--r--spec/lib/gitlab/checks/lfs_integrity_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb65
-rw-r--r--spec/lib/gitlab/conflict/file_spec.rb2
-rw-r--r--spec/lib/gitlab/cycle_analytics/usage_data_spec.rb19
-rw-r--r--spec/lib/gitlab/file_finder_spec.rb24
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb133
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml1
-rw-r--r--spec/lib/gitlab/project_search_results_spec.rb82
-rw-r--r--spec/lib/gitlab/url_blocker_spec.rb10
-rw-r--r--spec/lib/gitlab/wiki_file_finder_spec.rb20
11 files changed, 242 insertions, 130 deletions
diff --git a/spec/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits_spec.rb b/spec/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits_spec.rb
index 007e93c1db6..211e3aaa94b 100644
--- a/spec/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits_spec.rb
+++ b/spec/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits_spec.rb
@@ -299,7 +299,11 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m
let(:commits) { merge_request_diff.commits.map(&:to_hash) }
let(:first_commit) { project.repository.commit(merge_request_diff.head_commit_sha) }
let(:expected_commits) { commits }
- let(:diffs) { first_commit.rugged_diff_from_parent.patches }
+ let(:diffs) do
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ first_commit.rugged_diff_from_parent.patches
+ end
+ end
let(:expected_diffs) { [] }
include_examples 'updated MR diff'
@@ -309,7 +313,11 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m
let(:commits) { merge_request_diff.commits.map(&:to_hash) }
let(:first_commit) { project.repository.commit(merge_request_diff.head_commit_sha) }
let(:expected_commits) { commits }
- let(:diffs) { first_commit.rugged_diff_from_parent.deltas }
+ let(:diffs) do
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ first_commit.rugged_diff_from_parent.deltas
+ end
+ end
let(:expected_diffs) { [] }
include_examples 'updated MR diff'
diff --git a/spec/lib/gitlab/checks/lfs_integrity_spec.rb b/spec/lib/gitlab/checks/lfs_integrity_spec.rb
index 7201e4f7bf6..ec22e3a198e 100644
--- a/spec/lib/gitlab/checks/lfs_integrity_spec.rb
+++ b/spec/lib/gitlab/checks/lfs_integrity_spec.rb
@@ -6,7 +6,9 @@ describe Gitlab::Checks::LfsIntegrity do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:newrev) do
- operations = BareRepoOperations.new(repository.path)
+ operations = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ BareRepoOperations.new(repository.path)
+ end
# Create a commit not pointed at by any ref to emulate being in the
# pre-receive hook so that `--not --all` returns some objects
diff --git a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
index 4d7d6951a51..c5a4d9b4778 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
@@ -42,6 +42,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'correctly assigns user' do
expect(pipeline.builds).to all(have_attributes(user: user))
end
+
+ it 'has pipeline iid' do
+ expect(pipeline.iid).to be > 0
+ end
end
context 'when pipeline is empty' do
@@ -68,6 +72,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.errors.to_a)
.to include 'No stages / jobs for this pipeline.'
end
+
+ it 'wastes pipeline iid' do
+ expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
+ end
end
context 'when pipeline has validation errors' do
@@ -87,6 +95,10 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.errors.to_a)
.to include 'Failed to build the pipeline!'
end
+
+ it 'wastes pipeline iid' do
+ expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
+ end
end
context 'when there is a seed blocks present' do
@@ -111,6 +123,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
expect(pipeline.variables.first.key).to eq 'VAR'
expect(pipeline.variables.first.value).to eq '123'
end
+
+ it 'has pipeline iid' do
+ step.perform!
+
+ expect(pipeline.iid).to be > 0
+ end
end
context 'when seeds block tries to persist some resources' do
@@ -121,6 +139,12 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'raises exception' do
expect { step.perform! }.to raise_error(ActiveRecord::RecordNotSaved)
end
+
+ it 'wastes pipeline iid' do
+ expect { step.perform! }.to raise_error
+
+ expect(InternalId.ci_pipelines.where(project_id: project.id).last.last_value).to be > 0
+ end
end
end
@@ -132,22 +156,39 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
end
end
- context 'when using only/except build policies' do
- let(:config) do
- { rspec: { script: 'rspec', stage: 'test', only: ['master'] },
- prod: { script: 'cap prod', stage: 'deploy', only: ['tags'] } }
- end
+ context 'when variables policy is specified' do
+ shared_examples_for 'a correct pipeline' do
+ it 'populates pipeline according to used policies' do
+ step.perform!
- let(:pipeline) do
- build(:ci_pipeline, ref: 'master', config: config)
+ expect(pipeline.stages.size).to eq 1
+ expect(pipeline.stages.first.builds.size).to eq 1
+ expect(pipeline.stages.first.builds.first.name).to eq 'rspec'
+ end
end
- it 'populates pipeline according to used policies' do
- step.perform!
+ context 'when using only/except build policies' do
+ let(:config) do
+ { rspec: { script: 'rspec', stage: 'test', only: ['master'] },
+ prod: { script: 'cap prod', stage: 'deploy', only: ['tags'] } }
+ end
+
+ let(:pipeline) do
+ build(:ci_pipeline, ref: 'master', config: config)
+ end
- expect(pipeline.stages.size).to eq 1
- expect(pipeline.stages.first.builds.size).to eq 1
- expect(pipeline.stages.first.builds.first.name).to eq 'rspec'
+ it_behaves_like 'a correct pipeline'
+
+ context 'when variables expression is specified' do
+ context 'when pipeline iid is the subject' do
+ let(:config) do
+ { rspec: { script: 'rspec', only: { variables: ["$CI_PIPELINE_IID == '1'"] } },
+ prod: { script: 'cap prod', only: { variables: ["$CI_PIPELINE_IID == '1000'"] } } }
+ end
+
+ it_behaves_like 'a correct pipeline'
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb
index 92792144429..5b343920429 100644
--- a/spec/lib/gitlab/conflict/file_spec.rb
+++ b/spec/lib/gitlab/conflict/file_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::Conflict::File do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
- let(:rugged) { repository.rugged }
+ let(:rugged) { Gitlab::GitalyClient::StorageSettings.allow_disk_access { repository.rugged } }
let(:their_commit) { rugged.branches['conflict-start'].target }
let(:our_commit) { rugged.branches['conflict-resolvable'].target }
let(:merge_request) { create(:merge_request, source_branch: 'conflict-resolvable', target_branch: 'conflict-start', source_project: project) }
diff --git a/spec/lib/gitlab/cycle_analytics/usage_data_spec.rb b/spec/lib/gitlab/cycle_analytics/usage_data_spec.rb
index 56a316318cb..a785b17f682 100644
--- a/spec/lib/gitlab/cycle_analytics/usage_data_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/usage_data_spec.rb
@@ -3,7 +3,12 @@ require 'spec_helper'
describe Gitlab::CycleAnalytics::UsageData do
describe '#to_json' do
before do
- Timecop.freeze do
+ # Since git commits only have second precision, round up to the
+ # nearest second to ensure we have accurate median and standard
+ # deviation calculations.
+ current_time = Time.at(Time.now.to_i)
+
+ Timecop.freeze(current_time) do
user = create(:user, :admin)
projects = create_list(:project, 2, :repository)
@@ -37,13 +42,7 @@ describe Gitlab::CycleAnalytics::UsageData do
expected_values.each_pair do |op, value|
expect(stage_values).to have_key(op)
-
- if op == :missing
- expect(stage_values[op]).to eq(value)
- else
- # delta is used because of git timings that Timecop does not stub
- expect(stage_values[op].to_i).to be_within(5).of(value.to_i)
- end
+ expect(stage_values[op]).to eq(value)
end
end
end
@@ -58,8 +57,8 @@ describe Gitlab::CycleAnalytics::UsageData do
missing: 0
},
plan: {
- average: 2,
- sd: 2,
+ average: 1,
+ sd: 0,
missing: 0
},
code: {
diff --git a/spec/lib/gitlab/file_finder_spec.rb b/spec/lib/gitlab/file_finder_spec.rb
index 07cb10e563e..d6d9e4001a3 100644
--- a/spec/lib/gitlab/file_finder_spec.rb
+++ b/spec/lib/gitlab/file_finder_spec.rb
@@ -3,27 +3,11 @@ require 'spec_helper'
describe Gitlab::FileFinder do
describe '#find' do
let(:project) { create(:project, :public, :repository) }
- let(:finder) { described_class.new(project, project.default_branch) }
- it 'finds by name' do
- results = finder.find('files')
-
- filename, blob = results.find { |_, blob| blob.filename == 'files/images/wm.svg' }
- expect(filename).to eq('files/images/wm.svg')
- expect(blob).to be_a(Gitlab::SearchResults::FoundBlob)
- expect(blob.ref).to eq(finder.ref)
- expect(blob.data).not_to be_empty
- end
-
- it 'finds by content' do
- results = finder.find('files')
-
- filename, blob = results.find { |_, blob| blob.filename == 'CHANGELOG' }
-
- expect(filename).to eq('CHANGELOG')
- expect(blob).to be_a(Gitlab::SearchResults::FoundBlob)
- expect(blob.ref).to eq(finder.ref)
- expect(blob.data).not_to be_empty
+ it_behaves_like 'file finder' do
+ subject { described_class.new(project, project.default_branch) }
+ let(:expected_file_by_name) { 'files/images/wm.svg' }
+ let(:expected_file_by_content) { 'CHANGELOG' }
end
end
end
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index dd5c498706d..7a9621d9c78 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -114,7 +114,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'raises a no repository exception when there is no repo' do
broken_repo = described_class.new('default', 'a/path.git', '')
- expect { broken_repo.rugged }.to raise_error(Gitlab::Git::Repository::NoRepository)
+ expect do
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access { broken_repo.rugged }
+ end.to raise_error(Gitlab::Git::Repository::NoRepository)
end
describe 'alternates keyword argument' do
@@ -124,9 +126,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
it "is passed an empty array" do
- expect(Rugged::Repository).to receive(:new).with(repository.path, alternates: [])
+ expect(Rugged::Repository).to receive(:new).with(repository_path, alternates: [])
- repository.rugged
+ repository_rugged
end
end
@@ -142,10 +144,10 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
it "is passed the relative object dir envvars after being converted to absolute ones" do
- alternates = %w[foo bar baz].map { |d| File.join(repository.path, './objects', d) }
- expect(Rugged::Repository).to receive(:new).with(repository.path, alternates: alternates)
+ alternates = %w[foo bar baz].map { |d| File.join(repository_path, './objects', d) }
+ expect(Rugged::Repository).to receive(:new).with(repository_path, alternates: alternates)
- repository.rugged
+ repository_rugged
end
end
end
@@ -156,16 +158,22 @@ describe Gitlab::Git::Repository, seed_helper: true do
let(:feature) { 'feature' }
let(:feature2) { 'feature2' }
+ around do |example|
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ example.run
+ end
+ end
+
it "returns 'master' when master exists" do
expect(repository).to receive(:branch_names).at_least(:once).and_return([feature, master])
expect(repository.discover_default_branch).to eq('master')
end
it "returns non-master when master exists but default branch is set to something else" do
- File.write(File.join(repository.path, 'HEAD'), 'ref: refs/heads/feature')
+ File.write(File.join(repository_path, 'HEAD'), 'ref: refs/heads/feature')
expect(repository).to receive(:branch_names).at_least(:once).and_return([feature, master])
expect(repository.discover_default_branch).to eq('feature')
- File.write(File.join(repository.path, 'HEAD'), 'ref: refs/heads/master')
+ File.write(File.join(repository_path, 'HEAD'), 'ref: refs/heads/master')
end
it "returns a non-master branch when only one exists" do
@@ -364,6 +372,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
context '#submodules' do
+ around do |example|
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ example.run
+ end
+ end
+
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') }
context 'where repo has submodules' do
@@ -474,8 +488,8 @@ describe Gitlab::Git::Repository, seed_helper: true do
# Sanity check
expect(repository.has_local_branches?).to eq(true)
- FileUtils.rm_rf(File.join(repository.path, 'packed-refs'))
- heads_dir = File.join(repository.path, 'refs/heads')
+ FileUtils.rm_rf(File.join(repository_path, 'packed-refs'))
+ heads_dir = File.join(repository_path, 'refs/heads')
FileUtils.rm_rf(heads_dir)
FileUtils.mkdir_p(heads_dir)
@@ -516,10 +530,10 @@ describe Gitlab::Git::Repository, seed_helper: true do
branch_name = "to-be-deleted-soon"
repository.create_branch(branch_name)
- expect(repository.rugged.branches[branch_name]).not_to be_nil
+ expect(repository_rugged.branches[branch_name]).not_to be_nil
repository.delete_branch(branch_name)
- expect(repository.rugged.branches[branch_name]).to be_nil
+ expect(repository_rugged.branches[branch_name]).to be_nil
end
context "when branch does not exist" do
@@ -577,6 +591,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
shared_examples 'deleting refs' do
let(:repo) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') }
+ def repo_rugged
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ repo.rugged
+ end
+ end
+
after do
ensure_seeds
end
@@ -584,7 +604,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'deletes the ref' do
repo.delete_refs('refs/heads/feature')
- expect(repo.rugged.references['refs/heads/feature']).to be_nil
+ expect(repo_rugged.references['refs/heads/feature']).to be_nil
end
it 'deletes all refs' do
@@ -592,7 +612,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
repo.delete_refs(*refs)
refs.each do |ref|
- expect(repo.rugged.references[ref]).to be_nil
+ expect(repo_rugged.references[ref]).to be_nil
end
end
@@ -615,7 +635,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe '#branch_names_contains_sha' do
- let(:head_id) { repository.rugged.head.target.oid }
+ let(:head_id) { repository_rugged.head.target.oid }
let(:new_branch) { head_id }
let(:utf8_branch) { 'branch-é' }
@@ -699,7 +719,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'fetches a repository as a mirror remote' do
subject
- expect(refs(new_repository.path)).to eq(refs(repository.path))
+ expect(refs(new_repository_path)).to eq(refs(repository_path))
end
context 'with keep-around refs' do
@@ -708,15 +728,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
let(:tmp_ref) { "refs/tmp/#{SecureRandom.hex}" }
before do
- repository.rugged.references.create(keep_around_ref, sha, force: true)
- repository.rugged.references.create(tmp_ref, sha, force: true)
+ repository_rugged.references.create(keep_around_ref, sha, force: true)
+ repository_rugged.references.create(tmp_ref, sha, force: true)
end
it 'includes the temporary and keep-around refs' do
subject
- expect(refs(new_repository.path)).to include(keep_around_ref)
- expect(refs(new_repository.path)).to include(tmp_ref)
+ expect(refs(new_repository_path)).to include(keep_around_ref)
+ expect(refs(new_repository_path)).to include(tmp_ref)
end
end
end
@@ -728,6 +748,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'with gitaly enabled', :skip_gitaly_mock do
it_behaves_like 'repository mirror fecthing'
end
+
+ def new_repository_path
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ new_repository.path
+ end
+ end
end
describe '#remote_tags' do
@@ -739,10 +765,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '')
end
+ around do |example|
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ example.run
+ end
+ end
+
subject { repository.remote_tags(remote_name) }
before do
- repository.add_remote(remote_name, remote_repository.path)
+ remote_repository_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access { remote_repository.path }
+ repository.add_remote(remote_name, remote_repository_path)
remote_repository.add_tag(tag_name, user: user, target: target_commit_id)
end
@@ -975,8 +1008,10 @@ describe Gitlab::Git::Repository, seed_helper: true do
let(:options) { { ref: 'master', path: ['PROCESS.md', 'README.md'] } }
def commit_files(commit)
- commit.rugged_diff_from_parent.deltas.flat_map do |delta|
- [delta.old_file[:path], delta.new_file[:path]].uniq.compact
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ commit.rugged_diff_from_parent.deltas.flat_map do |delta|
+ [delta.old_file[:path], delta.new_file[:path]].uniq.compact
+ end
end
end
@@ -1019,6 +1054,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe "#rugged_commits_between" do
+ around do |example|
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ example.run
+ end
+ end
+
context 'two SHAs' do
let(:first_sha) { 'b0e52af38d7ea43cf41d8a6f2471351ac036d6c9' }
let(:second_sha) { '0e50ec4d3c7ce42ab74dda1d422cb2cbffe1e326' }
@@ -1363,7 +1404,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
allow(ref).to receive(:target) { raise Rugged::ReferenceError }
branches = double()
allow(branches).to receive(:each) { [ref].each }
- allow(repository.rugged).to receive(:branches) { branches }
+ allow(repository_rugged).to receive(:branches) { branches }
expect(subject).to be_empty
end
@@ -1661,6 +1702,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#batch_existence' do
let(:refs) { ['deadbeef', SeedRepo::RubyBlob::ID, '909e6157199'] }
+ around do |example|
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ example.run
+ end
+ end
+
it 'returns existing refs back' do
result = repository.batch_existence(refs)
@@ -1840,7 +1887,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'when the branch exists' do
context 'when the commit does not exist locally' do
let(:source_branch) { 'new-branch-for-fetch-source-branch' }
- let(:source_rugged) { source_repository.rugged }
+ let(:source_rugged) { Gitlab::GitalyClient::StorageSettings.allow_disk_access { source_repository.rugged } }
let(:new_oid) { new_commit_edit_old_file(source_rugged).oid }
before do
@@ -1898,7 +1945,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
it "removes the branch from the repo" do
repository.rm_branch(branch_name, user: user)
- expect(repository.rugged.branches[branch_name]).to be_nil
+ expect(repository_rugged.branches[branch_name]).to be_nil
end
end
@@ -1930,7 +1977,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#write_config' do
before do
- repository.rugged.config["gitlab.fullpath"] = repository.path
+ repository_rugged.config["gitlab.fullpath"] = repository_path
end
shared_examples 'writing repo config' do
@@ -1938,7 +1985,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'writes it to disk' do
repository.write_config(full_path: "not-the/real-path.git")
- config = File.read(File.join(repository.path, "config"))
+ config = File.read(File.join(repository_path, "config"))
expect(config).to include("[gitlab]")
expect(config).to include("fullpath = not-the/real-path.git")
@@ -1949,10 +1996,10 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'does not write it to disk' do
repository.write_config(full_path: "")
- config = File.read(File.join(repository.path, "config"))
+ config = File.read(File.join(repository_path, "config"))
expect(config).to include("[gitlab]")
- expect(config).to include("fullpath = #{repository.path}")
+ expect(config).to include("fullpath = #{repository_path}")
end
end
end
@@ -2173,7 +2220,11 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#gitlab_projects' do
subject { repository.gitlab_projects }
- it { expect(subject.shard_path).to eq(storage_path) }
+ it do
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ expect(subject.shard_path).to eq(storage_path)
+ end
+ end
it { expect(subject.repository_relative_path).to eq(repository.relative_path) }
end
@@ -2189,7 +2240,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
repository.bundle_to_disk(save_path)
success = system(
- *%W(#{Gitlab.config.git.bin_path} -C #{repository.path} bundle verify #{save_path}),
+ *%W(#{Gitlab.config.git.bin_path} -C #{repository_path} bundle verify #{save_path}),
[:out, :err] => '/dev/null'
)
expect(success).to be true
@@ -2231,7 +2282,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'creates a symlink to the global hooks dir' do
imported_repo.create_from_bundle(bundle_path)
- hooks_path = File.join(imported_repo.path, 'hooks')
+ hooks_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access { File.join(imported_repo.path, 'hooks') }
expect(File.readlink(hooks_path)).to eq(Gitlab.config.gitlab_shell.hooks_path)
end
@@ -2360,7 +2411,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe '#clean_stale_repository_files' do
- let(:worktree_path) { File.join(repository.path, 'worktrees', 'delete-me') }
+ let(:worktree_path) { File.join(repository_path, 'worktrees', 'delete-me') }
it 'cleans up the files' do
repository.with_worktree(worktree_path, 'master', env: ENV) do
@@ -2507,7 +2558,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
def create_remote_branch(repository, remote_name, branch_name, source_branch_name)
source_branch = repository.branches.find { |branch| branch.name == source_branch_name }
- rugged = repository.rugged
+ rugged = repository_rugged
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha)
end
@@ -2586,4 +2637,16 @@ describe Gitlab::Git::Repository, seed_helper: true do
line.split("\t").last
end
end
+
+ def repository_rugged
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ repository.rugged
+ end
+ end
+
+ def repository_path
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ repository.path
+ end
+ end
end
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index 74e7a45fd6c..2aebdc57f7c 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -242,6 +242,7 @@ Ci::Pipeline:
- config_source
- failure_reason
- protected
+- iid
Ci::Stage:
- id
- name
diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb
index e3f705d2299..50224bde722 100644
--- a/spec/lib/gitlab/project_search_results_spec.rb
+++ b/spec/lib/gitlab/project_search_results_spec.rb
@@ -22,47 +22,57 @@ describe Gitlab::ProjectSearchResults do
it { expect(results.query).to eq('hello world') }
end
- describe 'blob search' do
- let(:project) { create(:project, :public, :repository) }
-
- subject(:results) { described_class.new(user, project, 'files').objects('blobs') }
-
- context 'when repository is disabled' do
- let(:project) { create(:project, :public, :repository, :repository_disabled) }
+ shared_examples 'general blob search' do |entity_type, blob_kind|
+ let(:query) { 'files' }
+ subject(:results) { described_class.new(user, project, query).objects(blob_type) }
- it 'hides blobs from members' do
+ context "when #{entity_type} is disabled" do
+ let(:project) { disabled_project }
+ it "hides #{blob_kind} from members" do
project.add_reporter(user)
is_expected.to be_empty
end
- it 'hides blobs from non-members' do
+ it "hides #{blob_kind} from non-members" do
is_expected.to be_empty
end
end
- context 'when repository is internal' do
- let(:project) { create(:project, :public, :repository, :repository_private) }
+ context "when #{entity_type} is internal" do
+ let(:project) { private_project }
- it 'finds blobs for members' do
+ it "finds #{blob_kind} for members" do
project.add_reporter(user)
is_expected.not_to be_empty
end
- it 'hides blobs from non-members' do
+ it "hides #{blob_kind} from non-members" do
is_expected.to be_empty
end
end
it 'finds by name' do
- expect(results.map(&:first)).to include('files/images/wm.svg')
+ expect(results.map(&:first)).to include(expected_file_by_name)
end
it 'finds by content' do
- blob = results.select { |result| result.first == "CHANGELOG" }.flatten.last
+ blob = results.select { |result| result.first == expected_file_by_content }.flatten.last
- expect(blob.filename).to eq("CHANGELOG")
+ expect(blob.filename).to eq(expected_file_by_content)
+ end
+ end
+
+ describe 'blob search' do
+ let(:project) { create(:project, :public, :repository) }
+
+ it_behaves_like 'general blob search', 'repository', 'blobs' do
+ let(:blob_type) { 'blobs' }
+ let(:disabled_project) { create(:project, :public, :repository, :repository_disabled) }
+ let(:private_project) { create(:project, :public, :repository, :repository_private) }
+ let(:expected_file_by_name) { 'files/images/wm.svg' }
+ let(:expected_file_by_content) { 'CHANGELOG' }
end
describe 'parsing results' do
@@ -189,40 +199,18 @@ describe Gitlab::ProjectSearchResults do
describe 'wiki search' do
let(:project) { create(:project, :public, :wiki_repo) }
let(:wiki) { build(:project_wiki, project: project) }
- let!(:wiki_page) { wiki.create_page('Title', 'Content') }
-
- subject(:results) { described_class.new(user, project, 'Content').objects('wiki_blobs') }
-
- context 'when wiki is disabled' do
- let(:project) { create(:project, :public, :wiki_repo, :wiki_disabled) }
- it 'hides wiki blobs from members' do
- project.add_reporter(user)
-
- is_expected.to be_empty
- end
-
- it 'hides wiki blobs from non-members' do
- is_expected.to be_empty
- end
- end
-
- context 'when wiki is internal' do
- let(:project) { create(:project, :public, :wiki_repo, :wiki_private) }
-
- it 'finds wiki blobs for guest' do
- project.add_guest(user)
-
- is_expected.not_to be_empty
- end
-
- it 'hides wiki blobs from non-members' do
- is_expected.to be_empty
- end
+ before do
+ wiki.create_page('Files/Title', 'Content')
+ wiki.create_page('CHANGELOG', 'Files example')
end
- it 'finds by content' do
- expect(results).to include("master:Title.md\x001\x00Content\n")
+ it_behaves_like 'general blob search', 'wiki', 'wiki blobs' do
+ let(:blob_type) { 'wiki_blobs' }
+ let(:disabled_project) { create(:project, :public, :wiki_repo, :wiki_disabled) }
+ let(:private_project) { create(:project, :public, :wiki_repo, :wiki_private) }
+ let(:expected_file_by_name) { 'Files/Title.md' }
+ let(:expected_file_by_content) { 'CHANGELOG.md' }
end
end
diff --git a/spec/lib/gitlab/url_blocker_spec.rb b/spec/lib/gitlab/url_blocker_spec.rb
index a3b3dc3be6d..81dbbb962dd 100644
--- a/spec/lib/gitlab/url_blocker_spec.rb
+++ b/spec/lib/gitlab/url_blocker_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::UrlBlocker do
describe '#blocked_url?' do
- let(:valid_ports) { Project::VALID_IMPORT_PORTS }
+ let(:ports) { Project::VALID_IMPORT_PORTS }
it 'allows imports from configured web host and port' do
import_url = "http://#{Gitlab.config.gitlab.host}:#{Gitlab.config.gitlab.port}/t.git"
@@ -19,7 +19,13 @@ describe Gitlab::UrlBlocker do
end
it 'returns true for bad port' do
- expect(described_class.blocked_url?('https://gitlab.com:25/foo/foo.git', valid_ports: valid_ports)).to be true
+ expect(described_class.blocked_url?('https://gitlab.com:25/foo/foo.git', ports: ports)).to be true
+ end
+
+ it 'returns true for bad protocol' do
+ expect(described_class.blocked_url?('https://gitlab.com/foo/foo.git', protocols: ['https'])).to be false
+ expect(described_class.blocked_url?('https://gitlab.com/foo/foo.git')).to be false
+ expect(described_class.blocked_url?('https://gitlab.com/foo/foo.git', protocols: ['http'])).to be true
end
it 'returns true for alternative version of 127.0.0.1 (0177.1)' do
diff --git a/spec/lib/gitlab/wiki_file_finder_spec.rb b/spec/lib/gitlab/wiki_file_finder_spec.rb
new file mode 100644
index 00000000000..025d1203dc5
--- /dev/null
+++ b/spec/lib/gitlab/wiki_file_finder_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Gitlab::WikiFileFinder do
+ describe '#find' do
+ let(:project) { create(:project, :public, :wiki_repo) }
+ let(:wiki) { build(:project_wiki, project: project) }
+
+ before do
+ wiki.create_page('Files/Title', 'Content')
+ wiki.create_page('CHANGELOG', 'Files example')
+ end
+
+ it_behaves_like 'file finder' do
+ subject { described_class.new(project, project.wiki.default_branch) }
+
+ let(:expected_file_by_name) { 'Files/Title.md' }
+ let(:expected_file_by_content) { 'CHANGELOG.md' }
+ end
+ end
+end