Commit dedad142 authored by Philip Cunningham's avatar Philip Cunningham

Clean up DAST profile not found error handling

- Favours push instead of append
- Removes nil check and defers to ability check
- Removes questionable spec
parent 9bc09614
......@@ -41,8 +41,8 @@ module AppSec
profile = yield(name).execute.first
unless profile && can?(current_user, :read_on_demand_scans, profile)
errors.append("DAST profile not found: #{name}")
unless can?(current_user, :read_on_demand_scans, profile)
errors.push("DAST profile not found: #{name}")
return
end
......
......@@ -22,9 +22,7 @@ module EE
override :errors
def errors
strong_memoize(:errors) do
super.concat(dast_configuration.errors)
end
super.concat(dast_configuration.errors)
end
private
......
......@@ -3,11 +3,10 @@
require 'spec_helper'
RSpec.describe AppSec::Dast::Profiles::BuildConfigService do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:project) { create(: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(:user) { create(:user, developer_projects: [project] ) }
let_it_be(:outsider) { create(:user) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
let(:dast_site_profile_name) { dast_site_profile.name }
let(:dast_scanner_profile_name) { dast_scanner_profile.name }
......@@ -58,14 +57,8 @@ RSpec.describe AppSec::Dast::Profiles::BuildConfigService do
end
context 'when the profile cannot be read' do
let_it_be(:user) { outsider }
before do
allow_next_instance_of(AppSec::Dast::Profiles::BuildConfigService) do |service|
allow(service).to receive(:can?).and_call_original
allow(service).to receive(:can?).with(user, :create_on_demand_dast_scan, project).and_return(true)
end
end
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
it_behaves_like 'an error occurred' do
let(:error_message) { "DAST profile not found: #{profile_name}" }
......
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