Commit ad0f8f12 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'issue_17065' into 'master'

Delete ProjectImportData record only if Project is not a mirror.

This fix ensure we always use the full import URL when syncing the
mirror.

REF: https://gitlab.com/gitlab-org/gitlab-ce/issues/17065

See merge request !370
parents a8185038 ea47850f
......@@ -269,7 +269,7 @@ class Project < ActiveRecord::Base
state :failed
after_transition any => :started, do: :schedule_add_import_job
after_transition any => :finished, do: :clear_import_data
after_transition any => :finished, do: :reset_cache_and_import_attrs
after_transition started: :finished do |project, transaction|
if project.mirror?
......@@ -453,12 +453,12 @@ class Project < ActiveRecord::Base
end
end
def clear_import_data
def reset_cache_and_import_attrs
update(import_error: nil)
ProjectCacheWorker.perform_async(self.id)
self.import_data.destroy if self.import_data
self.import_data.destroy if !mirror? && import_data
end
def import_url=(value)
......
......@@ -894,4 +894,27 @@ describe Project, models: true do
end
end
end
describe 'handling import URL' do
context 'when project is a mirror' do
it 'returns the full URL' do
project = create(:project, :mirror, import_url: 'http://user:pass@test.com')
project.import_finish
expect(project.reload.import_url).to eq('http://user:pass@test.com')
end
end
context 'when project is not a mirror' do
it 'returns the sanitized URL' do
project = create(:project, import_status: 'started', import_url: 'http://user:pass@test.com')
project.import_finish
expect(project.reload.import_url).to eq('http://test.com')
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