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
86147808
Commit
86147808
authored
Feb 16, 2021
by
Philip Cunningham
Committed by
charlie ablett
Feb 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing validations to DAST models
Adds model-level constraints to reflect database constraints.
parent
8f792928
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
3 deletions
+22
-3
ee/app/models/dast/profile.rb
ee/app/models/dast/profile.rb
+6
-1
ee/app/models/dast_scanner_profile.rb
ee/app/models/dast_scanner_profile.rb
+1
-1
ee/app/models/dast_site_profile.rb
ee/app/models/dast_site_profile.rb
+1
-1
ee/spec/models/dast/profile_spec.rb
ee/spec/models/dast/profile_spec.rb
+12
-0
ee/spec/models/dast_scanner_profile_spec.rb
ee/spec/models/dast_scanner_profile_spec.rb
+1
-0
ee/spec/models/dast_site_profile_spec.rb
ee/spec/models/dast_site_profile_spec.rb
+1
-0
No files found.
ee/app/models/dast/profile.rb
View file @
86147808
...
@@ -9,10 +9,11 @@ module Dast
...
@@ -9,10 +9,11 @@ module Dast
belongs_to
:dast_scanner_profile
belongs_to
:dast_scanner_profile
validates
:description
,
length:
{
maximum:
255
}
validates
:description
,
length:
{
maximum:
255
}
validates
:name
,
length:
{
maximum:
255
},
uniqueness:
{
scope: :project_id
}
validates
:name
,
length:
{
maximum:
255
},
uniqueness:
{
scope: :project_id
}
,
presence:
true
validates
:project_id
,
:dast_site_profile_id
,
:dast_scanner_profile_id
,
presence:
true
validates
:project_id
,
:dast_site_profile_id
,
:dast_scanner_profile_id
,
presence:
true
validate
:project_ids_match
validate
:project_ids_match
validate
:description_not_nil
scope
:by_project_id
,
->
(
project_id
)
do
scope
:by_project_id
,
->
(
project_id
)
do
where
(
project_id:
project_id
)
where
(
project_id:
project_id
)
...
@@ -25,6 +26,10 @@ module Dast
...
@@ -25,6 +26,10 @@ module Dast
association_project_id_matches
(
dast_scanner_profile
)
association_project_id_matches
(
dast_scanner_profile
)
end
end
def
description_not_nil
errors
.
add
(
:description
,
'can\'t be nil'
)
if
description
.
nil?
end
def
association_project_id_matches
(
association
)
def
association_project_id_matches
(
association
)
return
if
association
.
nil?
return
if
association
.
nil?
...
...
ee/app/models/dast_scanner_profile.rb
View file @
86147808
...
@@ -4,7 +4,7 @@ class DastScannerProfile < ApplicationRecord
...
@@ -4,7 +4,7 @@ class DastScannerProfile < ApplicationRecord
belongs_to
:project
belongs_to
:project
validates
:project_id
,
presence:
true
validates
:project_id
,
presence:
true
validates
:name
,
length:
{
maximum:
255
},
uniqueness:
{
scope: :project_id
}
validates
:name
,
length:
{
maximum:
255
},
uniqueness:
{
scope: :project_id
}
,
presence:
true
scope
:project_id_in
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
)
}
scope
:project_id_in
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
)
}
...
...
ee/app/models/dast_site_profile.rb
View file @
86147808
...
@@ -4,7 +4,7 @@ class DastSiteProfile < ApplicationRecord
...
@@ -4,7 +4,7 @@ class DastSiteProfile < ApplicationRecord
belongs_to
:project
belongs_to
:project
belongs_to
:dast_site
belongs_to
:dast_site
validates
:name
,
length:
{
maximum:
255
},
uniqueness:
{
scope: :project_id
}
validates
:name
,
length:
{
maximum:
255
},
uniqueness:
{
scope: :project_id
}
,
presence:
true
validates
:project_id
,
:dast_site_id
,
presence:
true
validates
:project_id
,
:dast_site_id
,
presence:
true
validate
:dast_site_project_id_fk
validate
:dast_site_project_id_fk
...
...
ee/spec/models/dast/profile_spec.rb
View file @
86147808
...
@@ -19,6 +19,7 @@ RSpec.describe Dast::Profile, type: :model do
...
@@ -19,6 +19,7 @@ RSpec.describe Dast::Profile, type: :model do
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dast_site_profile_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dast_site_profile_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dast_scanner_profile_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dast_scanner_profile_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
context
'when the project_id and dast_site_profile.project_id do not match'
do
context
'when the project_id and dast_site_profile.project_id do not match'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
...
@@ -47,6 +48,17 @@ RSpec.describe Dast::Profile, type: :model do
...
@@ -47,6 +48,17 @@ RSpec.describe Dast::Profile, type: :model do
end
end
end
end
end
end
context
'when the description is nil'
do
subject
{
build
(
:dast_profile
,
description:
nil
)
}
it
'is not valid'
do
aggregate_failures
do
expect
(
subject
.
valid?
).
to
be_falsey
expect
(
subject
.
errors
.
full_messages
).
to
include
(
'Description can\'t be nil'
)
end
end
end
end
end
describe
'scopes'
do
describe
'scopes'
do
...
...
ee/spec/models/dast_scanner_profile_spec.rb
View file @
86147808
...
@@ -14,6 +14,7 @@ RSpec.describe DastScannerProfile, type: :model do
...
@@ -14,6 +14,7 @@ RSpec.describe DastScannerProfile, type: :model do
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
end
end
describe
'scopes'
do
describe
'scopes'
do
...
...
ee/spec/models/dast_site_profile_spec.rb
View file @
86147808
...
@@ -16,6 +16,7 @@ RSpec.describe DastSiteProfile, type: :model do
...
@@ -16,6 +16,7 @@ RSpec.describe DastSiteProfile, type: :model do
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dast_site_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dast_site_id
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
context
'when the project_id and dast_site.project_id do not match'
do
context
'when the project_id and dast_site.project_id do not match'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
...
...
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