Commit 23107d81 authored by Douwe Maan's avatar Douwe Maan

Merge branch '4054-fix-geo-wiki-clone-instructions' into 'master'

Fix generated clone URLs for wikis on Geo secondaries

Closes #4054

See merge request gitlab-org/gitlab-ee!3448
parents 9f4878f1 48c906fe
---
title: Fix generated clone URLs for wikis on Geo secondaries
merge_request: 3448
author:
type: fixed
...@@ -3,24 +3,24 @@ module EE ...@@ -3,24 +3,24 @@ module EE
include ::ProjectsHelper include ::ProjectsHelper
include ::ApplicationSettingsHelper include ::ApplicationSettingsHelper
def geo_primary_web_url(project) def geo_primary_web_url(project_or_wiki)
File.join(::Gitlab::Geo.primary_node.url, ::Gitlab::Routing.url_helpers.project_path(project)) File.join(::Gitlab::Geo.primary_node.url, project_or_wiki.full_path)
end end
def geo_primary_ssh_url_to_repo(project) def geo_primary_ssh_url_to_repo(project_or_wiki)
"#{::Gitlab::Geo.primary_node.clone_url_prefix}#{project.full_path}.git" "#{::Gitlab::Geo.primary_node.clone_url_prefix}#{project_or_wiki.full_path}.git"
end end
def geo_primary_http_url_to_repo(project) def geo_primary_http_url_to_repo(project_or_wiki)
"#{geo_primary_web_url(project)}.git" geo_primary_web_url(project_or_wiki) + '.git'
end end
def geo_primary_default_url_to_repo(project) def geo_primary_default_url_to_repo(project_or_wiki)
case default_clone_protocol case default_clone_protocol
when 'ssh' when 'ssh'
geo_primary_ssh_url_to_repo(project) geo_primary_ssh_url_to_repo(project_or_wiki)
else else
geo_primary_http_url_to_repo(project) geo_primary_http_url_to_repo(project_or_wiki)
end end
end end
......
...@@ -4,63 +4,85 @@ describe EE::GitlabRoutingHelper do ...@@ -4,63 +4,85 @@ describe EE::GitlabRoutingHelper do
include ProjectsHelper include ProjectsHelper
include ApplicationSettingsHelper include ApplicationSettingsHelper
let!(:primary_node) { create(:geo_node, :primary) } set(:primary) { create(:geo_node, :primary, url: 'http://localhost:123/relative', clone_url_prefix: 'git@localhost:') }
let(:project) { build_stubbed(:project) } set(:group) { create(:group, path: 'foo') }
set(:project) { create(:project, namespace: group, path: 'bar') }
describe '#geo_primary_default_url_to_repo' do describe '#geo_primary_web_url' do
it 'returns an HTTP URL' do before do
allow(helper).to receive(:default_clone_protocol).and_return('http') 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('http://localhost:123/relative/foo/bar')
expect(result).to eq(helper.geo_primary_http_url_to_repo(project))
end end
it 'returns an HTTPS URL' do it 'generates a path to the wiki' do
primary_node.update_attribute(:schema, 'https') result = helper.geo_primary_web_url(project.wiki)
allow(helper).to receive(:default_clone_protocol).and_return('https')
result = helper.geo_primary_default_url_to_repo(project)
expect(result).to start_with('https://') expect(result).to eq('http://localhost:123/relative/foo/bar.wiki')
expect(result).to eq(helper.geo_primary_http_url_to_repo(project))
end end
end
it 'returns an SSH URL' do describe '#geo_primary_default_url_to_repo' do
allow(helper).to receive(:default_clone_protocol).and_return('ssh') 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@') context 'project' do
expect(result).to eq(helper.geo_primary_ssh_url_to_repo(project)) let(:repo) { project }
end
end
describe '#geo_primary_http_url_to_repo' do it { is_expected.to eq('http://localhost:123/relative/foo/bar.git') }
context 'when using http protocol' do end
it 'returns a url in format http://hostname/namespace/repo.git' do
result = helper.geo_primary_http_url_to_repo(project)
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
end end
context 'when using https protocol' do context 'HTTPS' do
it 'returns a url in format https://hostname/namespace/repo.git' do before do
primary_node.update_attributes(schema: 'https', port: 443) allow(helper).to receive(:default_clone_protocol).and_return('https')
result = helper.geo_primary_http_url_to_repo(project) 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 end
end
describe '#geo_primary_ssh_url_to_repo' do context 'SSH' do
it 'returns a url in format user@host:namespace/repo.git' do before do
result = helper.geo_primary_ssh_url_to_repo(project) 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 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