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
92120a0f
Commit
92120a0f
authored
Jan 25, 2021
by
Philip Cunningham
Committed by
Matthias Käppler
Jan 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Dast::ProfilesFinder to retreive dast_profiles
Adds new finder for DAST saved scans feature.
parent
30cf2c96
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
1 deletion
+126
-1
ee/app/finders/dast/profiles_finder.rb
ee/app/finders/dast/profiles_finder.rb
+47
-0
ee/app/models/dast/profile.rb
ee/app/models/dast/profile.rb
+4
-0
ee/spec/factories/dast_scanner_profiles.rb
ee/spec/factories/dast_scanner_profiles.rb
+3
-1
ee/spec/finders/dast/profiles_finder_spec.rb
ee/spec/finders/dast/profiles_finder_spec.rb
+57
-0
ee/spec/models/dast/profile_spec.rb
ee/spec/models/dast/profile_spec.rb
+15
-0
No files found.
ee/app/finders/dast/profiles_finder.rb
0 → 100644
View file @
92120a0f
# frozen_string_literal: true
module
Dast
class
ProfilesFinder
DEFAULT_SORT
=
{
id: :asc
}.
freeze
def
initialize
(
params
=
{})
@params
=
params
end
def
execute
relation
=
default_relation
relation
=
by_id
(
relation
)
relation
=
by_project
(
relation
)
sort
(
relation
)
end
private
attr_reader
:params
# rubocop: disable CodeReuse/ActiveRecord
def
default_relation
Dast
::
Profile
.
limit
(
100
)
end
# rubocop: enable CodeReuse/ActiveRecord
def
by_id
(
relation
)
return
relation
if
params
[
:id
].
nil?
relation
.
id_in
(
params
[
:id
])
end
def
by_project
(
relation
)
return
relation
if
params
[
:project_id
].
nil?
relation
.
by_project_id
(
params
[
:project_id
])
end
# rubocop: disable CodeReuse/ActiveRecord
def
sort
(
relation
)
relation
.
order
(
DEFAULT_SORT
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
ee/app/models/dast/profile.rb
View file @
92120a0f
...
...
@@ -14,6 +14,10 @@ module Dast
validate
:project_ids_match
scope
:by_project_id
,
->
(
project_id
)
do
where
(
project_id:
project_id
)
end
private
def
project_ids_match
...
...
ee/spec/factories/dast_scanner_profiles.rb
View file @
92120a0f
...
...
@@ -2,7 +2,9 @@
FactoryBot
.
define
do
factory
:dast_scanner_profile
do
name
{
FFaker
::
Product
.
product_name
}
sequence
:name
do
|
i
|
"
#{
FFaker
::
Product
.
product_name
.
truncate
(
200
)
}
-
#{
i
}
"
end
before
(
:create
)
do
|
dast_scanner_profile
|
dast_scanner_profile
.
project
||=
FactoryBot
.
create
(
:project
)
...
...
ee/spec/finders/dast/profiles_finder_spec.rb
0 → 100644
View file @
92120a0f
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Dast
::
ProfilesFinder
do
let_it_be
(
:project1
)
{
create
(
:project
)
}
let_it_be
(
:project2
)
{
create
(
:project
)
}
let_it_be
(
:dast_profile1
)
{
create
(
:dast_profile
,
project:
project1
)
}
let_it_be
(
:dast_profile2
)
{
create
(
:dast_profile
,
project:
project2
)
}
let_it_be
(
:dast_profile3
)
{
create
(
:dast_profile
,
project:
project1
)
}
let
(
:params
)
{
{}
}
subject
do
described_class
.
new
(
params
).
execute
end
describe
'#execute'
do
it
'returns dast_profiles limited to 100 records'
do
aggregate_failures
do
expect
(
Dast
::
Profile
).
to
receive
(
:limit
).
with
(
100
).
and_call_original
expect
(
subject
).
to
contain_exactly
(
dast_profile1
,
dast_profile2
,
dast_profile3
)
end
end
context
'filtering by id'
do
let
(
:params
)
{
{
id:
dast_profile1
.
id
}
}
it
'returns the matching dast_profile'
do
expect
(
subject
).
to
contain_exactly
(
dast_profile1
)
end
end
context
'filtering by project_id'
do
let
(
:params
)
{
{
project_id:
project1
.
id
}
}
it
'returns the matching dast_profiles'
do
expect
(
subject
).
to
contain_exactly
(
dast_profile1
,
dast_profile3
)
end
end
context
'when the dast_profile does not exist'
do
let
(
:params
)
{
{
project_id:
0
}
}
it
'returns an empty relation'
do
expect
(
subject
).
to
be_empty
end
end
context
'sorting'
do
it
'orders by id asc by default'
do
expect
(
subject
).
to
be_sorted
(
:id
,
:asc
)
end
end
end
end
ee/spec/models/dast/profile_spec.rb
View file @
92120a0f
...
...
@@ -48,4 +48,19 @@ RSpec.describe Dast::Profile, type: :model do
end
end
end
describe
'scopes'
do
describe
'by_project_id'
do
it
'includes the correct records'
do
another_dast_profile
=
create
(
:dast_profile
)
result
=
described_class
.
by_project_id
(
subject
.
project_id
)
aggregate_failures
do
expect
(
result
).
to
include
(
subject
)
expect
(
result
).
not_to
include
(
another_dast_profile
)
end
end
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