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
7e14f096
Commit
7e14f096
authored
Oct 27, 2020
by
ggelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds some composer version validation
parent
f375c51b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
1 deletion
+26
-1
app/models/packages/package.rb
app/models/packages/package.rb
+6
-1
lib/gitlab/regex.rb
lib/gitlab/regex.rb
+4
-0
spec/lib/gitlab/regex_spec.rb
spec/lib/gitlab/regex_spec.rb
+9
-0
spec/models/packages/package_spec.rb
spec/models/packages/package_spec.rb
+7
-0
No files found.
app/models/packages/package.rb
View file @
7e14f096
...
...
@@ -37,12 +37,13 @@ class Packages::Package < ApplicationRecord
validate
:package_already_taken
,
if: :npm?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
conan_recipe_component_regex
},
if: :conan?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
generic_package_name_regex
},
if: :generic?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
semver_regex
},
if: :npm?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
nuget_version_regex
},
if: :nuget?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
conan_recipe_component_regex
},
if: :conan?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
maven_version_regex
},
if:
->
{
version?
&&
maven?
}
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
pypi_version_regex
},
if: :pypi?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
prefixed_semver_regex
},
if: :golang?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
semver_regex
},
if:
->
{
composer_tag_version?
||
npm?
}
validates
:version
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
generic_package_version_regex
},
...
...
@@ -174,6 +175,10 @@ class Packages::Package < ApplicationRecord
private
def
composer_tag_version?
composer?
&&
!
Gitlab
::
Regex
.
composer_dev_version_regex
.
match
(
version
.
to_s
)
end
def
valid_conan_package_recipe
recipe_exists
=
project
.
packages
.
conan
...
...
lib/gitlab/regex.rb
View file @
7e14f096
...
...
@@ -22,6 +22,10 @@ module Gitlab
@composer_package_version_regex
||=
%r{^v?(
\d
+(
\.
(
\d
+|x))*(-.+)?)}
.
freeze
end
def
composer_dev_version_regex
@composer_dev_version_regex
||=
%r{(^dev-)|(-dev$)}
.
freeze
end
def
package_name_regex
@package_name_regex
||=
%r{
\A\@
?(([
\w\-\.\+
]*)
\/
)*([
\w\-\.
]+)@?(([
\w\-\.\+
]*)
\/
)*([
\w\-\.
]*)
\z
}
.
freeze
end
...
...
spec/lib/gitlab/regex_spec.rb
View file @
7e14f096
...
...
@@ -243,6 +243,15 @@ RSpec.describe Gitlab::Regex do
it
{
is_expected
.
not_to
match
(
'!!()()'
)
}
end
describe
'.composer_dev_version_regex'
do
subject
{
described_class
.
composer_dev_version_regex
}
it
{
is_expected
.
to
match
(
'dev-master'
)
}
it
{
is_expected
.
to
match
(
'1.x-dev'
)
}
it
{
is_expected
.
not_to
match
(
'foobar'
)
}
it
{
is_expected
.
not_to
match
(
'1.2.3'
)
}
end
describe
'.conan_recipe_component_regex'
do
subject
{
described_class
.
conan_recipe_component_regex
}
...
...
spec/models/packages/package_spec.rb
View file @
7e14f096
...
...
@@ -156,6 +156,13 @@ RSpec.describe Packages::Package, type: :model do
it
{
is_expected
.
not_to
allow_value
(
'%2e%2e%2f1.2.3'
).
for
(
:version
)
}
end
context
'composer package'
do
it_behaves_like
'validating version to be SemVer compliant for'
,
:composer_package
it
{
is_expected
.
to
allow_value
(
'dev-master'
).
for
(
:version
)
}
it
{
is_expected
.
to
allow_value
(
'2.x-dev'
).
for
(
:version
)
}
end
context
'maven package'
do
subject
{
build_stubbed
(
:maven_package
)
}
...
...
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