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
b62e5009
Commit
b62e5009
authored
Dec 10, 2020
by
Philip Cunningham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter by most recent in DastSiteValidationsFinder
Returns only the most recent validation by url_base.
parent
2b2f29a8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
15 deletions
+63
-15
ee/app/finders/dast_site_validations_finder.rb
ee/app/finders/dast_site_validations_finder.rb
+7
-0
ee/app/graphql/resolvers/dast_site_validation_resolver.rb
ee/app/graphql/resolvers/dast_site_validation_resolver.rb
+1
-1
ee/app/models/dast_site_validation.rb
ee/app/models/dast_site_validation.rb
+4
-0
ee/spec/finders/dast_site_validations_finder_spec.rb
ee/spec/finders/dast_site_validations_finder_spec.rb
+29
-7
ee/spec/graphql/resolvers/dast_site_validation_resolver_spec.rb
...c/graphql/resolvers/dast_site_validation_resolver_spec.rb
+1
-1
ee/spec/models/dast_site_validation_spec.rb
ee/spec/models/dast_site_validation_spec.rb
+13
-1
ee/spec/requests/api/graphql/project/dast_site_validations_spec.rb
...equests/api/graphql/project/dast_site_validations_spec.rb
+8
-5
No files found.
ee/app/finders/dast_site_validations_finder.rb
View file @
b62e5009
...
...
@@ -10,6 +10,7 @@ class DastSiteValidationsFinder
def
execute
relation
=
DastSiteValidation
.
all
relation
=
by_most_recent
(
relation
)
relation
=
by_project
(
relation
)
relation
=
by_url_base
(
relation
)
relation
=
by_state
(
relation
)
...
...
@@ -21,6 +22,12 @@ class DastSiteValidationsFinder
attr_reader
:params
def
by_most_recent
(
relation
)
return
relation
unless
params
[
:most_recent
]
relation
.
by_most_recent
end
def
by_project
(
relation
)
return
relation
if
params
[
:project_id
].
nil?
...
...
ee/app/graphql/resolvers/dast_site_validation_resolver.rb
View file @
b62e5009
...
...
@@ -12,7 +12,7 @@ module Resolvers
def
resolve
(
**
args
)
return
DastSiteValidation
.
none
unless
allowed?
DastSiteValidationsFinder
.
new
(
project_id:
project
.
id
,
url_base:
args
[
:normalized_target_urls
]).
execute
DastSiteValidationsFinder
.
new
(
project_id:
project
.
id
,
url_base:
args
[
:normalized_target_urls
]
,
most_recent:
true
).
execute
end
private
...
...
ee/app/models/dast_site_validation.rb
View file @
b62e5009
...
...
@@ -17,6 +17,10 @@ class DastSiteValidation < ApplicationRecord
where
(
url_base:
url_base
)
end
scope
:by_most_recent
,
->
do
where
(
id:
select
(
'MAX(id) AS id'
).
group
(
:url_base
))
end
before_create
:set_normalized_url_base
enum
validation_strategy:
{
text_file:
0
,
header:
1
}
...
...
ee/spec/finders/dast_site_validations_finder_spec.rb
View file @
b62e5009
...
...
@@ -18,11 +18,17 @@ RSpec.describe DastSiteValidationsFinder do
expect
(
subject
).
to
eq
([
dast_site_validation_3
,
dast_site_validation_2
,
dast_site_validation_1
])
end
context
'filtering by
url_base
'
do
let
(
:params
)
{
{
url_base:
dast_site_validation_1
.
url_bas
e
}
}
context
'filtering by
most_recent
'
do
let
(
:params
)
{
{
most_recent:
tru
e
}
}
it
'returns the matching dast_site_validations'
do
expect
(
subject
).
to
eq
([
dast_site_validation_3
,
dast_site_validation_1
])
expect
(
subject
).
to
eq
([
dast_site_validation_3
,
dast_site_validation_2
])
end
it
'allows the results to be easily re-ordered'
do
relation
=
subject
.
reorder
(
id: :asc
)
expect
(
relation
).
to
eq
([
dast_site_validation_2
,
dast_site_validation_3
])
end
end
...
...
@@ -32,13 +38,29 @@ RSpec.describe DastSiteValidationsFinder do
it
'returns the matching dast_site_validations'
do
expect
(
subject
).
to
eq
([
dast_site_validation_2
])
end
context
'when url_base is for a different project'
do
let
(
:params
)
{
{
project_id:
dast_site_validation_2
.
project
.
id
,
url_base:
dast_site_validation_1
.
url_base
}
}
it
'returns an empty relation'
do
expect
(
subject
).
to
be_empty
end
end
end
context
'
when url_base is for a different project
'
do
let
(
:params
)
{
{
url_base:
dast_site_validation_1
.
url_base
,
project_id:
dast_site_validation_2
.
project
.
id
}
}
context
'
filtering by url_base
'
do
let
(
:params
)
{
{
url_base:
dast_site_validation_1
.
url_base
}
}
it
'returns an empty relation'
do
expect
(
subject
).
to
be_empty
it
'returns the matching dast_site_validations'
do
expect
(
subject
).
to
eq
([
dast_site_validation_3
,
dast_site_validation_1
])
end
end
context
'filtering by *'
do
let
(
:params
)
{
{
project_id:
dast_site_validation_1
.
project
.
id
,
url_base:
dast_site_validation_1
.
url_base
,
most_recent:
true
}
}
it
'returns the matching dast_site_validations'
do
expect
(
subject
).
to
eq
([
dast_site_validation_3
])
end
end
end
...
...
ee/spec/graphql/resolvers/dast_site_validation_resolver_spec.rb
View file @
b62e5009
...
...
@@ -37,7 +37,7 @@ RSpec.describe Resolvers::DastSiteValidationResolver do
it
{
is_expected
.
to
contain_exactly
(
dast_site_validation3
,
dast_site_validation1
)
}
end
context
'when one normalized_target_url
s
is specified'
do
context
'when one normalized_target_url is specified'
do
let
(
:args
)
{
{
normalized_target_urls:
[
dast_site_validation2
.
url_base
]
}
}
it
{
is_expected
.
to
contain_exactly
(
dast_site_validation2
)
}
...
...
ee/spec/models/dast_site_validation_spec.rb
View file @
b62e5009
...
...
@@ -50,7 +50,7 @@ RSpec.describe DastSiteValidation, type: :model do
describe
'by_url_base'
do
let
(
:more_dast_site_validations
)
do
create_list
(
:dast_site_validation
,
5
,
dast_site_token:
subject
.
dast_site_token
)
.
prepend
(
subject
)
create_list
(
:dast_site_validation
,
5
,
dast_site_token:
subject
.
dast_site_token
)
end
it
'includes the correct records'
do
...
...
@@ -59,6 +59,18 @@ RSpec.describe DastSiteValidation, type: :model do
expect
(
result
).
not_to
include
(
another_dast_site_validation
)
end
end
describe
'by_most_recent'
do
let
(
:more_dast_site_validations
)
do
create_list
(
:dast_site_validation
,
5
,
dast_site_token:
subject
.
dast_site_token
)
end
it
'includes the correct records'
do
result
=
described_class
.
by_most_recent
expect
(
result
).
to
contain_exactly
(
another_dast_site_validation
,
more_dast_site_validations
.
last
)
end
end
end
describe
'enums'
do
...
...
ee/spec/requests/api/graphql/project/dast_site_validations_spec.rb
View file @
b62e5009
...
...
@@ -6,11 +6,14 @@ RSpec.describe 'Query.project(fullPath).dastSiteValidations' do
include
GraphqlHelpers
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:dast_site_token
)
{
create
(
:dast_site_token
,
project:
project
,
url:
generate
(
:url
))
}
let_it_be
(
:dast_site_validation1
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token
)
}
let_it_be
(
:dast_site_validation2
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token
)
}
let_it_be
(
:dast_site_validation3
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token
)
}
let_it_be
(
:dast_site_validation4
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token
)
}
let_it_be
(
:dast_site_token1
)
{
create
(
:dast_site_token
,
project:
project
,
url:
generate
(
:url
))
}
let_it_be
(
:dast_site_token2
)
{
create
(
:dast_site_token
,
project:
project
,
url:
generate
(
:url
))
}
let_it_be
(
:dast_site_token3
)
{
create
(
:dast_site_token
,
project:
project
,
url:
generate
(
:url
))
}
let_it_be
(
:dast_site_token4
)
{
create
(
:dast_site_token
,
project:
project
,
url:
generate
(
:url
))
}
let_it_be
(
:dast_site_validation1
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token1
)
}
let_it_be
(
:dast_site_validation2
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token2
)
}
let_it_be
(
:dast_site_validation3
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token3
)
}
let_it_be
(
:dast_site_validation4
)
{
create
(
:dast_site_validation
,
dast_site_token:
dast_site_token4
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
subject
do
...
...
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