Commit 6330bbe1 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'philipcunningham-fix-missing-dast-profile-from-scheduled' into 'master'

Pass Dast::Profile in profile schedule worker

See merge request gitlab-org/gitlab!72734
parents ddb2c3ae 5dc8dffd
...@@ -37,10 +37,7 @@ module AppSec ...@@ -37,10 +37,7 @@ module AppSec
::AppSec::Dast::Scans::CreateService.new( ::AppSec::Dast::Scans::CreateService.new(
container: schedule.project, container: schedule.project,
current_user: schedule.owner, current_user: schedule.owner,
params: { params: { dast_profile: schedule.dast_profile }
dast_site_profile: schedule.dast_profile.dast_site_profile,
dast_scanner_profile: schedule.dast_profile.dast_scanner_profile
}
) )
end end
......
...@@ -34,9 +34,11 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do ...@@ -34,9 +34,11 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do
it 'does not call runnable_schedules' do it 'does not call runnable_schedules' do
expect(::Dast::ProfileSchedule).not_to receive(:runnable_schedules) expect(::Dast::ProfileSchedule).not_to receive(:runnable_schedules)
subject subject
end end
end end
context 'when feature is licensed' do context 'when feature is licensed' do
before do before do
stub_licensed_features(security_on_demand_scans: true) stub_licensed_features(security_on_demand_scans: true)
...@@ -83,9 +85,11 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do ...@@ -83,9 +85,11 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do
end end
end end
it 'sets active to false' do it 'sets active to false', :aggregate_failures do
expect(service).to receive(:execute) expect(service).to receive(:execute)
subject subject
expect(Dast::ProfileSchedule.where(active: false).count).to eq(2) expect(Dast::ProfileSchedule.where(active: false).count).to eq(2)
end end
end end
...@@ -96,7 +100,7 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do ...@@ -96,7 +100,7 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do
schedule.update_column(:next_run_at, 1.minute.ago) schedule.update_column(:next_run_at, 1.minute.ago)
end end
it 'executes the rule schedule service' do it 'executes the service that creates dast scans', :aggregate_failures do
expect_next_found_instance_of(::Dast::ProfileSchedule) do |schedule| expect_next_found_instance_of(::Dast::ProfileSchedule) do |schedule|
expect(schedule).to receive(:schedule_next_run!) expect(schedule).to receive(:schedule_next_run!)
end end
...@@ -106,6 +110,12 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do ...@@ -106,6 +110,12 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do
subject subject
end end
it 'calls the service that creates dast scans with the correct parameters' do
expect(::AppSec::Dast::Scans::CreateService).to receive(:new).with(container: project, current_user: owner, params: { dast_profile: schedule.dast_profile })
subject
end
context 'when the schedule owner is invalid' do context 'when the schedule owner is invalid' do
before do before do
schedule.update_column(:user_id, nil) schedule.update_column(:user_id, nil)
...@@ -140,19 +150,19 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do ...@@ -140,19 +150,19 @@ RSpec.describe AppSec::Dast::ProfileScheduleWorker do
schedule.update_column(:next_run_at, 1.minute.from_now) schedule.update_column(:next_run_at, 1.minute.from_now)
end end
it 'executes the rule schedule service' do it 'does not execute the service that creates dast scans' do
expect(::AppSec::Dast::Scans::CreateService).not_to receive(:new) expect(::AppSec::Dast::Scans::CreateService).not_to receive(:new)
subject subject
end end
end end
context 'when single run schedule exists' do context 'when a schedule that does not repeat exists' do
before do before do
schedule.update_columns(next_run_at: 1.minute.ago, cadence: {}) schedule.update_columns(next_run_at: 1.minute.ago, cadence: {})
end end
it 'executes the rule schedule service and deactivate the schedule', :aggregate_failures do it 'sets active to false', :aggregate_failures do
expect(schedule.repeat?).to be(false) expect(schedule.repeat?).to be(false)
subject subject
......
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