Commit 48c906fe authored by Nick Thomas's avatar Nick Thomas

Fix generated clone URLs for wikis on Geo secondaries

parent 7f9dac98
---
title: Fix generated clone URLs for wikis on Geo secondaries
merge_request: 3448
author:
type: fixed
......@@ -3,24 +3,24 @@ module EE
include ::ProjectsHelper
include ::ApplicationSettingsHelper
def geo_primary_web_url(project)
File.join(::Gitlab::Geo.primary_node.url, ::Gitlab::Routing.url_helpers.project_path(project))
def geo_primary_web_url(project_or_wiki)
File.join(::Gitlab::Geo.primary_node.url, project_or_wiki.full_path)
end
def geo_primary_ssh_url_to_repo(project)
"#{::Gitlab::Geo.primary_node.clone_url_prefix}#{project.full_path}.git"
def geo_primary_ssh_url_to_repo(project_or_wiki)
"#{::Gitlab::Geo.primary_node.clone_url_prefix}#{project_or_wiki.full_path}.git"
end
def geo_primary_http_url_to_repo(project)
"#{geo_primary_web_url(project)}.git"
def geo_primary_http_url_to_repo(project_or_wiki)
geo_primary_web_url(project_or_wiki) + '.git'
end
def geo_primary_default_url_to_repo(project)
def geo_primary_default_url_to_repo(project_or_wiki)
case default_clone_protocol
when 'ssh'
geo_primary_ssh_url_to_repo(project)
geo_primary_ssh_url_to_repo(project_or_wiki)
else
geo_primary_http_url_to_repo(project)
geo_primary_http_url_to_repo(project_or_wiki)
end
end
......
......@@ -4,63 +4,85 @@ describe EE::GitlabRoutingHelper do
include ProjectsHelper
include ApplicationSettingsHelper
let!(:primary_node) { create(:geo_node, :primary) }
let(:project) { build_stubbed(:project) }
set(:primary) { create(:geo_node, :primary, url: 'http://localhost:123/relative', clone_url_prefix: 'git@localhost:') }
set(:group) { create(:group, path: 'foo') }
set(:project) { create(:project, namespace: group, path: 'bar') }
describe '#geo_primary_default_url_to_repo' do
it 'returns an HTTP URL' do
describe '#geo_primary_web_url' do
before do
allow(helper).to receive(:default_clone_protocol).and_return('http')
end
result = helper.geo_primary_default_url_to_repo(project)
it 'generates a path to the project' do
result = helper.geo_primary_web_url(project)
expect(result).to start_with('http://')
expect(result).to eq(helper.geo_primary_http_url_to_repo(project))
expect(result).to eq('http://localhost:123/relative/foo/bar')
end
it 'returns an HTTPS URL' do
primary_node.update_attribute(:schema, 'https')
allow(helper).to receive(:default_clone_protocol).and_return('https')
result = helper.geo_primary_default_url_to_repo(project)
it 'generates a path to the wiki' do
result = helper.geo_primary_web_url(project.wiki)
expect(result).to start_with('https://')
expect(result).to eq(helper.geo_primary_http_url_to_repo(project))
expect(result).to eq('http://localhost:123/relative/foo/bar.wiki')
end
end
it 'returns an SSH URL' do
allow(helper).to receive(:default_clone_protocol).and_return('ssh')
describe '#geo_primary_default_url_to_repo' do
subject { helper.geo_primary_default_url_to_repo(repo) }
result = helper.geo_primary_default_url_to_repo(project)
context 'HTTP' do
before do
allow(helper).to receive(:default_clone_protocol).and_return('http')
primary.update!(schema: 'http')
end
expect(result).to start_with('git@')
expect(result).to eq(helper.geo_primary_ssh_url_to_repo(project))
end
end
context 'project' do
let(:repo) { project }
describe '#geo_primary_http_url_to_repo' do
context 'when using http protocol' do
it 'returns a url in format http://hostname/namespace/repo.git' do
result = helper.geo_primary_http_url_to_repo(project)
it { is_expected.to eq('http://localhost:123/relative/foo/bar.git') }
end
expect(result).to eq("http://localhost/#{project.full_path}.git")
context 'wiki' do
let(:repo) { project.wiki }
it { is_expected.to eq('http://localhost:123/relative/foo/bar.wiki.git') }
end
end
context 'when using https protocol' do
it 'returns a url in format https://hostname/namespace/repo.git' do
primary_node.update_attributes(schema: 'https', port: 443)
result = helper.geo_primary_http_url_to_repo(project)
context 'HTTPS' do
before do
allow(helper).to receive(:default_clone_protocol).and_return('https')
primary.update!(schema: 'https')
end
context 'project' do
let(:repo) { project }
it { is_expected.to eq('https://localhost:123/relative/foo/bar.git') }
end
context 'wiki' do
let(:repo) { project.wiki }
expect(result).to eq("https://localhost/#{project.full_path}.git")
it { is_expected.to eq('https://localhost:123/relative/foo/bar.wiki.git') }
end
end
end
describe '#geo_primary_ssh_url_to_repo' do
it 'returns a url in format user@host:namespace/repo.git' do
result = helper.geo_primary_ssh_url_to_repo(project)
context 'SSH' do
before do
allow(helper).to receive(:default_clone_protocol).and_return('ssh')
end
expect(result).to eq("git@localhost:#{project.full_path}.git")
context 'project' do
let(:repo) { project }
it { is_expected.to eq('git@localhost:foo/bar.git') }
end
context 'wiki' do
let(:repo) { project.wiki }
it { is_expected.to eq('git@localhost:foo/bar.wiki.git') }
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment