diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 03:07:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 03:07:49 +0300 |
commit | 77237c5a6b9044f58beabc54d3589e5fa09cbfba (patch) | |
tree | f43188047fe8955f6cf78e05ae9c2e8f6a019e0b /spec/lib | |
parent | 2fd92f2dc784ade9cb4e1c33dd60cbfad7b86818 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/backup/manager_spec.rb | 53 | ||||
-rw-r--r-- | spec/lib/gitlab/asset_proxy_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/gl_repository/repo_type_spec.rb | 78 | ||||
-rw-r--r-- | spec/lib/gitlab/gl_repository_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/path_regex_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/repo_path_spec.rb | 80 | ||||
-rw-r--r-- | spec/lib/gitlab/repository_cache_spec.rb | 43 | ||||
-rw-r--r-- | spec/lib/gitlab/repository_set_cache_spec.rb | 39 |
9 files changed, 281 insertions, 72 deletions
diff --git a/spec/lib/backup/manager_spec.rb b/spec/lib/backup/manager_spec.rb index 06ad0557e37..cee299522ce 100644 --- a/spec/lib/backup/manager_spec.rb +++ b/spec/lib/backup/manager_spec.rb @@ -214,6 +214,30 @@ describe Backup::Manager do end end + describe 'verify_backup_version' do + context 'on version mismatch' do + let(:gitlab_version) { Gitlab::VERSION } + + it 'stops the process' do + allow(YAML).to receive(:load_file) + .and_return({ gitlab_version: "not #{gitlab_version}" }) + + expect { subject.verify_backup_version }.to raise_error SystemExit + end + end + + context 'on version match' do + let(:gitlab_version) { Gitlab::VERSION } + + it 'does nothing' do + allow(YAML).to receive(:load_file) + .and_return({ gitlab_version: "#{gitlab_version}" }) + + expect { subject.verify_backup_version }.not_to raise_error + end + end + end + describe '#unpack' do context 'when there are no backup files in the directory' do before do @@ -292,6 +316,23 @@ describe Backup::Manager do expect(progress).to have_received(:puts).with(a_string_matching('done')) end end + + context 'when there is a non-tarred backup in the directory' do + before do + allow(Dir).to receieve(:glob).and_return( + [ + 'backup_information.yml' + ] + ) + + it 'selects the non-tarred backup to restore from' do + expect { subject.unpack }.to output.to_stdout + expect(progress).to have_received(:puts) + .with(a_string_matching('Non tarred backup found ')) + expect(Kernel).not_to receive(:system) + end + end + end end describe '#upload' do @@ -329,9 +370,7 @@ describe Backup::Manager do .with(hash_including(key: backup_filename, public: false)) .and_return(true) - Dir.chdir(Gitlab.config.backup.path) do - subject.upload - end + subject.upload end it 'adds the DIRECTORY environment variable if present' do @@ -341,9 +380,7 @@ describe Backup::Manager do .with(hash_including(key: "daily/#{backup_filename}", public: false)) .and_return(true) - Dir.chdir(Gitlab.config.backup.path) do - subject.upload - end + subject.upload end end @@ -373,9 +410,7 @@ describe Backup::Manager do .with(hash_excluding(public: false)) .and_return(true) - Dir.chdir(Gitlab.config.backup.path) do - subject.upload - end + subject.upload end end end diff --git a/spec/lib/gitlab/asset_proxy_spec.rb b/spec/lib/gitlab/asset_proxy_spec.rb index f5aa1819982..e406917a5a4 100644 --- a/spec/lib/gitlab/asset_proxy_spec.rb +++ b/spec/lib/gitlab/asset_proxy_spec.rb @@ -33,9 +33,15 @@ describe Gitlab::AssetProxy do expect(described_class.proxy_url(url)).to eq(proxied_url) end + it 'returns original URL for invalid domains' do + url = 'foo_bar://' + + expect(described_class.proxy_url(url)).to eq(url) + end + context 'whitelisted domain' do it 'returns original URL for single domain whitelist' do - url = 'http://gitlab.com/test.png' + url = 'http://gitlab.com/${default_branch}/test.png' expect(described_class.proxy_url(url)).to eq(url) end diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index f95349a2125..a29c56c598f 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -240,7 +240,7 @@ describe Gitlab::GitAccess do let(:access) do described_class.new(actor, nil, protocol, authentication_abilities: authentication_abilities, - project_path: project_path, namespace_path: namespace_path, + repository_path: project_path, namespace_path: namespace_path, redirected_path: redirected_path) end @@ -259,7 +259,7 @@ describe Gitlab::GitAccess do let(:access) do described_class.new(actor, nil, protocol, authentication_abilities: authentication_abilities, - project_path: project_path, namespace_path: namespace_path, + repository_path: project_path, namespace_path: namespace_path, redirected_path: redirected_path) end @@ -453,7 +453,7 @@ describe Gitlab::GitAccess do let(:access) do described_class.new(actor, project, protocol, authentication_abilities: authentication_abilities, - project_path: project_path, namespace_path: namespace_path, + repository_path: project_path, namespace_path: namespace_path, redirected_path: redirected_path) end @@ -598,7 +598,7 @@ describe Gitlab::GitAccess do let(:public_project) { create(:project, :public, :repository) } let(:project_path) { public_project.path } let(:namespace_path) { public_project.namespace.path } - let(:access) { described_class.new(nil, public_project, 'web', authentication_abilities: [:download_code], project_path: project_path, namespace_path: namespace_path) } + let(:access) { described_class.new(nil, public_project, 'web', authentication_abilities: [:download_code], repository_path: project_path, namespace_path: namespace_path) } context 'when repository is enabled' do it 'give access to download code' do @@ -1203,7 +1203,7 @@ describe Gitlab::GitAccess do def access described_class.new(actor, project, protocol, authentication_abilities: authentication_abilities, - namespace_path: namespace_path, project_path: project_path, + namespace_path: namespace_path, repository_path: project_path, redirected_path: redirected_path, auth_result_type: auth_result_type) end diff --git a/spec/lib/gitlab/gl_repository/repo_type_spec.rb b/spec/lib/gitlab/gl_repository/repo_type_spec.rb index 7cf0442fbe1..6185b068d4c 100644 --- a/spec/lib/gitlab/gl_repository/repo_type_spec.rb +++ b/spec/lib/gitlab/gl_repository/repo_type_spec.rb @@ -5,46 +5,62 @@ describe Gitlab::GlRepository::RepoType do let_it_be(:project) { create(:project) } let_it_be(:personal_snippet) { create(:personal_snippet, author: project.owner) } let_it_be(:project_snippet) { create(:project_snippet, project: project, author: project.owner) } + let(:project_path) { project.repository.full_path } + let(:wiki_path) { project.wiki.repository.full_path } + let(:personal_snippet_path) { "snippets/#{personal_snippet.id}" } + let(:project_snippet_path) { "#{project.full_path}/snippets/#{project_snippet.id}" } describe Gitlab::GlRepository::PROJECT do it_behaves_like 'a repo type' do - let(:expected_identifier) { "project-#{project.id}" } let(:expected_id) { project.id.to_s } + let(:expected_identifier) { "project-#{expected_id}" } let(:expected_suffix) { '' } - let(:expected_repository) { project.repository } let(:expected_container) { project } + let(:expected_repository) { expected_container.repository } end it 'knows its type' do - expect(described_class).not_to be_wiki - expect(described_class).to be_project - expect(described_class).not_to be_snippet + aggregate_failures do + expect(described_class).not_to be_wiki + expect(described_class).to be_project + expect(described_class).not_to be_snippet + end end it 'checks if repository path is valid' do - expect(described_class.valid?(project.repository.full_path)).to be_truthy - expect(described_class.valid?(project.wiki.repository.full_path)).to be_truthy + aggregate_failures do + expect(described_class.valid?(project_path)).to be_truthy + expect(described_class.valid?(wiki_path)).to be_truthy + expect(described_class.valid?(personal_snippet_path)).to be_truthy + expect(described_class.valid?(project_snippet_path)).to be_truthy + end end end describe Gitlab::GlRepository::WIKI do it_behaves_like 'a repo type' do - let(:expected_identifier) { "wiki-#{project.id}" } let(:expected_id) { project.id.to_s } + let(:expected_identifier) { "wiki-#{expected_id}" } let(:expected_suffix) { '.wiki' } - let(:expected_repository) { project.wiki.repository } let(:expected_container) { project } + let(:expected_repository) { expected_container.wiki.repository } end it 'knows its type' do - expect(described_class).to be_wiki - expect(described_class).not_to be_project - expect(described_class).not_to be_snippet + aggregate_failures do + expect(described_class).to be_wiki + expect(described_class).not_to be_project + expect(described_class).not_to be_snippet + end end it 'checks if repository path is valid' do - expect(described_class.valid?(project.repository.full_path)).to be_falsey - expect(described_class.valid?(project.wiki.repository.full_path)).to be_truthy + aggregate_failures do + expect(described_class.valid?(project_path)).to be_falsey + expect(described_class.valid?(wiki_path)).to be_truthy + expect(described_class.valid?(personal_snippet_path)).to be_falsey + expect(described_class.valid?(project_snippet_path)).to be_falsey + end end end @@ -59,9 +75,20 @@ describe Gitlab::GlRepository::RepoType do end it 'knows its type' do - expect(described_class).to be_snippet - expect(described_class).not_to be_wiki - expect(described_class).not_to be_project + aggregate_failures do + expect(described_class).to be_snippet + expect(described_class).not_to be_wiki + expect(described_class).not_to be_project + end + end + + it 'checks if repository path is valid' do + aggregate_failures do + expect(described_class.valid?(project_path)).to be_falsey + expect(described_class.valid?(wiki_path)).to be_falsey + expect(described_class.valid?(personal_snippet_path)).to be_truthy + expect(described_class.valid?(project_snippet_path)).to be_truthy + end end end @@ -75,9 +102,20 @@ describe Gitlab::GlRepository::RepoType do end it 'knows its type' do - expect(described_class).to be_snippet - expect(described_class).not_to be_wiki - expect(described_class).not_to be_project + aggregate_failures do + expect(described_class).to be_snippet + expect(described_class).not_to be_wiki + expect(described_class).not_to be_project + end + end + + it 'checks if repository path is valid' do + aggregate_failures do + expect(described_class.valid?(project_path)).to be_falsey + expect(described_class.valid?(wiki_path)).to be_falsey + expect(described_class.valid?(personal_snippet_path)).to be_truthy + expect(described_class.valid?(project_snippet_path)).to be_truthy + end end end end diff --git a/spec/lib/gitlab/gl_repository_spec.rb b/spec/lib/gitlab/gl_repository_spec.rb index 3cfc4c2a132..858f436047e 100644 --- a/spec/lib/gitlab/gl_repository_spec.rb +++ b/spec/lib/gitlab/gl_repository_spec.rb @@ -5,13 +5,18 @@ require 'spec_helper' describe ::Gitlab::GlRepository do describe '.parse' do let_it_be(:project) { create(:project, :repository) } + let_it_be(:snippet) { create(:personal_snippet) } it 'parses a project gl_repository' do - expect(described_class.parse("project-#{project.id}")).to eq([project, Gitlab::GlRepository::PROJECT]) + expect(described_class.parse("project-#{project.id}")).to eq([project, project, Gitlab::GlRepository::PROJECT]) end it 'parses a wiki gl_repository' do - expect(described_class.parse("wiki-#{project.id}")).to eq([project, Gitlab::GlRepository::WIKI]) + expect(described_class.parse("wiki-#{project.id}")).to eq([project, project, Gitlab::GlRepository::WIKI]) + end + + it 'parses a snippet gl_repository' do + expect(described_class.parse("snippet-#{snippet.id}")).to eq([snippet, nil, Gitlab::GlRepository::SNIPPET]) end it 'throws an argument error on an invalid gl_repository type' do diff --git a/spec/lib/gitlab/path_regex_spec.rb b/spec/lib/gitlab/path_regex_spec.rb index 3cbcae4cdeb..8dabe5a756b 100644 --- a/spec/lib/gitlab/path_regex_spec.rb +++ b/spec/lib/gitlab/path_regex_spec.rb @@ -411,4 +411,37 @@ describe Gitlab::PathRegex do it { is_expected.not_to match('git lab') } it { is_expected.not_to match('gitlab.git') } end + + shared_examples 'invalid snippet routes' do + it { is_expected.not_to match('gitlab-org/gitlab/snippets/1.git') } + it { is_expected.not_to match('snippets/1.git') } + it { is_expected.not_to match('gitlab-org/gitlab/snippets/') } + it { is_expected.not_to match('/gitlab-org/gitlab/snippets/1') } + it { is_expected.not_to match('gitlab-org/gitlab/snippets/foo') } + it { is_expected.not_to match('root/snippets/1') } + it { is_expected.not_to match('/snippets/1') } + it { is_expected.not_to match('snippets/') } + it { is_expected.not_to match('snippets/foo') } + end + + describe '.full_snippets_repository_path_regex' do + subject { described_class.full_snippets_repository_path_regex } + + it { is_expected.to match('gitlab-org/gitlab/snippets/1') } + it { is_expected.to match('snippets/1') } + + it_behaves_like 'invalid snippet routes' + end + + describe '.personal_and_project_snippets_path_regex' do + subject { %r{\A#{described_class.personal_and_project_snippets_path_regex}\z} } + + it { is_expected.to match('gitlab-org/gitlab/snippets') } + it { is_expected.to match('snippets') } + + it { is_expected.not_to match('gitlab-org/gitlab/snippets/1') } + it { is_expected.not_to match('snippets/1') } + + it_behaves_like 'invalid snippet routes' + end end diff --git a/spec/lib/gitlab/repo_path_spec.rb b/spec/lib/gitlab/repo_path_spec.rb index 2aeb69db2cb..e72bdc01940 100644 --- a/spec/lib/gitlab/repo_path_spec.rb +++ b/spec/lib/gitlab/repo_path_spec.rb @@ -3,60 +3,72 @@ require 'spec_helper' describe ::Gitlab::RepoPath do - describe '.parse' do - let_it_be(:project) { create(:project, :repository) } + include Gitlab::Routing + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:personal_snippet) { create(:personal_snippet) } + let_it_be(:project_snippet) { create(:project_snippet, project: project) } + let_it_be(:redirect) { project.route.create_redirect('foo/bar/baz') } + describe '.parse' do context 'a repository storage path' do - it 'parses a full repository path' do - expect(described_class.parse(project.repository.full_path)).to eq([project, Gitlab::GlRepository::PROJECT, nil]) + it 'parses a full repository project path' do + expect(described_class.parse(project.repository.full_path)).to eq([project, project, Gitlab::GlRepository::PROJECT, nil]) + end + + it 'parses a full wiki project path' do + expect(described_class.parse(project.wiki.repository.full_path)).to eq([project, project, Gitlab::GlRepository::WIKI, nil]) + end + + it 'parses a personal snippet repository path' do + expect(described_class.parse("snippets/#{personal_snippet.id}")).to eq([personal_snippet, nil, Gitlab::GlRepository::SNIPPET, nil]) end - it 'parses a full wiki path' do - expect(described_class.parse(project.wiki.repository.full_path)).to eq([project, Gitlab::GlRepository::WIKI, nil]) + it 'parses a project snippet repository path' do + expect(described_class.parse("#{project.full_path}/snippets/#{project_snippet.id}")).to eq([project_snippet, project, Gitlab::GlRepository::SNIPPET, nil]) end end context 'a relative path' do it 'parses a relative repository path' do - expect(described_class.parse(project.full_path + '.git')).to eq([project, Gitlab::GlRepository::PROJECT, nil]) + expect(described_class.parse(project.full_path + '.git')).to eq([project, project, Gitlab::GlRepository::PROJECT, nil]) end it 'parses a relative wiki path' do - expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, Gitlab::GlRepository::WIKI, nil]) + expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, project, Gitlab::GlRepository::WIKI, nil]) end it 'parses a relative path starting with /' do - expect(described_class.parse('/' + project.full_path + '.git')).to eq([project, Gitlab::GlRepository::PROJECT, nil]) + expect(described_class.parse('/' + project.full_path + '.git')).to eq([project, project, Gitlab::GlRepository::PROJECT, nil]) end context 'of a redirected project' do let(:redirect) { project.route.create_redirect('foo/bar') } it 'parses a relative repository path' do - expect(described_class.parse(redirect.path + '.git')).to eq([project, Gitlab::GlRepository::PROJECT, 'foo/bar']) + expect(described_class.parse(redirect.path + '.git')).to eq([project, project, Gitlab::GlRepository::PROJECT, 'foo/bar']) end it 'parses a relative wiki path' do - expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project, Gitlab::GlRepository::WIKI, 'foo/bar.wiki']) + expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project, project, Gitlab::GlRepository::WIKI, 'foo/bar.wiki']) end it 'parses a relative path starting with /' do - expect(described_class.parse('/' + redirect.path + '.git')).to eq([project, Gitlab::GlRepository::PROJECT, 'foo/bar']) + expect(described_class.parse('/' + redirect.path + '.git')).to eq([project, project, Gitlab::GlRepository::PROJECT, 'foo/bar']) + end + + it 'parses a redirected project snippet repository path' do + expect(described_class.parse(redirect.path + "/snippets/#{project_snippet.id}.git")).to eq([project_snippet, project, Gitlab::GlRepository::SNIPPET, "foo/bar/snippets/#{project_snippet.id}"]) end end end - it "returns the default type for non existent paths" do - _project, type, _redirected = described_class.parse("path/non-existent.git") - - expect(type).to eq(Gitlab::GlRepository.default_type) + it 'returns the default type for non existent paths' do + expect(described_class.parse('path/non-existent.git')).to eq([nil, nil, Gitlab::GlRepository.default_type, nil]) end end describe '.find_project' do - let(:project) { create(:project) } - let(:redirect) { project.route.create_redirect('foo/bar/baz') } - context 'when finding a project by its canonical path' do context 'when the cases match' do it 'returns the project and false' do @@ -81,4 +93,34 @@ describe ::Gitlab::RepoPath do end end end + + describe '.find_snippet' do + it 'extracts path and id from personal snippet route' do + expect(described_class.find_snippet("snippets/#{personal_snippet.id}")).to eq([personal_snippet, false]) + end + + it 'extracts path and id from project snippet route' do + expect(described_class.find_snippet("#{project.full_path}/snippets/#{project_snippet.id}")).to eq([project_snippet, false]) + end + + it 'returns nil for invalid snippet paths' do + aggregate_failures do + expect(described_class.find_snippet("snippets/#{project_snippet.id}")).to eq([nil, false]) + expect(described_class.find_snippet("#{project.full_path}/snippets/#{personal_snippet.id}")).to eq([nil, false]) + expect(described_class.find_snippet('')).to eq([nil, false]) + end + end + + it 'returns nil for snippets not associated with the project' do + snippet = create(:project_snippet) + + expect(described_class.find_snippet("#{project.full_path}/snippets/#{snippet.id}")).to eq([nil, false]) + end + + context 'when finding a project snippet via a redirect' do + it 'returns the project and true' do + expect(described_class.find_snippet("#{redirect.path}/snippets/#{project_snippet.id}")).to eq([project_snippet, true]) + end + end + end end diff --git a/spec/lib/gitlab/repository_cache_spec.rb b/spec/lib/gitlab/repository_cache_spec.rb index e787288fc51..be31be761ad 100644 --- a/spec/lib/gitlab/repository_cache_spec.rb +++ b/spec/lib/gitlab/repository_cache_spec.rb @@ -12,19 +12,44 @@ describe Gitlab::RepositoryCache do describe '#cache_key' do subject { cache.cache_key(:foo) } - it 'includes the namespace' do - expect(subject).to eq "foo:#{namespace}" + shared_examples 'cache_key examples' do + it 'includes the namespace' do + expect(subject).to eq "foo:#{namespace}" + end + + context 'with a given namespace' do + let(:extra_namespace) { 'my:data' } + let(:cache) do + described_class.new(repository, extra_namespace: extra_namespace, + backend: backend) + end + + it 'includes the full namespace' do + expect(subject).to eq "foo:#{namespace}:#{extra_namespace}" + end + end end - context 'with a given namespace' do - let(:extra_namespace) { 'my:data' } - let(:cache) do - described_class.new(repository, extra_namespace: extra_namespace, - backend: backend) + describe 'project repository' do + it_behaves_like 'cache_key examples' do + let(:repository) { project.repository } end + end + + describe 'personal snippet repository' do + let_it_be(:personal_snippet) { create(:personal_snippet) } + let(:namespace) { repository.full_path } + + it_behaves_like 'cache_key examples' do + let(:repository) { personal_snippet.repository } + end + end + + describe 'project snippet repository' do + let_it_be(:project_snippet) { create(:project_snippet, project: project) } - it 'includes the full namespace' do - expect(subject).to eq "foo:#{namespace}:#{extra_namespace}" + it_behaves_like 'cache_key examples' do + let(:repository) { project_snippet.repository } end end end diff --git a/spec/lib/gitlab/repository_set_cache_spec.rb b/spec/lib/gitlab/repository_set_cache_spec.rb index de0f3602346..bcf27b338f6 100644 --- a/spec/lib/gitlab/repository_set_cache_spec.rb +++ b/spec/lib/gitlab/repository_set_cache_spec.rb @@ -11,16 +11,41 @@ describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do describe '#cache_key' do subject { cache.cache_key(:foo) } - it 'includes the namespace' do - is_expected.to eq("foo:#{namespace}:set") + shared_examples 'cache_key examples' do + it 'includes the namespace' do + is_expected.to eq("foo:#{namespace}:set") + end + + context 'with a given namespace' do + let(:extra_namespace) { 'my:data' } + let(:cache) { described_class.new(repository, extra_namespace: extra_namespace) } + + it 'includes the full namespace' do + is_expected.to eq("foo:#{namespace}:#{extra_namespace}:set") + end + end + end + + describe 'project repository' do + it_behaves_like 'cache_key examples' do + let(:repository) { project.repository } + end + end + + describe 'personal snippet repository' do + let_it_be(:personal_snippet) { create(:personal_snippet) } + let(:namespace) { repository.full_path } + + it_behaves_like 'cache_key examples' do + let(:repository) { personal_snippet.repository } + end end - context 'with a given namespace' do - let(:extra_namespace) { 'my:data' } - let(:cache) { described_class.new(repository, extra_namespace: extra_namespace) } + describe 'project snippet repository' do + let_it_be(:project_snippet) { create(:project_snippet, project: project) } - it 'includes the full namespace' do - is_expected.to eq("foo:#{namespace}:#{extra_namespace}:set") + it_behaves_like 'cache_key examples' do + let(:repository) { project_snippet.repository } end end end |