Commit 7227d6d1 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'philipcunningham-run-dast-scan-against-specified-branch-322526' into 'master'

Optionally specify branch for DAST on-demand scan

See merge request gitlab-org/gitlab!55141
parents 305a8e54 4db9087a
...@@ -60,6 +60,7 @@ module Mutations ...@@ -60,6 +60,7 @@ module Mutations
container: project, container: project,
current_user: current_user, current_user: current_user,
params: { params: {
branch: dast_profile.branch_name,
dast_site_profile: dast_profile.dast_site_profile, dast_site_profile: dast_profile.dast_site_profile,
dast_scanner_profile: dast_profile.dast_scanner_profile dast_scanner_profile: dast_profile.dast_scanner_profile
} }
......
...@@ -21,6 +21,7 @@ module Dast ...@@ -21,6 +21,7 @@ module Dast
container: container, container: container,
current_user: current_user, current_user: current_user,
params: { params: {
branch: dast_profile.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
} }
......
...@@ -49,6 +49,7 @@ module Dast ...@@ -49,6 +49,7 @@ module Dast
def create_scan(dast_profile) def create_scan(dast_profile)
params = { params = {
branch: dast_profile.branch_name,
dast_site_profile: dast_profile.dast_site_profile, dast_site_profile: dast_profile.dast_site_profile,
dast_scanner_profile: dast_profile.dast_scanner_profile dast_scanner_profile: dast_profile.dast_scanner_profile
} }
......
...@@ -56,7 +56,7 @@ RSpec.describe Mutations::Dast::Profiles::Create do ...@@ -56,7 +56,7 @@ RSpec.describe Mutations::Dast::Profiles::Create do
actual_url = subject[:pipeline_url] actual_url = subject[:pipeline_url]
pipeline = Ci::Pipeline.find_by( pipeline = Ci::Pipeline.find_by(
project: project, project: project,
sha: project.repository.commit.sha, sha: project.repository.commits('orphaned-branch', limit: 1)[0].id,
source: :ondemand_dast_scan, source: :ondemand_dast_scan,
config_source: :parameter_source config_source: :parameter_source
) )
......
...@@ -6,7 +6,7 @@ RSpec.describe Mutations::Dast::Profiles::Run do ...@@ -6,7 +6,7 @@ RSpec.describe Mutations::Dast::Profiles::Run do
let_it_be_with_refind(:project) { create(:project, :repository) } let_it_be_with_refind(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:dast_profile) { create(:dast_profile, project: project) } let_it_be(:dast_profile) { create(:dast_profile, project: project, branch_name: 'orphaned-branch') }
let(:full_path) { project.full_path } let(:full_path) { project.full_path }
let(:dast_profile_id) { dast_profile.to_global_id } let(:dast_profile_id) { dast_profile.to_global_id }
...@@ -60,6 +60,12 @@ RSpec.describe Mutations::Dast::Profiles::Run do ...@@ -60,6 +60,12 @@ RSpec.describe Mutations::Dast::Profiles::Run do
project.add_developer(user) project.add_developer(user)
end end
it_behaves_like 'it delegates scan creation to another service' do
let(:delegated_params) do
{ branch: dast_profile.branch_name, dast_site_profile: dast_profile.dast_site_profile, dast_scanner_profile: dast_profile.dast_scanner_profile }
end
end
it 'returns a pipeline_url containing the correct path' do it 'returns a pipeline_url containing the correct path' do
actual_url = subject[:pipeline_url] actual_url = subject[:pipeline_url]
pipeline = Ci::Pipeline.last pipeline = Ci::Pipeline.last
......
...@@ -7,8 +7,16 @@ RSpec.describe Dast::Profiles::CreateService do ...@@ -7,8 +7,16 @@ RSpec.describe Dast::Profiles::CreateService do
let_it_be(:developer) { create(:user, developer_projects: [project] ) } let_it_be(:developer) { create(:user, developer_projects: [project] ) }
let_it_be(:dast_site_profile) { create(:dast_site_profile, project: project) } let_it_be(:dast_site_profile) { create(:dast_site_profile, project: project) }
let_it_be(:dast_scanner_profile) { create(:dast_scanner_profile, project: project) } let_it_be(:dast_scanner_profile) { create(:dast_scanner_profile, project: project) }
let_it_be(:default_params) do let_it_be(:default_params) do
{ name: SecureRandom.hex, description: :description, dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile, run_after_create: false } {
name: SecureRandom.hex,
description: :description,
branch_name: 'orphaned-branch',
dast_site_profile: dast_site_profile,
dast_scanner_profile: dast_scanner_profile,
run_after_create: false
}
end end
let(:params) { default_params } let(:params) { default_params }
...@@ -57,12 +65,10 @@ RSpec.describe Dast::Profiles::CreateService do ...@@ -57,12 +65,10 @@ RSpec.describe Dast::Profiles::CreateService do
context 'when param run_after_create: true' do context 'when param run_after_create: true' do
let(:params) { default_params.merge(run_after_create: true) } let(:params) { default_params.merge(run_after_create: true) }
it 'calls DastOnDemandScans::CreateService' do it_behaves_like 'it delegates scan creation to another service' do
params = { dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile } let(:delegated_params) do
{ branch: default_params[:branch_name], dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile }
expect(DastOnDemandScans::CreateService).to receive(:new).with(hash_including(params: params)).and_call_original end
subject
end end
it 'creates a ci_pipeline' do it 'creates a ci_pipeline' do
......
...@@ -5,17 +5,18 @@ require 'spec_helper' ...@@ -5,17 +5,18 @@ require 'spec_helper'
RSpec.describe Dast::Profiles::UpdateService do RSpec.describe Dast::Profiles::UpdateService do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
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: 'orphaned-branch') }
let_it_be(:dast_site_profile) { create(:dast_site_profile, project: project) } let_it_be(:dast_site_profile) { create(:dast_site_profile, project: project) }
let_it_be(:dast_scanner_profile) { create(:dast_scanner_profile, project: project) } let_it_be(:dast_scanner_profile) { create(:dast_scanner_profile, project: project) }
let(:default_params) do let(:default_params) do
{ {
name: SecureRandom.hex,
description: SecureRandom.hex,
branch_name: 'orphaned-branch',
dast_profile: dast_profile, dast_profile: dast_profile,
dast_site_profile_id: dast_site_profile.id, dast_site_profile_id: dast_site_profile.id,
dast_scanner_profile_id: dast_scanner_profile.id, dast_scanner_profile_id: dast_scanner_profile.id
name: SecureRandom.hex,
description: SecureRandom.hex
} }
end end
...@@ -92,12 +93,10 @@ RSpec.describe Dast::Profiles::UpdateService do ...@@ -92,12 +93,10 @@ RSpec.describe Dast::Profiles::UpdateService do
context 'when param run_after_update: true' do context 'when param run_after_update: true' do
let(:params) { default_params.merge(run_after_update: true) } let(:params) { default_params.merge(run_after_update: true) }
it 'calls DastOnDemandScans::CreateService' do it_behaves_like 'it delegates scan creation to another service' do
params = { dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile } let(:delegated_params) do
{ branch: dast_profile.branch_name, dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile }
expect(DastOnDemandScans::CreateService).to receive(:new).with(hash_including(params: params)).and_call_original end
subject
end end
it 'creates a ci_pipeline' do it 'creates a ci_pipeline' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples 'it delegates scan creation to another service' do
it 'calls DastOnDemandScans::CreateService' do
expect(DastOnDemandScans::CreateService).to receive(:new).with(hash_including(params: delegated_params)).and_call_original
subject
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