Commit b0bb680f authored by Sean McGivern's avatar Sean McGivern

Merge branch...

Merge branch 'philipcunningham-add-optional-branch-names-to-dast-site-create-and-update-322526' into 'master'

Add ability to set dast_profiles.branch_name

See merge request gitlab-org/gitlab!55138
parents e3ac6c9d 6a9af12e
...@@ -29,6 +29,11 @@ module Mutations ...@@ -29,6 +29,11 @@ module Mutations
description: 'The description of the profile. Defaults to an empty string.', description: 'The description of the profile. Defaults to an empty string.',
default_value: '' default_value: ''
argument :branch_name, GraphQL::STRING_TYPE,
required: false,
description: 'The associated branch. Will be ignored ' \
'if `dast_branch_selection` feature flag is disabled.'
argument :dast_site_profile_id, ::Types::GlobalIDType[::DastSiteProfile], argument :dast_site_profile_id, ::Types::GlobalIDType[::DastSiteProfile],
required: true, required: true,
description: 'ID of the site profile to be associated.' description: 'ID of the site profile to be associated.'
...@@ -44,7 +49,7 @@ module Mutations ...@@ -44,7 +49,7 @@ module Mutations
authorize :create_on_demand_dast_scan authorize :create_on_demand_dast_scan
def resolve(full_path:, name:, description: '', dast_site_profile_id:, dast_scanner_profile_id:, run_after_create: false) def resolve(full_path:, name:, description: '', branch_name: nil, dast_site_profile_id:, dast_scanner_profile_id:, run_after_create: false)
project = authorized_find!(full_path) project = authorized_find!(full_path)
raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless allowed?(project) raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless allowed?(project)
...@@ -63,6 +68,7 @@ module Mutations ...@@ -63,6 +68,7 @@ module Mutations
project: project, project: project,
name: name, name: name,
description: description, description: description,
branch_name: feature_flagged_branch_name(project, branch_name),
dast_site_profile: dast_site_profile, dast_site_profile: dast_site_profile,
dast_scanner_profile: dast_scanner_profile, dast_scanner_profile: dast_scanner_profile,
run_after_create: run_after_create run_after_create: run_after_create
...@@ -80,6 +86,12 @@ module Mutations ...@@ -80,6 +86,12 @@ module Mutations
project.feature_available?(:security_on_demand_scans) && project.feature_available?(:security_on_demand_scans) &&
Feature.enabled?(:dast_saved_scans, project, default_enabled: :yaml) Feature.enabled?(:dast_saved_scans, project, default_enabled: :yaml)
end end
def feature_flagged_branch_name(project, branch_name)
return unless Feature.enabled?(:dast_branch_selection, project, default_enabled: :yaml)
branch_name
end
end end
end end
end end
......
...@@ -39,6 +39,11 @@ module Mutations ...@@ -39,6 +39,11 @@ module Mutations
description: 'The description of the profile. Defaults to an empty string.', description: 'The description of the profile. Defaults to an empty string.',
default_value: '' default_value: ''
argument :branch_name, GraphQL::STRING_TYPE,
required: false,
description: 'The associated branch. Will be ignored ' \
'if `dast_branch_selection` feature flag is disabled.'
argument :dast_site_profile_id, SiteProfileID, argument :dast_site_profile_id, SiteProfileID,
required: false, required: false,
description: 'ID of the site profile to be associated.' description: 'ID of the site profile to be associated.'
...@@ -54,7 +59,7 @@ module Mutations ...@@ -54,7 +59,7 @@ module Mutations
authorize :create_on_demand_dast_scan authorize :create_on_demand_dast_scan
def resolve(full_path:, id:, name:, description:, dast_site_profile_id: nil, dast_scanner_profile_id: nil, run_after_update: false) def resolve(full_path:, id:, name:, description:, branch_name: nil, dast_site_profile_id: nil, dast_scanner_profile_id: nil, run_after_update: false)
project = authorized_find!(full_path) project = authorized_find!(full_path)
raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless allowed?(project) raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless allowed?(project)
...@@ -65,6 +70,7 @@ module Mutations ...@@ -65,6 +70,7 @@ module Mutations
dast_profile: dast_profile, dast_profile: dast_profile,
name: name, name: name,
description: description, description: description,
branch_name: feature_flagged_branch_name(project, branch_name) || dast_profile.branch_name,
dast_site_profile_id: as_model_id(SiteProfileID, dast_site_profile_id), dast_site_profile_id: as_model_id(SiteProfileID, dast_site_profile_id),
dast_scanner_profile_id: as_model_id(ScannerProfileID, dast_scanner_profile_id), dast_scanner_profile_id: as_model_id(ScannerProfileID, dast_scanner_profile_id),
run_after_update: run_after_update run_after_update: run_after_update
...@@ -103,6 +109,12 @@ module Mutations ...@@ -103,6 +109,12 @@ module Mutations
.execute .execute
.first .first
end end
def feature_flagged_branch_name(project, branch_name)
return unless Feature.enabled?(:dast_branch_selection, project, default_enabled: :yaml)
branch_name
end
end end
end end
end end
......
...@@ -10,6 +10,7 @@ module Dast ...@@ -10,6 +10,7 @@ module Dast
project: container, project: container,
name: params.fetch(:name), name: params.fetch(:name),
description: params.fetch(:description), description: params.fetch(:description),
branch_name: params[:branch_name],
dast_site_profile: dast_site_profile, dast_site_profile: dast_site_profile,
dast_scanner_profile: dast_scanner_profile dast_scanner_profile: dast_scanner_profile
) )
......
...@@ -44,7 +44,7 @@ module Dast ...@@ -44,7 +44,7 @@ module Dast
end end
def dast_profile_params def dast_profile_params
params.slice(:dast_site_profile_id, :dast_scanner_profile_id, :name, :description) params.slice(:dast_site_profile_id, :dast_scanner_profile_id, :name, :description, :branch_name)
end end
def create_scan(dast_profile) def create_scan(dast_profile)
......
...@@ -28,6 +28,7 @@ RSpec.describe Mutations::Dast::Profiles::Create do ...@@ -28,6 +28,7 @@ RSpec.describe Mutations::Dast::Profiles::Create do
full_path: project.full_path, full_path: project.full_path,
name: name, name: name,
description: description, description: description,
branch_name: 'orphaned-branch',
dast_site_profile_id: dast_site_profile.to_global_id.to_s, dast_site_profile_id: dast_site_profile.to_global_id.to_s,
dast_scanner_profile_id: dast_scanner_profile.to_global_id.to_s, dast_scanner_profile_id: dast_scanner_profile.to_global_id.to_s,
run_after_create: run_after_create run_after_create: run_after_create
...@@ -66,6 +67,22 @@ RSpec.describe Mutations::Dast::Profiles::Create do ...@@ -66,6 +67,22 @@ RSpec.describe Mutations::Dast::Profiles::Create do
expect(actual_url).to eq(expected_url) expect(actual_url).to eq(expected_url)
end end
end end
context "when branch_name='orphaned_branch'" do
context 'when the feature flag dast_branch_selection is disabled' do
it 'does not set the branch_name' do
stub_feature_flags(dast_branch_selection: false)
expect(subject[:dast_profile].branch_name).to be_nil
end
end
context 'when the feature flag dast_branch_selection is enabled' do
it 'sets the branch_name' do
expect(subject[:dast_profile].branch_name).to eq('orphaned-branch')
end
end
end
end end
end end
end end
......
...@@ -7,17 +7,18 @@ RSpec.describe Mutations::Dast::Profiles::Update do ...@@ -7,17 +7,18 @@ RSpec.describe Mutations::Dast::Profiles::Update do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:dast_profile, reload: true) { create(:dast_profile, project: project) } let_it_be(:dast_profile, reload: true) { create(:dast_profile, project: project, branch_name: 'audio') }
let(:dast_profile_gid) { dast_profile.to_global_id } let(:dast_profile_gid) { dast_profile.to_global_id }
let(:params) do let(:params) do
{ {
id: dast_profile_gid, id: dast_profile_gid,
dast_site_profile_id: global_id_of(create(:dast_site_profile, project: project)),
dast_scanner_profile_id: global_id_of(create(:dast_scanner_profile, project: project)),
name: SecureRandom.hex, name: SecureRandom.hex,
description: SecureRandom.hex description: SecureRandom.hex,
branch_name: 'orphaned-branch',
dast_site_profile_id: global_id_of(create(:dast_site_profile, project: project)),
dast_scanner_profile_id: global_id_of(create(:dast_scanner_profile, project: project))
} }
end end
...@@ -72,6 +73,15 @@ RSpec.describe Mutations::Dast::Profiles::Update do ...@@ -72,6 +73,15 @@ RSpec.describe Mutations::Dast::Profiles::Update do
expect(global_id_of(updated_dast_profile.dast_scanner_profile)).to eq(params[:dast_scanner_profile_id]) expect(global_id_of(updated_dast_profile.dast_scanner_profile)).to eq(params[:dast_scanner_profile_id])
expect(updated_dast_profile.name).to eq(params[:name]) expect(updated_dast_profile.name).to eq(params[:name])
expect(updated_dast_profile.description).to eq(params[:description]) expect(updated_dast_profile.description).to eq(params[:description])
expect(updated_dast_profile.branch_name).to eq(params[:branch_name])
end
end
context 'when the feature flag dast_branch_selection is disabled' do
it 'does not set the branch_name' do
stub_feature_flags(dast_branch_selection: false)
expect(subject[:dast_profile].branch_name).to eq(dast_profile.branch_name)
end end
end end
......
...@@ -17,6 +17,7 @@ RSpec.describe 'Creating a DAST Profile' do ...@@ -17,6 +17,7 @@ RSpec.describe 'Creating a DAST Profile' do
mutation_name, mutation_name,
full_path: full_path, full_path: full_path,
name: name, name: name,
branch_name: project.default_branch,
dast_site_profile_id: global_id_of(dast_site_profile), dast_site_profile_id: global_id_of(dast_site_profile),
dast_scanner_profile_id: global_id_of(dast_scanner_profile), dast_scanner_profile_id: global_id_of(dast_scanner_profile),
run_after_create: true run_after_create: true
......
...@@ -15,6 +15,7 @@ RSpec.describe 'Updating a DAST Profile' do ...@@ -15,6 +15,7 @@ RSpec.describe 'Updating a DAST Profile' do
full_path: project.full_path, full_path: project.full_path,
id: global_id_of(dast_profile), id: global_id_of(dast_profile),
name: 'updated dast_profiles.name', name: 'updated dast_profiles.name',
branch_name: project.default_branch,
run_after_update: true run_after_update: true
) )
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment