Commit 6058cccd authored by Philip Cunningham's avatar Philip Cunningham Committed by Dylan Griffith

Move Dast::Profile association out of transaction

parent 1b3a4e6e
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
- 1 - 1
- - analytics_usage_trends_counter_job - - analytics_usage_trends_counter_job
- 1 - 1
- - app_sec_dast_scans_consistency
- 1
- - approval_rules_external_approval_rule_payload - - approval_rules_external_approval_rule_payload
- 1 - 1
- - approve_blocked_pending_approval_users - - approve_blocked_pending_approval_users
......
...@@ -8,13 +8,13 @@ module AppSec ...@@ -8,13 +8,13 @@ module AppSec
return ServiceResponse.error(message: 'Insufficient permissions') unless allowed? return ServiceResponse.error(message: 'Insufficient permissions') unless allowed?
service = Ci::CreatePipelineService.new(project, current_user, ref: branch) service = Ci::CreatePipelineService.new(project, current_user, ref: branch)
response = service.execute(:ondemand_dast_scan, content: ci_configuration)
response = service.execute(:ondemand_dast_scan, content: ci_configuration) do |pipeline|
pipeline.dast_profile = dast_profile
end
pipeline = response.payload pipeline = response.payload
if pipeline.created_successfully? if pipeline.created_successfully?
associate_dast_profile(pipeline, dast_profile) if dast_profile
ServiceResponse.success(payload: pipeline) ServiceResponse.success(payload: pipeline)
else else
ServiceResponse.error(message: pipeline.full_error_messages) ServiceResponse.error(message: pipeline.full_error_messages)
...@@ -26,6 +26,12 @@ module AppSec ...@@ -26,6 +26,12 @@ module AppSec
def allowed? def allowed?
Ability.allowed?(current_user, :create_on_demand_dast_scan, project) Ability.allowed?(current_user, :create_on_demand_dast_scan, project)
end end
def associate_dast_profile(pipeline, dast_profile)
AppSec::Dast::Scans::ConsistencyWorker.perform_async(pipeline.id, dast_profile.id)
pipeline.dast_profile = dast_profile # this assignment performs an insert
end
end end
end end
end end
......
...@@ -876,6 +876,15 @@ ...@@ -876,6 +876,15 @@
:weight: 1 :weight: 1
:idempotent: true :idempotent: true
:tags: [] :tags: []
- :name: app_sec_dast_scans_consistency
:worker_name: AppSec::Dast::Scans::ConsistencyWorker
:feature_category: :dynamic_application_security_testing
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: approval_rules_external_approval_rule_payload - :name: approval_rules_external_approval_rule_payload
:worker_name: ApprovalRules::ExternalApprovalRulePayloadWorker :worker_name: ApprovalRules::ExternalApprovalRulePayloadWorker
:feature_category: :source_code_management :feature_category: :source_code_management
......
# frozen_string_literal: true
module AppSec
module Dast
module Scans
class ConsistencyWorker
include ApplicationWorker
data_consistency :always
deduplicate :until_executed
idempotent!
feature_category :dynamic_application_security_testing
def perform(ci_pipeline_id, dast_profile_id)
::Dast::ProfilesPipeline.create!(ci_pipeline_id: ci_pipeline_id, dast_profile_id: dast_profile_id)
rescue ActiveRecord::RecordNotUnique
# assume record is already associated
end
end
end
end
end
...@@ -57,6 +57,14 @@ RSpec.describe AppSec::Dast::Scans::RunService do ...@@ -57,6 +57,14 @@ RSpec.describe AppSec::Dast::Scans::RunService do
expect { subject }.to change(Ci::Pipeline, :count).by(1) expect { subject }.to change(Ci::Pipeline, :count).by(1)
end end
it 'associates the dast profile', :aggregate_failures do
worker_class = AppSec::Dast::Scans::ConsistencyWorker
allow(worker_class).to receive(:perform_async).and_call_original
expect(pipeline.dast_profile).to eq(dast_profile)
expect(worker_class).to have_received(:perform_async).with(pipeline.id, dast_profile.id)
end
it 'sets the pipeline ref to the branch' do it 'sets the pipeline ref to the branch' do
expect(pipeline.ref).to eq(project.default_branch) expect(pipeline.ref).to eq(project.default_branch)
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AppSec::Dast::Scans::ConsistencyWorker do
let(:worker) { described_class.new }
describe '#perform' do
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:profile) { create(:dast_profile, project: project) }
let(:job_args) { [pipeline.id, profile.id] }
it 'ensures cross database association is created', :aggregate_failures do
expect { worker.perform(*job_args) }.to change { Dast::ProfilesPipeline.count }.by(1)
expect(Dast::ProfilesPipeline.where(ci_pipeline_id: pipeline.id, dast_profile_id: profile.id)).to exist
end
it_behaves_like 'an idempotent worker'
end
end
- "./ee/spec/controllers/projects/settings/access_tokens_controller_spec.rb" - "./ee/spec/controllers/projects/settings/access_tokens_controller_spec.rb"
- "./ee/spec/graphql/mutations/dast/profiles/create_spec.rb"
- "./ee/spec/graphql/mutations/dast/profiles/run_spec.rb"
- "./ee/spec/graphql/mutations/dast/profiles/update_spec.rb"
- "./ee/spec/graphql/mutations/dast_on_demand_scans/create_spec.rb"
- "./ee/spec/lib/gitlab/ci/templates/Jobs/dast_default_branch_gitlab_ci_yaml_spec.rb" - "./ee/spec/lib/gitlab/ci/templates/Jobs/dast_default_branch_gitlab_ci_yaml_spec.rb"
- "./ee/spec/mailers/notify_spec.rb" - "./ee/spec/mailers/notify_spec.rb"
- "./ee/spec/models/ci/bridge_spec.rb" - "./ee/spec/models/ci/bridge_spec.rb"
......
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