Commit bf4cc9e1 authored by Rémy Coutable's avatar Rémy Coutable 🏔

Don't allow to pass a user to ProjectWiki#http_url_to_repo

This partially reverts be25bbc4.
Signed-off-by: Rémy Coutable's avatarRémy Coutable <remy@rymai.me>
parent fd376b3e
......@@ -42,11 +42,8 @@ class ProjectWiki
url_to_repo
end
def http_url_to_repo(user = nil)
url = "#{Gitlab.config.gitlab.url}/#{path_with_namespace}.git"
credentials = Gitlab::UrlSanitizer.http_credentials_for_user(user)
Gitlab::UrlSanitizer.new(url, credentials: credentials).full_url
def http_url_to_repo
"#{Gitlab.config.gitlab.url}/#{path_with_namespace}.git"
end
def wiki_base_path
......
......@@ -18,12 +18,6 @@ module Gitlab
false
end
def self.http_credentials_for_user(user)
return {} unless user.respond_to?(:username)
{ user: user.username }
end
def initialize(url, credentials: nil)
@url = Addressable::URI.parse(url.strip)
@credentials = credentials
......
......@@ -21,6 +21,6 @@ describe 'Projects > Wiki > User views Git access wiki page', :feature do
click_link 'Clone repository'
expect(page).to have_text("Clone repository #{project.wiki.path_with_namespace}")
expect(page).to have_text(project.wiki.http_url_to_repo(user))
expect(page).to have_text(project.wiki.http_url_to_repo)
end
end
......@@ -62,11 +62,6 @@ describe Gitlab::UrlSanitizer, lib: true do
end
end
describe '.http_credentials_for_user' do
it { expect(described_class.http_credentials_for_user(user)).to eq({ user: 'john.doe' }) }
it { expect(described_class.http_credentials_for_user('foo')).to eq({}) }
end
describe '#sanitized_url' do
it { expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git") }
end
......@@ -76,7 +71,7 @@ describe Gitlab::UrlSanitizer, lib: true do
context 'when user is given to #initialize' do
let(:url_sanitizer) do
described_class.new("https://github.com/me/project.git", credentials: described_class.http_credentials_for_user(user))
described_class.new("https://github.com/me/project.git", credentials: { user: user.username })
end
it { expect(url_sanitizer.credentials).to eq({ user: 'john.doe' }) }
......@@ -94,7 +89,7 @@ describe Gitlab::UrlSanitizer, lib: true do
context 'when user is given to #initialize' do
let(:url_sanitizer) do
described_class.new("https://github.com/me/project.git", credentials: described_class.http_credentials_for_user(user))
described_class.new("https://github.com/me/project.git", credentials: { user: user.username })
end
it { expect(url_sanitizer.full_url).to eq("https://john.doe@github.com/me/project.git") }
......
......@@ -37,21 +37,11 @@ describe ProjectWiki, models: true do
describe "#http_url_to_repo" do
let(:project) { create :empty_project }
context 'when no user is given' do
it 'returns the url to the repo without a username' do
expected_url = "#{Gitlab.config.gitlab.url}/#{subject.path_with_namespace}.git"
it 'returns the full http url to the repo' do
expected_url = "#{Gitlab.config.gitlab.url}/#{subject.path_with_namespace}.git"
expect(project_wiki.http_url_to_repo).to eq(expected_url)
expect(project_wiki.http_url_to_repo).not_to include('@')
end
end
context 'when user is given' do
it 'returns the url to the repo with the username' do
user = build_stubbed(:user)
expect(project_wiki.http_url_to_repo(user)).to start_with("http://#{user.username}@")
end
expect(project_wiki.http_url_to_repo).to eq(expected_url)
expect(project_wiki.http_url_to_repo).not_to include('@')
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