Add project.dastProfiles GraphQL field
Background
a Dast::Profile
is a description of how to run an on-demand dast
scan. it is comprised of a name
and description
and is associated with both a DastSiteProfile
and a DastScannerProfile
.
What does this MR do?
adds project.dastProfiles
field.
Why?
to allow frontend to manage dast_profiles
.
Related Issue(s)
Example Query
{
project(fullPath: "root/rails-webgoat") {
dastProfiles(first: 3) {
nodes {
id
name
description
dastSiteProfile {
id
profileName
}
dastScannerProfile {
id
profileName
}
editPath
}
}
}
}
Feature Flag
echo "Feature.enable(:dast_saved_scans)" | rails c
Database
dast_profiles
is a brand new table, so i have opted to create some records locally for analysis. we anticipate an ee
customer to have a handful of dast_profiles
for a given project
.
Setup
[1] pry(#<RSpec::ExampleGroups::DastProfilesFinder::Execute>)> Project.count
=> 50
[2] pry(#<RSpec::ExampleGroups::DastProfilesFinder::Execute>)> DastSite.count
=> 50
[3] pry(#<RSpec::ExampleGroups::DastProfilesFinder::Execute>)> DastSiteProfile.count
=> 1000
[4] pry(#<RSpec::ExampleGroups::DastProfilesFinder::Execute>)> DastScannerProfile.count
=> 1000
[5] pry(#<RSpec::ExampleGroups::DastProfilesFinder::Execute>)> Dast::Profile.count
=> 100000
projects = Array.new(50) { create(:project) }
dast_sites = Array.new(50) { create(:dast_site, project: projects.sample) }
dast_site_profiles = []
dast_scanner_profiles = []
1000.times do
dast_site = dast_sites.sample
project = dast_site.project
dast_site_profiles.push(
build(:dast_site_profile, project: project, dast_site: dast_site, created_at: Time.now.utc, updated_at: Time.now.utc).attributes.except('id')
)
dast_scanner_profiles.push(
build(:dast_scanner_profile, project: project, created_at: Time.now.utc, updated_at: Time.now.utc).attributes.except('id')
)
end
project_ids = dast_site_profiles.map { |dast_site_profile| dast_site_profile['project_id'] }
dast_site_profile_ids = DastSiteProfile.insert_all(dast_site_profiles).rows.map(&:first)
dast_scanner_profile_ids = DastScannerProfile.insert_all(dast_scanner_profiles).rows.map(&:first)
triples = project_ids.zip(dast_site_profile_ids, dast_scanner_profile_ids)
dast_profile_attrs = Array.new(100000) do
row = triples.sample
project_id = row[0]
dast_site_profile_id = row[1]
dast_scanner_profile_id = row[2]
build(:dast_profile, project_id: project_id, dast_site_profile_id: dast_site_profile_id, dast_scanner_profile_id: dast_scanner_profile_id, created_at: Time.now.utc, updated_at: Time.now.utc)
.attributes
.except('id')
end
result = Dast::Profile.insert_all(dast_profile_attrs)
id
By SELECT "dast_profiles".* FROM "dast_profiles" WHERE "dast_profiles"."id" = 42095 ORDER BY "dast_profiles"."id" DESC
Index Scan using dast_profiles_pkey on dast_profiles (cost=0.29..2.31 rows=1 width=112) (actual time=0.007..0.008 rows=1 loops=1)
Index Cond: (id = 42095)
Planning Time: 0.090 ms
Execution Time: 0.022 ms
project_id
By SELECT "dast_profiles".* FROM "dast_profiles" WHERE "dast_profiles"."project_id" = 19 ORDER BY "dast_profiles"."id" DESC
Sort (cost=413.16..414.25 rows=436 width=112) (actual time=1.456..1.617 rows=1671 loops=1)
Sort Key: id DESC
Sort Method: quicksort Memory: 284kB
-> Index Scan using index_dast_profiles_on_project_id_and_name on dast_profiles (cost=0.42..394.05 rows=436 width=112) (actual time=0.007..1.076 rows=1671 loops=1)
Index Cond: (project_id = 19)
Planning Time: 0.070 ms
Execution Time: 1.739 ms
Composite
SELECT "dast_profiles".* FROM "dast_profiles" WHERE "dast_profiles"."id" = 42095 AND "dast_profiles"."project_id" = 7 ORDER BY "dast_profiles"."id" DESC
Index Scan using dast_profiles_pkey on dast_profiles (cost=0.29..2.31 rows=1 width=112) (actual time=0.013..0.013 rows=1 loops=1)
Index Cond: (id = 42095)
Filter: (project_id = 7)
Planning Time: 0.076 ms
Execution Time: 0.027 m
Does this MR meet the acceptance criteria?
Conformity
-
[ ] Changelog entrybehind feature flag -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Philip Cunningham