Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1c87bacb
Commit
1c87bacb
authored
Sep 04, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a regression breaking projects with an empty import URL
parent
0ae313c4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
22 deletions
+33
-22
app/validators/addressable_url_validator.rb
app/validators/addressable_url_validator.rb
+1
-3
changelogs/unreleased-ee/3288-fix-repository-mirroring-when-url-is-empty-string.yml
...288-fix-repository-mirroring-when-url-is-empty-string.yml
+5
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+2
-1
lib/gitlab/url_sanitizer.rb
lib/gitlab/url_sanitizer.rb
+1
-1
spec/ee/spec/models/ee/project_spec.rb
spec/ee/spec/models/ee/project_spec.rb
+23
-17
spec/lib/gitlab/url_sanitizer_spec.rb
spec/lib/gitlab/url_sanitizer_spec.rb
+1
-0
No files found.
app/validators/addressable_url_validator.rb
View file @
1c87bacb
...
@@ -29,9 +29,7 @@ class AddressableUrlValidator < ActiveModel::EachValidator
...
@@ -29,9 +29,7 @@ class AddressableUrlValidator < ActiveModel::EachValidator
private
private
def
valid_url?
(
value
)
def
valid_url?
(
value
)
return
false
unless
value
valid_uri?
(
value
)
&&
valid_protocol?
(
value
)
valid_protocol?
(
value
)
&&
valid_uri?
(
value
)
end
end
def
valid_uri?
(
value
)
def
valid_uri?
(
value
)
...
...
changelogs/unreleased-ee/3288-fix-repository-mirroring-when-url-is-empty-string.yml
0 → 100644
View file @
1c87bacb
---
title
:
Fix a regression breaking projects with an empty import URL
merge_request
:
2824
author
:
type
:
fixed
ee/app/models/ee/project.rb
View file @
1c87bacb
...
@@ -384,7 +384,8 @@ module EE
...
@@ -384,7 +384,8 @@ module EE
def
username_only_import_url
=
(
value
)
def
username_only_import_url
=
(
value
)
unless
::
Gitlab
::
UrlSanitizer
.
valid?
(
value
)
unless
::
Gitlab
::
UrlSanitizer
.
valid?
(
value
)
self
.
import_url
=
value
self
.
import_url
=
value
return
self
.
import_data
&
.
user
=
nil
return
value
end
end
url
=
::
Gitlab
::
UrlSanitizer
.
new
(
value
)
url
=
::
Gitlab
::
UrlSanitizer
.
new
(
value
)
...
...
lib/gitlab/url_sanitizer.rb
View file @
1c87bacb
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
end
end
def
self
.
valid?
(
url
)
def
self
.
valid?
(
url
)
return
false
unless
url
return
false
unless
url
.
present?
Addressable
::
URI
.
parse
(
url
.
strip
)
Addressable
::
URI
.
parse
(
url
.
strip
)
...
...
spec/ee/spec/models/ee/project_spec.rb
View file @
1c87bacb
...
@@ -814,28 +814,24 @@ describe Project do
...
@@ -814,28 +814,24 @@ describe Project do
end
end
describe
'#username_only_import_url'
do
describe
'#username_only_import_url'
do
def
build_project
(
username:
'user'
,
password:
'password'
)
where
(
:import_url
,
:username
,
:expected_import_url
)
do
build
(
:project
,
import_url:
'http://example.com'
).
tap
do
|
project
|
''
|
'foo'
|
''
project
.
build_import_data
(
credentials:
{
user:
username
,
password:
password
})
''
|
''
|
''
end
''
|
nil
|
''
end
it
'shows the bare url when no username is present'
do
nil
|
'foo'
|
nil
project
=
build_project
(
username:
nil
)
nil
|
''
|
nil
nil
|
nil
|
nil
expect
(
project
.
username_only_import_url
).
to
eq
(
'http://example.com'
)
'http://example.com'
|
'foo'
|
'http://foo@example.com'
'http://example.com'
|
''
|
'http://example.com'
'http://example.com'
|
nil
|
'http://example.com'
end
end
it
'shows the URL with username when present'
do
with_them
do
project
=
build_project
(
password:
nil
)
let
(
:project
)
{
build
(
:project
,
import_url:
import_url
,
import_data_attributes:
{
user:
username
,
password:
'password'
})
}
expect
(
project
.
username_only_import_url
).
to
eq
(
'http://user@example.com'
)
it
{
expect
(
project
.
username_only_import_url
).
to
eq
(
expected_import_url
)
}
end
it
'excludes the pasword when present'
do
project
=
build_project
expect
(
project
.
username_only_import_url
).
to
eq
(
'http://user@example.com'
)
end
end
end
end
...
@@ -855,5 +851,15 @@ describe Project do
...
@@ -855,5 +851,15 @@ describe Project do
expect
(
project
.
import_url
).
to
eq
(
'http://user:pass@example.com'
)
expect
(
project
.
import_url
).
to
eq
(
'http://user:pass@example.com'
)
expect
(
project
.
import_data
.
password
).
to
eq
(
'pass'
)
expect
(
project
.
import_data
.
password
).
to
eq
(
'pass'
)
end
end
it
'clears the username if passed the empty string'
do
project
=
build
(
:project
,
import_url:
'http://olduser:pass@old.example.com'
)
project
.
username_only_import_url
=
''
expect
(
project
.
username_only_import_url
).
to
eq
(
''
)
expect
(
project
.
import_url
).
to
eq
(
''
)
expect
(
project
.
import_data
.
user
).
to
be_nil
expect
(
project
.
import_data
.
password
).
to
eq
(
'pass'
)
end
end
end
end
end
spec/lib/gitlab/url_sanitizer_spec.rb
View file @
1c87bacb
...
@@ -57,6 +57,7 @@ describe Gitlab::UrlSanitizer do
...
@@ -57,6 +57,7 @@ describe Gitlab::UrlSanitizer do
describe
'.valid?'
do
describe
'.valid?'
do
it
'validates url strings'
do
it
'validates url strings'
do
expect
(
described_class
.
valid?
(
nil
)).
to
be
(
false
)
expect
(
described_class
.
valid?
(
nil
)).
to
be
(
false
)
expect
(
described_class
.
valid?
(
''
)).
to
be
(
false
)
expect
(
described_class
.
valid?
(
'valid@project:url.git'
)).
to
be
(
true
)
expect
(
described_class
.
valid?
(
'valid@project:url.git'
)).
to
be
(
true
)
expect
(
described_class
.
valid?
(
'123://invalid:url'
)).
to
be
(
false
)
expect
(
described_class
.
valid?
(
'123://invalid:url'
)).
to
be
(
false
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment