diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-03-10 18:56:24 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-03-10 18:56:24 +0300 |
commit | 6ade63977a744ad361281ebeaa18271305a0192f (patch) | |
tree | f3a3c0736869809acf7ff1e0500d8cef6355a198 | |
parent | 4d7dedf7f5057911cfaf4cc8238b770dd30b4046 (diff) | |
parent | c92808ed323d70c6af00cd19fb5e4ed35ce9957d (diff) |
Merge branch 'tc-fix-project-create-500' into 'master'
Fix for creating a project through API when import_url is nil
Closes #29121
See merge request !9841
-rw-r--r-- | changelogs/unreleased/tc-fix-project-create-500.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/url_sanitizer.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/url_sanitizer_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 8 |
4 files changed, 22 insertions, 0 deletions
diff --git a/changelogs/unreleased/tc-fix-project-create-500.yml b/changelogs/unreleased/tc-fix-project-create-500.yml new file mode 100644 index 00000000000..1b746a41eab --- /dev/null +++ b/changelogs/unreleased/tc-fix-project-create-500.yml @@ -0,0 +1,4 @@ +--- +title: Fix for creating a project through API when import_url is nil +merge_request: 9841 +author: diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb index 1f0d96088cf..c81dc7e30d0 100644 --- a/lib/gitlab/url_sanitizer.rb +++ b/lib/gitlab/url_sanitizer.rb @@ -9,6 +9,8 @@ module Gitlab end def self.valid?(url) + return false unless url + Addressable::URI.parse(url.strip) true diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb index 2cb74629da8..3fd361de458 100644 --- a/spec/lib/gitlab/url_sanitizer_spec.rb +++ b/spec/lib/gitlab/url_sanitizer_spec.rb @@ -70,4 +70,12 @@ describe Gitlab::UrlSanitizer, lib: true do expect(sanitizer.full_url).to eq('user@server:project.git') end end + + describe '.valid?' do + it 'validates url strings' do + expect(described_class.valid?(nil)).to be(false) + expect(described_class.valid?('valid@project:url.git')).to be(true) + expect(described_class.valid?('123://invalid:url')).to be(false) + end + end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 77f79cd5bc7..b4b23617498 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -424,6 +424,14 @@ describe API::Projects, api: true do expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_truthy end + it 'ignores import_url when it is nil' do + project = attributes_for(:project, { import_url: nil }) + + post api('/projects', user), project + + expect(response).to have_http_status(201) + end + context 'when a visibility level is restricted' do let(:project_param) { attributes_for(:project, visibility: 'public') } |