Commit 7945c266 authored by Philip Cunningham's avatar Philip Cunningham

Rename DAST Sites services to use AppSec namespace

- Renames find or create service
- Updates specs and cleans up one small issue
parent f819d222
......@@ -18,7 +18,7 @@ module AppSec
return ServiceResponse.error(message: _('Insufficient permissions')) unless allowed?
ApplicationRecord.transaction do
@dast_site = ::DastSites::FindOrCreateService.new(project, current_user).execute!(url: target_url)
@dast_site = ::AppSec::Dast::Sites::FindOrCreateService.new(project, current_user).execute!(url: target_url)
params.merge!(project: project, dast_site: dast_site, name: name).compact!
@dast_site_validation = find_existing_dast_site_validation
......
......@@ -31,7 +31,7 @@ module AppSec
})
if target_url = params.delete(:target_url)
params[:dast_site] = DastSites::FindOrCreateService.new(project, current_user).execute!(url: target_url)
params[:dast_site] = AppSec::Dast::Sites::FindOrCreateService.new(project, current_user).execute!(url: target_url)
end
handle_secret_variable!(params, :request_headers, ::Dast::SiteProfileSecretVariable::REQUEST_HEADERS)
......
# frozen_string_literal: true
module AppSec
module Dast
module Sites
class FindOrCreateService < BaseService
PermissionsError = Class.new(StandardError)
def execute!(url:)
raise PermissionsError, 'Insufficient permissions' unless allowed?
DastSite.find_or_create_by!(project: project, url: url) # rubocop:disable CodeReuse/ActiveRecord
end
private
def allowed?
Ability.allowed?(current_user, :create_on_demand_dast_scan, project)
end
end
end
end
end
# frozen_string_literal: true
module DastSites
class FindOrCreateService < BaseService
PermissionsError = Class.new(StandardError)
def execute!(url:)
raise PermissionsError, 'Insufficient permissions' unless allowed?
DastSite.find_or_create_by!(project: project, url: url) # rubocop:disable CodeReuse/ActiveRecord
end
private
def allowed?
Ability.allowed?(current_user, :create_on_demand_dast_scan, project)
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe DastSites::FindOrCreateService do
RSpec.describe AppSec::Dast::Sites::FindOrCreateService do
let(:user) { create(:user) }
let(:project) { create(:project, :repository, creator: user) }
let(:url) { generate(:url) }
......@@ -16,7 +16,7 @@ RSpec.describe DastSites::FindOrCreateService do
context 'when a user does not have access to the project' do
it 'raises an exception' do
expect { subject }.to raise_error(DastSites::FindOrCreateService::PermissionsError) do |err|
expect { subject }.to raise_error(described_class::PermissionsError) do |err|
expect(err.message).to include('Insufficient permissions')
end
end
......@@ -63,7 +63,7 @@ RSpec.describe DastSites::FindOrCreateService do
it 'raises an exception' do
stub_licensed_features(security_on_demand_scans: false)
expect { subject }.to raise_error(DastSites::FindOrCreateService::PermissionsError) do |err|
expect { subject }.to raise_error(described_class::PermissionsError) do |err|
expect(err.message).to include('Insufficient permissions')
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