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
62874176
Commit
62874176
authored
Aug 14, 2018
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add format validation to package models
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
ae7687f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
4 deletions
+56
-4
ee/app/models/packages/maven_metadatum.rb
ee/app/models/packages/maven_metadatum.rb
+12
-3
ee/app/models/packages/package.rb
ee/app/models/packages/package.rb
+4
-1
ee/lib/ee/gitlab/regex.rb
ee/lib/ee/gitlab/regex.rb
+16
-0
ee/spec/models/packages/maven_metadatum_spec.rb
ee/spec/models/packages/maven_metadatum_spec.rb
+18
-0
ee/spec/models/packages/package_spec.rb
ee/spec/models/packages/package_spec.rb
+6
-0
No files found.
ee/app/models/packages/maven_metadatum.rb
View file @
62874176
...
...
@@ -3,7 +3,16 @@ class Packages::MavenMetadatum < ActiveRecord::Base
belongs_to
:package
validates
:package
,
presence:
true
validates
:path
,
presence:
true
validates
:app_group
,
presence:
true
validates
:app_name
,
presence:
true
validates
:path
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
maven_path_regex
}
validates
:app_group
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
maven_app_group_regex
}
validates
:app_name
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
maven_app_name_regex
}
end
ee/app/models/packages/package.rb
View file @
62874176
...
...
@@ -7,5 +7,8 @@ class Packages::Package < ActiveRecord::Base
accepts_nested_attributes_for
:maven_metadatum
validates
:project
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
package_name_regex
}
end
ee/lib/ee/gitlab/regex.rb
View file @
62874176
...
...
@@ -12,6 +12,22 @@ module EE
def
environment_scope_regex_message
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
end
def
package_name_regex
@package_name_regex
||=
/\A(([\w\-\.]*)\/)*([\w\-\.]*)\z/
.
freeze
end
def
maven_path_regex
package_name_regex
end
def
maven_app_name_regex
@maven_app_name_regex
||=
/\A[\w\-\.]+\z/
.
freeze
end
def
maven_app_group_regex
maven_app_name_regex
end
end
end
end
ee/spec/models/packages/maven_metadatum_spec.rb
View file @
62874176
...
...
@@ -8,5 +8,23 @@ RSpec.describe Packages::MavenMetadatum, type: :model do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:package
)
}
describe
'#app_name'
do
it
{
is_expected
.
to
allow_value
(
"my-app"
).
for
(
:app_name
)
}
it
{
is_expected
.
to_not
allow_value
(
"my/app"
).
for
(
:app_name
)
}
it
{
is_expected
.
to_not
allow_value
(
"my(app)"
).
for
(
:app_name
)
}
end
describe
'#app_group'
do
it
{
is_expected
.
to
allow_value
(
"my.domain.com"
).
for
(
:app_group
)
}
it
{
is_expected
.
to_not
allow_value
(
"my/domain/com"
).
for
(
:app_group
)
}
it
{
is_expected
.
to_not
allow_value
(
"my(domain)"
).
for
(
:app_group
)
}
end
describe
'#path'
do
it
{
is_expected
.
to
allow_value
(
"my/domain/com/my-app"
).
for
(
:path
)
}
it
{
is_expected
.
to
allow_value
(
"my/domain/com/my-app/1.0-SNAPSHOT"
).
for
(
:path
)
}
it
{
is_expected
.
to_not
allow_value
(
"my(domain)com.my-app"
).
for
(
:path
)
}
end
end
end
ee/spec/models/packages/package_spec.rb
View file @
62874176
...
...
@@ -9,5 +9,11 @@ RSpec.describe Packages::Package, type: :model do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
describe
'#name'
do
it
{
is_expected
.
to
allow_value
(
"my/domain/com/my-app"
).
for
(
:name
)
}
it
{
is_expected
.
to
allow_value
(
"my.app-11.07.2018"
).
for
(
:name
)
}
it
{
is_expected
.
to_not
allow_value
(
"my(dom$$$ain)com.my-app"
).
for
(
:name
)
}
end
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