2017-03-24 11:54:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ::Gitlab::RepoPath do
|
2017-04-28 12:52:09 -04:00
|
|
|
describe '.parse' do
|
2017-08-01 14:51:52 -04:00
|
|
|
set(:project) { create(:project, :repository) }
|
2017-04-28 12:52:09 -04:00
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
context 'a repository storage path' do
|
|
|
|
it 'parses a full repository path' do
|
2017-12-01 08:58:49 -05:00
|
|
|
expect(described_class.parse(project.repository.full_path)).to eq([project, false, nil])
|
2017-06-15 20:03:54 -04:00
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
it 'parses a full wiki path' do
|
2017-12-01 08:58:49 -05:00
|
|
|
expect(described_class.parse(project.wiki.repository.full_path)).to eq([project, true, nil])
|
2017-06-15 20:03:54 -04:00
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
context 'a relative path' do
|
|
|
|
it 'parses a relative repository path' do
|
|
|
|
expect(described_class.parse(project.full_path + '.git')).to eq([project, false, nil])
|
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
it 'parses a relative wiki path' do
|
|
|
|
expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, true, nil])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'parses a relative path starting with /' do
|
|
|
|
expect(described_class.parse('/' + project.full_path + '.git')).to eq([project, false, 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, false, 'foo/bar'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'parses a relative wiki path' do
|
|
|
|
expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project, true, 'foo/bar.wiki'])
|
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
it 'parses a relative path starting with /' do
|
|
|
|
expect(described_class.parse('/' + redirect.path + '.git')).to eq([project, false, 'foo/bar'])
|
|
|
|
end
|
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 11:54:22 -04:00
|
|
|
describe '.strip_storage_path' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.repositories).to receive(:storages).and_return({
|
|
|
|
'storage1' => { 'path' => '/foo' },
|
2017-05-03 07:22:03 -04:00
|
|
|
'storage2' => { 'path' => '/bar' }
|
2017-03-24 11:54:22 -04:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'strips the storage path' do
|
|
|
|
expect(described_class.strip_storage_path('/bar/foo/qux/baz.git')).to eq('foo/qux/baz.git')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises NotFoundError if no storage matches the path' do
|
|
|
|
expect { described_class.strip_storage_path('/doesnotexist/foo.git') }.to raise_error(
|
|
|
|
described_class::NotFoundError
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2017-06-15 20:03:54 -04:00
|
|
|
|
|
|
|
describe '.find_project' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-06-15 20:03:54 -04:00
|
|
|
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
|
|
|
|
expect(described_class.find_project(project.full_path)).to eq([project, false])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the cases do not match' do
|
|
|
|
# This is slightly different than web behavior because on the web it is
|
|
|
|
# easy and safe to redirect someone to the correctly-cased URL. For git
|
|
|
|
# requests, we should accept wrongly-cased URLs because it is a pain to
|
|
|
|
# block people's git operations and force them to update remote URLs.
|
|
|
|
it 'returns the project and false' do
|
|
|
|
expect(described_class.find_project(project.full_path.upcase)).to eq([project, false])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when finding a project via a redirect' do
|
|
|
|
it 'returns the project and true' do
|
|
|
|
expect(described_class.find_project(redirect.path)).to eq([project, true])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-24 11:54:22 -04:00
|
|
|
end
|