fixes a few issues to do with import_url not being saved correctly for imports. This should prevent the import_data to be created when it should not and output an error properly validating before creating it.

This commit is contained in:
James Lopez 2016-07-12 16:21:28 +02:00
parent b7ba5fa06b
commit ad6ff22380
3 changed files with 23 additions and 5 deletions

View File

@ -162,7 +162,7 @@ class Project < ActiveRecord::Base
validates :namespace, presence: true
validates_uniqueness_of :name, scope: :namespace_id
validates_uniqueness_of :path, scope: :namespace_id
validates :import_url, addressable_url: true, if: :external_import?
validates :import_url, addressable_url: true, if: :import_url
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create
validate :avatar_type,
@ -464,8 +464,8 @@ class Project < ActiveRecord::Base
return super(value) unless Gitlab::UrlSanitizer.valid?(value)
import_url = Gitlab::UrlSanitizer.new(value)
create_or_update_import_data(credentials: import_url.credentials)
super(import_url.sanitized_url)
create_or_update_import_data(credentials: import_url.credentials) if valid?
end
def import_url

View File

@ -43,7 +43,7 @@ module Projects
def import_repository
begin
gitlab_shell.import_repository(project.repository_storage_path, project.path_with_namespace, project.import_url)
rescue Gitlab::Shell::Error => e
rescue => e
raise Error, "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}"
end
end

View File

@ -130,17 +130,35 @@ describe Project, models: true do
end
end
it 'should not allow an invalid URI as import_url' do
it 'does not allow an invalid URI as import_url' do
project2 = build(:project, import_url: 'invalid://')
expect(project2).not_to be_valid
end
it 'should allow a valid URI as import_url' do
it 'does allow a valid URI as import_url' do
project2 = build(:project, import_url: 'ssh://test@gitlab.com/project.git')
expect(project2).to be_valid
end
it 'does not allow to introduce an empty URI' do
project2 = build(:project, import_url: '')
expect(project2).not_to be_valid
end
it 'does not produce import data on an empty URI' do
project2 = build(:project, import_url: '')
expect(project2.import_data).to be_nil
end
it 'does not produce import data on an invalid URI' do
project2 = build(:project, import_url: 'test://')
expect(project2.import_data).to be_nil
end
end
describe 'default_scope' do