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
b71fedce
Commit
b71fedce
authored
Oct 01, 2020
by
Philip Cunningham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use calculated status for DastSiteProfile query
Replace stubbed field with validation status from the database.
parent
479c7bf2
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
75 additions
and
13 deletions
+75
-13
ee/app/finders/dast_site_profiles_finder.rb
ee/app/finders/dast_site_profiles_finder.rb
+2
-2
ee/app/graphql/ee/types/project_type.rb
ee/app/graphql/ee/types/project_type.rb
+1
-1
ee/app/graphql/types/dast_site_profile_type.rb
ee/app/graphql/types/dast_site_profile_type.rb
+1
-1
ee/app/models/dast_site_profile.rb
ee/app/models/dast_site_profile.rb
+9
-1
ee/app/models/dast_site_validation.rb
ee/app/models/dast_site_validation.rb
+3
-1
ee/changelogs/unreleased/replace-stubbed-dast-site-validation-status-245214.yml
...ed/replace-stubbed-dast-site-validation-status-245214.yml
+5
-0
ee/spec/factories/dast_sites.rb
ee/spec/factories/dast_sites.rb
+11
-1
ee/spec/finders/dast_site_profiles_finder_spec.rb
ee/spec/finders/dast_site_profiles_finder_spec.rb
+10
-0
ee/spec/graphql/types/dast_site_profile_type_spec.rb
ee/spec/graphql/types/dast_site_profile_type_spec.rb
+1
-1
ee/spec/models/dast_site_profile_spec.rb
ee/spec/models/dast_site_profile_spec.rb
+29
-2
ee/spec/requests/api/graphql/project/dast_site_profiles_spec.rb
...c/requests/api/graphql/project/dast_site_profiles_spec.rb
+3
-3
No files found.
ee/app/finders/dast_site_profiles_finder.rb
View file @
b71fedce
...
...
@@ -6,7 +6,7 @@ class DastSiteProfilesFinder
end
def
execute
relation
=
DastSiteProfile
.
with_dast_site
relation
=
DastSiteProfile
.
with_dast_site
_and_validation
relation
=
by_id
(
relation
)
relation
=
by_project
(
relation
)
relation
...
...
@@ -20,7 +20,7 @@ class DastSiteProfilesFinder
def
by_id
(
relation
)
return
relation
if
params
[
:id
].
nil?
relation
.
where
(
id:
params
[
:id
])
relation
.
where
(
id:
params
[
:id
])
.
limit
(
1
)
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
ee/app/graphql/ee/types/project_type.rb
View file @
b71fedce
...
...
@@ -100,7 +100,7 @@ module EE
::
Types
::
DastSiteProfileType
.
connection_type
,
null:
true
,
description:
'DAST Site Profiles associated with the project'
,
resolve:
->
(
obj
,
_args
,
_ctx
)
{
obj
.
dast_site_profiles
.
with_dast_si
te
}
resolve:
->
(
obj
,
_args
,
_ctx
)
{
DastSiteProfilesFinder
.
new
(
project_id:
obj
.
id
).
execu
te
}
field
:cluster_agent
,
::
Types
::
Clusters
::
AgentType
,
...
...
ee/app/graphql/types/dast_site_profile_type.rb
View file @
b71fedce
...
...
@@ -28,6 +28,6 @@ module Types
field
:validation_status
,
Types
::
DastSiteProfileValidationStatusEnum
,
null:
true
,
description:
'The current validation status of the site profile'
,
resolve:
->
(
_obj
,
_args
,
_ctx
)
{
Types
::
DastSiteProfileValidationStatusEnum
.
enum
[
'pending_validation'
]
}
resolve:
->
(
obj
,
_args
,
_ctx
)
{
"
#{
obj
.
status
.
upcase
}
_VALIDATION"
}
end
end
ee/app/models/dast_site_profile.rb
View file @
b71fedce
...
...
@@ -8,10 +8,18 @@ class DastSiteProfile < ApplicationRecord
validates
:project_id
,
:dast_site_id
,
presence:
true
validate
:dast_site_project_id_fk
scope
:with_dast_site
,
->
{
includes
(
:dast_site
)
}
scope
:with_dast_site
_and_validation
,
->
{
includes
(
dast_site: :dast_site_validation
)
}
after_destroy
:cleanup_dast_site
delegate
:dast_site_validation
,
to: :dast_site
,
allow_nil:
true
def
status
return
DastSiteValidation
::
INITIAL_STATE
unless
dast_site_validation
dast_site_validation
.
state
end
private
def
cleanup_dast_site
...
...
ee/app/models/dast_site_validation.rb
View file @
b71fedce
...
...
@@ -21,7 +21,9 @@ class DastSiteValidation < ApplicationRecord
"
#{
url_base
}
/
#{
url_path
}
"
end
state_machine
:state
,
initial: :pending
do
INITIAL_STATE
=
:pending
state_machine
:state
,
initial:
INITIAL_STATE
do
event
:start
do
transition
pending: :inprogress
end
...
...
ee/changelogs/unreleased/replace-stubbed-dast-site-validation-status-245214.yml
0 → 100644
View file @
b71fedce
---
title
:
Change stubbed DastSiteProfile#status for calculated status
merge_request
:
44133
author
:
type
:
changed
ee/spec/factories/dast_sites.rb
View file @
b71fedce
...
...
@@ -2,7 +2,17 @@
FactoryBot
.
define
do
factory
:dast_site
do
project
url
{
generate
(
:url
)
}
before
(
:create
)
do
|
dast_site
|
dast_site
.
project
||=
FactoryBot
.
create
(
:project
)
dast_site
.
dast_site_validation
||=
FactoryBot
.
create
(
:dast_site_validation
,
dast_site_token:
FactoryBot
.
create
(
:dast_site_token
,
project:
dast_site
.
project
)
)
end
end
end
ee/spec/finders/dast_site_profiles_finder_spec.rb
View file @
b71fedce
...
...
@@ -31,6 +31,16 @@ RSpec.describe DastSiteProfilesFinder do
expect
(
recorder
.
count
).
to
be_zero
end
it
'eager loads the dast_site_validation association'
do
dast_site_profile1
=
subject
.
first!
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
dast_site_profile1
.
dast_site_validation
end
expect
(
recorder
.
count
).
to
be_zero
end
context
'filtering by id'
do
let
(
:params
)
{
{
id:
dast_site_profile1
.
id
}
}
...
...
ee/spec/graphql/types/dast_site_profile_type_spec.rb
View file @
b71fedce
...
...
@@ -84,7 +84,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do
end
describe
'validation_status field'
do
it
'is
a placeholder
validation status'
do
it
'is
the
validation status'
do
expect
(
first_dast_site_profile
[
'validationStatus'
]).
to
eq
(
'PENDING_VALIDATION'
)
end
end
...
...
ee/spec/models/dast_site_profile_spec.rb
View file @
b71fedce
...
...
@@ -31,15 +31,23 @@ RSpec.describe DastSiteProfile, type: :model do
end
describe
'scopes'
do
describe
'.with_dast_site'
do
describe
'.with_dast_site_and_validation'
do
before
do
subject
.
dast_site_validation
.
update!
(
state: :failed
)
end
it
'eager loads the association'
do
subject
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
subject
.
dast_site
subject
.
dast_site_validation
end
expect
(
recorder
.
count
).
to
be_zero
aggregate_failures
do
expect
(
subject
.
status
).
to
eq
(
'failed'
)
# ensures guard passed
expect
(
recorder
.
count
).
to
be_zero
end
end
end
end
...
...
@@ -63,4 +71,23 @@ RSpec.describe DastSiteProfile, type: :model do
end
end
end
describe
'#status'
do
context
'when dast_site_validation association does not exist'
do
it
'is pending'
do
subject
.
dast_site
.
update!
(
dast_site_validation_id:
nil
)
aggregate_failures
do
expect
(
subject
.
dast_site_validation
).
to
be_nil
expect
(
subject
.
status
).
to
eq
(
:pending
)
end
end
end
context
'when dast_site_validation association does exist'
do
it
'is dast_site_validation#state'
do
expect
(
subject
.
status
).
to
eq
(
subject
.
dast_site_validation
.
state
)
end
end
end
end
ee/spec/requests/api/graphql/project/dast_site_profiles_spec.rb
View file @
b71fedce
...
...
@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec
.
describe
'Query.project(fullPath).dastSiteProfiles'
do
include
GraphqlHelpers
let_it_be
(
:
dast_site_profile
)
{
create
(
:dast_site_profile
)
}
let_it_be
(
:
project
)
{
dast_site_profile
.
project
}
let_it_be
(
:
project
)
{
create
(
:project
)
}
let_it_be
(
:
dast_site_profile
)
{
create
(
:dast_site_profile
,
project:
project
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let
(
:query
)
do
...
...
@@ -76,7 +76,7 @@ RSpec.describe 'Query.project(fullPath).dastSiteProfiles' do
expect
(
first_dast_site_profile_response
[
'id'
]).
to
eq
(
dast_site_profile
.
to_global_id
.
to_s
)
end
it
'eager loads the dast site'
do
it
'eager loads the dast site
and dast site validation
'
do
control
=
ActiveRecord
::
QueryRecorder
.
new
do
post_graphql
(
query
,
...
...
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