Commit 860122b1 authored by Andy Soiron's avatar Andy Soiron

Merge branch 'sk/337728-consume-security-policy-factory' into 'master'

Consume security policy yaml in specs from factory

See merge request gitlab-org/gitlab!69109
parents 6434079d 07826546
...@@ -10,22 +10,7 @@ RSpec.describe Mutations::SecurityPolicy::CommitScanExecutionPolicy do ...@@ -10,22 +10,7 @@ RSpec.describe Mutations::SecurityPolicy::CommitScanExecutionPolicy do
let_it_be(:policy_management_project) { create(:project, :repository, namespace: user.namespace) } let_it_be(:policy_management_project) { create(:project, :repository, namespace: user.namespace) }
let_it_be(:policy_configuration) { create(:security_orchestration_policy_configuration, security_policy_management_project: policy_management_project, project: project) } let_it_be(:policy_configuration) { create(:security_orchestration_policy_configuration, security_policy_management_project: policy_management_project, project: project) }
let_it_be(:operation_mode) { Types::MutationOperationModeEnum.enum[:append] } let_it_be(:operation_mode) { Types::MutationOperationModeEnum.enum[:append] }
let_it_be(:policy_yaml) do let_it_be(:policy_yaml) { build(:scan_execution_policy).merge(type: 'scan_execution_policy').to_yaml }
<<-EOS
name: Run DAST in every pipeline
type: scan_execution_policy
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end
subject { mutation.resolve(project_path: project.full_path, policy_yaml: policy_yaml, operation_mode: operation_mode) } subject { mutation.resolve(project_path: project.full_path, policy_yaml: policy_yaml, operation_mode: operation_mode) }
......
...@@ -11,17 +11,8 @@ RSpec.describe Resolvers::ScanExecutionPolicyResolver do ...@@ -11,17 +11,8 @@ RSpec.describe Resolvers::ScanExecutionPolicyResolver do
let_it_be(:policy_last_updated_at) { Time.now } let_it_be(:policy_last_updated_at) { Time.now }
let_it_be(:user) { policy_management_project.owner } let_it_be(:user) { policy_management_project.owner }
let_it_be(:policy) do let(:policy) { build(:scan_execution_policy, name: 'Run DAST in every pipeline') }
{ let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy]) }
name: 'Run DAST in every pipeline',
description: 'This policy enforces to run DAST for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[production] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
}
end
let(:repository) { instance_double(Repository, root_ref: 'master') } let(:repository) { instance_double(Repository, root_ref: 'master') }
...@@ -33,7 +24,7 @@ RSpec.describe Resolvers::ScanExecutionPolicyResolver do ...@@ -33,7 +24,7 @@ RSpec.describe Resolvers::ScanExecutionPolicyResolver do
commit.committed_date = policy_last_updated_at commit.committed_date = policy_last_updated_at
allow(policy_management_project).to receive(:repository).and_return(repository) allow(policy_management_project).to receive(:repository).and_return(repository)
allow(repository).to receive(:last_commit_for_path).and_return(commit) allow(repository).to receive(:last_commit_for_path).and_return(commit)
allow(repository).to receive(:blob_data_at).and_return({ scan_execution_policy: [policy] }.to_yaml) allow(repository).to receive(:blob_data_at).and_return(policy_yaml)
end end
context 'when feature is not licensed' do context 'when feature is not licensed' do
......
...@@ -73,43 +73,25 @@ RSpec.describe GitlabSchema.types['DastScannerProfile'] do ...@@ -73,43 +73,25 @@ RSpec.describe GitlabSchema.types['DastScannerProfile'] do
let_it_be(:policies_project) { create(:project, :repository) } let_it_be(:policies_project) { create(:project, :repository) }
let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_project) } let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_project) }
let_it_be(:policy_yml) do let(:policy1) do
<<-EOS build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: %w[master] }], actions: [
scan_execution_policy: { scan: 'dast', site_profile: 'Site Profile', scanner_profile: dast_scanner_profile.name },
- name: Run DAST in every pipeline { scan: 'dast', site_profile: 'Site Profile 2', scanner_profile: 'Scanner Profile 2' }
description: This policy enforces to run DAST for every pipeline within the project ])
enabled: true
rules:
- type: pipeline
branches:
- "master"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: #{dast_scanner_profile.name}
- scan: dast
site_profile: Site Profile 2
scanner_profile: Scanner Profile 2
- name: Run DAST in every pipeline 2
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "master"
actions:
- scan: dast
site_profile: Site Profile 3
scanner_profile: Scanner Profile 3
- scan: dast
site_profile: Site Profile 4
scanner_profile: Scanner Profile 4
EOS
end end
let(:policy2) do
build(:scan_execution_policy, name: 'Run DAST in every pipeline 2', rules: [{ type: 'pipeline', branches: %w[master] }], actions: [
{ scan: 'dast', site_profile: 'Site Profile 3', scanner_profile: 'Scanner Profile 3' },
{ scan: 'dast', site_profile: 'Site Profile 4', scanner_profile: 'Scanner Profile 4' }
])
end
let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy1, policy2]) }
before do before do
create_list(:dast_scanner_profile, 30, project: project) create_list(:dast_scanner_profile, 30, project: project)
create_file_in_repo(policies_project, 'master', 'master', Security::OrchestrationPolicyConfiguration::POLICY_PATH, policy_yml) create_file_in_repo(policies_project, 'master', 'master', Security::OrchestrationPolicyConfiguration::POLICY_PATH, policy_yaml)
end end
it 'only calls Gitaly twice when multiple profiles are present', :request_store do it 'only calls Gitaly twice when multiple profiles are present', :request_store do
......
...@@ -138,43 +138,25 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do ...@@ -138,43 +138,25 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do
let_it_be(:policies_project) { create(:project, :repository) } let_it_be(:policies_project) { create(:project, :repository) }
let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_project) } let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_project) }
let_it_be(:policy_yml) do let(:policy1) do
<<-EOS build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: %w[master] }], actions: [
scan_execution_policy: { scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' },
- name: Run DAST in every pipeline { scan: 'dast', site_profile: 'Site Profile 2', scanner_profile: 'Scanner Profile 2' }
description: This policy enforces to run DAST for every pipeline within the project ])
enabled: true
rules:
- type: pipeline
branches:
- "master"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
- scan: dast
site_profile: Site Profile 2
scanner_profile: Scanner Profile 2
- name: Run DAST in every pipeline 2
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "master"
actions:
- scan: dast
site_profile: Site Profile 3
scanner_profile: Scanner Profile 3
- scan: dast
site_profile: Site Profile 4
scanner_profile: Scanner Profile 4
EOS
end end
let(:policy2) do
build(:scan_execution_policy, name: 'Run DAST in every pipeline 2', rules: [{ type: 'pipeline', branches: %w[master] }], actions: [
{ scan: 'dast', site_profile: 'Site Profile 3', scanner_profile: 'Scanner Profile 3' },
{ scan: 'dast', site_profile: 'Site Profile 4', scanner_profile: 'Scanner Profile 4' }
])
end
let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy1, policy2]) }
before do before do
create_list(:dast_site_profile, 30, project: project) create_list(:dast_site_profile, 30, project: project)
create_file_in_repo(policies_project, 'master', 'master', Security::OrchestrationPolicyConfiguration::POLICY_PATH, policy_yml) create_file_in_repo(policies_project, 'master', 'master', Security::OrchestrationPolicyConfiguration::POLICY_PATH, policy_yaml)
end end
it 'only calls Gitaly twice when multiple profiles are present', :request_store do it 'only calls Gitaly twice when multiple profiles are present', :request_store do
......
...@@ -45,30 +45,14 @@ RSpec.describe Gitlab::Ci::Config do ...@@ -45,30 +45,14 @@ RSpec.describe Gitlab::Ci::Config do
let_it_be(:policies_repository) { create(:project, :repository) } let_it_be(:policies_repository) { create(:project, :repository) }
let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_repository) } let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_repository) }
let_it_be(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy)]) }
let_it_be(:policy_yml) do
<<-EOS
scan_execution_policy:
- name: Run DAST in every pipeline
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end
subject(:config) { described_class.new(ci_yml, source_ref_path: ref, project: project, source: source) } subject(:config) { described_class.new(ci_yml, source_ref_path: ref, project: project, source: source) }
before do before do
allow_next_instance_of(Repository) do |repository| allow_next_instance_of(Repository) do |repository|
# allow(repository).to receive(:ls_files).and_return(['.gitlab/security-policies/enforce-dast.yml']) # allow(repository).to receive(:ls_files).and_return(['.gitlab/security-policies/enforce-dast.yml'])
allow(repository).to receive(:blob_data_at).and_return(policy_yml) allow(repository).to receive(:blob_data_at).and_return(policy_yaml)
end end
end end
......
...@@ -16,28 +16,18 @@ RSpec.describe Gitlab::Ci::Config::SecurityOrchestrationPolicies::Processor do ...@@ -16,28 +16,18 @@ RSpec.describe Gitlab::Ci::Config::SecurityOrchestrationPolicies::Processor do
let_it_be(:policies_repository) { create(:project, :repository) } let_it_be(:policies_repository) { create(:project, :repository) }
let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_repository) } let_it_be(:security_orchestration_policy_configuration) { create(:security_orchestration_policy_configuration, project: project, security_policy_management_project: policies_repository) }
let_it_be(:policy) do
let_it_be(:policy_yml) do build(:scan_execution_policy, actions: [
<<-EOS { scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' },
scan_execution_policy: { scan: 'secret_detection' }
- name: Run DAST in every pipeline ])
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
- scan: secret_detection
EOS
end end
let_it_be(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy]) }
before do before do
allow_next_instance_of(Repository) do |repository| allow_next_instance_of(Repository) do |repository|
allow(repository).to receive(:blob_data_at).and_return(policy_yml) allow(repository).to receive(:blob_data_at).and_return(policy_yaml)
end end
end end
...@@ -56,20 +46,9 @@ RSpec.describe Gitlab::Ci::Config::SecurityOrchestrationPolicies::Processor do ...@@ -56,20 +46,9 @@ RSpec.describe Gitlab::Ci::Config::SecurityOrchestrationPolicies::Processor do
end end
shared_examples 'when policy is invalid' do shared_examples 'when policy is invalid' do
let_it_be(:policy_yml) do let_it_be(:policy_yaml) do
<<-EOS build(:scan_execution_policy_yaml, policies:
scan_execution_policy: [build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: 'production' }])])
- name: Run DAST in every pipeline
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches: "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end end
it 'does not modify the config', :aggregate_failures do it 'does not modify the config', :aggregate_failures do
......
...@@ -11,22 +11,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -11,22 +11,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
let(:default_branch) { security_policy_management_project.default_branch } let(:default_branch) { security_policy_management_project.default_branch }
let(:repository) { instance_double(Repository, root_ref: 'master') } let(:repository) { instance_double(Repository, root_ref: 'master') }
let(:policy_yaml) do let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy, name: 'Run DAST in every pipeline')]) }
<<-EOS
scan_execution_policy:
- name: Run DAST in every pipeline
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end
before do before do
allow(security_policy_management_project).to receive(:repository).and_return(repository) allow(security_policy_management_project).to receive(:repository).and_return(repository)
...@@ -153,22 +138,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -153,22 +138,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end end
context 'when policy is present' do context 'when policy is present' do
let(:policy_yaml) do let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy, name: 'Run DAST in every pipeline' )]) }
<<-EOS
scan_execution_policy:
- name: Run DAST in every pipeline
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end
it 'retrieves policy by type' do it 'retrieves policy by type' do
expect(subject.first[:name]).to eq('Run DAST in every pipeline') expect(subject.first[:name]).to eq('Run DAST in every pipeline')
...@@ -189,19 +159,8 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -189,19 +159,8 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
context 'when file is invalid' do context 'when file is invalid' do
let(:policy_yaml) do let(:policy_yaml) do
<<-EOS build(:scan_execution_policy_yaml, policies:
scan_execution_policy: [build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: 'production' }])])
- name: Run DAST in every pipeline
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branch: "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end end
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
...@@ -213,21 +172,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -213,21 +172,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
context 'when policy is passed as argument' do context 'when policy is passed as argument' do
let_it_be(:policy_yaml) { nil } let_it_be(:policy_yaml) { nil }
let_it_be(:policy) do let_it_be(:policy) { { scan_execution_policy: [build(:scan_execution_policy)] } }
{
scan_execution_policy: [
{
name: 'Run Scan in every pipeline',
description: 'This policy enforces to security scan for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[production] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
}
]
}
end
context 'when scan type is secret_detection' do context 'when scan type is secret_detection' do
it 'returns false if extra fields are present' do it 'returns false if extra fields are present' do
...@@ -248,72 +193,16 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -248,72 +193,16 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end end
describe '#active_policies' do describe '#active_policies' do
let(:enforce_dast_yaml) do let(:enforce_dast_yaml) { build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy)]) }
<<-EOS
scan_execution_policy:
- name: Run DAST in every pipeline
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end
let(:policy_yaml) { fixture_file('security_orchestration.yml', dir: 'ee') } let(:policy_yaml) { fixture_file('security_orchestration.yml', dir: 'ee') }
let(:expected_active_policies) do let(:expected_active_policies) do
[ [
{ build(:scan_execution_policy, name: 'Run DAST in every pipeline'),
name: 'Run DAST in every pipeline', build(:scan_execution_policy, name: 'Run DAST in every pipeline_v1', rules: [{ type: 'pipeline', branches: %w[master] }]),
description: 'This policy enforces to run DAST for every pipeline within the project', build(:scan_execution_policy, name: 'Run DAST in every pipeline_v3', rules: [{ type: 'pipeline', branches: %w[master] }]),
enabled: true, build(:scan_execution_policy, name: 'Run DAST in every pipeline_v4', rules: [{ type: 'pipeline', branches: %w[master] }]),
rules: [{ type: 'pipeline', branches: %w[production] }], build(:scan_execution_policy, name: 'Run DAST in every pipeline_v5', rules: [{ type: 'pipeline', branches: %w[master] }])
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
},
{
name: 'Run DAST in every pipeline_v1',
description: 'This policy enforces to run DAST for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[master] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
},
{
name: 'Run DAST in every pipeline_v3',
description: 'This policy enforces to run DAST for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[master] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
},
{
name: 'Run DAST in every pipeline_v4',
description: 'This policy enforces to run DAST for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[master] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
},
{
name: 'Run DAST in every pipeline_v5',
description: 'This policy enforces to run DAST for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[master] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
}
] ]
end end
...@@ -340,49 +229,11 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -340,49 +229,11 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end end
describe '#on_demand_scan_actions' do describe '#on_demand_scan_actions' do
let(:policy_yaml) do let(:policy1) { build(:scan_execution_policy) }
<<-EOS let(:policy2) { build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: ['release/*'] }], actions: [{ scan: 'dast', site_profile: 'Site Profile 2', scanner_profile: 'Scanner Profile 2' }]) }
scan_execution_policy: let(:policy3) { build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: ['*'] }], actions: [{ scan: 'dast', site_profile: 'Site Profile 3', scanner_profile: 'Scanner Profile 3' }]) }
- name: Run DAST in every pipeline let(:policy4) { build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: ['release/*'] }], actions: [{ scan: 'sast' }]) }
enabled: true let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy1, policy2, policy3, policy4]) }
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
- name: Run DAST in every pipeline
enabled: true
rules:
- type: pipeline
branches:
- "release/*"
actions:
- scan: dast
site_profile: Site Profile 2
scanner_profile: Scanner Profile 2
- name: Run DAST in every pipeline
enabled: true
rules:
- type: pipeline
branches:
- "*"
actions:
- scan: dast
site_profile: Site Profile 3
scanner_profile: Scanner Profile 3
- name: Run SAST in every pipeline
enabled: true
rules:
- type: pipeline
branches:
- "release/*"
actions:
- scan: sast
EOS
end
let(:expected_actions) do let(:expected_actions) do
[ [
...@@ -411,49 +262,11 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -411,49 +262,11 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end end
describe '#pipeline_scan_actions' do describe '#pipeline_scan_actions' do
let(:policy_yaml) do let(:policy1) { build(:scan_execution_policy) }
<<-EOS let(:policy2) { build(:scan_execution_policy, actions: [{ scan: 'dast', site_profile: 'Site Profile 2', scanner_profile: 'Scanner Profile 2' }, { scan: 'secret_detection' }]) }
scan_execution_policy: let(:policy3) { build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: ['*'] }], actions: [{ scan: 'secret_detection' }]) }
- name: Run DAST and Secret Detection in every pipeline let(:policy4) { build(:scan_execution_policy, :with_schedule, actions: [{ scan: 'secret_detection' }]) }
enabled: true let(:policy_yaml) { build(:scan_execution_policy_yaml, policies: [policy1, policy2, policy3, policy4]) }
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile 2
scanner_profile: Scanner Profile 2
- scan: secret_detection
- name: Run DAST in every pipeline
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
- name: Run Secret Detection for all branches
enabled: true
rules:
- type: pipeline
branches:
- "*"
actions:
- scan: secret_detection
- name: Scheduled scan
enabled: true
rules:
- type: schedule
cadence: '*/15 * * * *'
branches:
- "*"
actions:
- scan: secret_detection
EOS
end
let(:expected_actions) do let(:expected_actions) do
[{ scan: 'secret_detection' }, { scan: 'secret_detection' }] [{ scan: 'secret_detection' }, { scan: 'secret_detection' }]
...@@ -470,23 +283,10 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -470,23 +283,10 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
describe '#active_policy_names_with_dast_site_profile' do describe '#active_policy_names_with_dast_site_profile' do
let(:policy_yaml) do let(:policy_yaml) do
<<-EOS build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy, name: 'Run DAST in every pipeline', actions: [
scan_execution_policy: { scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' },
- name: Run DAST in every pipeline { scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile 2' }
description: This policy enforces to run DAST for every pipeline within the project ])])
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile 2
EOS
end end
it 'returns list of policy names where site profile is referenced' do it 'returns list of policy names where site profile is referenced' do
...@@ -496,24 +296,10 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -496,24 +296,10 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
describe '#active_policy_names_with_dast_scanner_profile' do describe '#active_policy_names_with_dast_scanner_profile' do
let(:enforce_dast_yaml) do let(:enforce_dast_yaml) do
<<-EOS build(:scan_execution_policy_yaml, policies: [build(:scan_execution_policy, name: 'Run DAST in every pipeline', actions: [
scan_execution_policy: { scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' },
- type: scan_execution_policy { scan: 'dast', site_profile: 'Site Profile 2', scanner_profile: 'Scanner Profile' }
name: Run DAST in every pipeline ])])
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
- scan: dast
site_profile: Site Profile 2
scanner_profile: Scanner Profile
EOS
end end
before do before do
......
...@@ -7,22 +7,7 @@ RSpec.describe 'Create scan execution policy for a project' do ...@@ -7,22 +7,7 @@ RSpec.describe 'Create scan execution policy for a project' do
let_it_be(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project, :repository, namespace: current_user.namespace) } let_it_be(:project) { create(:project, :repository, namespace: current_user.namespace) }
let_it_be(:policy_yaml) do let_it_be(:policy_yaml) { build(:scan_execution_policy).merge(type: 'scan_execution_policy').to_yaml }
<<-EOS
name: Run DAST in every pipeline
type: scan_execution_policy
description: This policy enforces to run DAST for every pipeline within the project
enabled: true
rules:
- type: pipeline
branches:
- "production"
actions:
- scan: dast
site_profile: Site Profile
scanner_profile: Scanner Profile
EOS
end
def mutation def mutation
variables = { project_path: project.full_path, policy_yaml: policy_yaml, operation_mode: 'APPEND' } variables = { project_path: project.full_path, policy_yaml: policy_yaml, operation_mode: 'APPEND' }
......
...@@ -8,18 +8,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do ...@@ -8,18 +8,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do
let_it_be(:project) { create(:project, :repository, namespace: owner.namespace) } let_it_be(:project) { create(:project, :repository, namespace: owner.namespace) }
let_it_be(:policy_management_project) { create(:project, :repository, namespace: owner.namespace) } let_it_be(:policy_management_project) { create(:project, :repository, namespace: owner.namespace) }
let_it_be(:policy_configuration) { create(:security_orchestration_policy_configuration, security_policy_management_project: policy_management_project, project: project) } let_it_be(:policy_configuration) { create(:security_orchestration_policy_configuration, security_policy_management_project: policy_management_project, project: project) }
let_it_be(:policy) do let_it_be(:policy) { build(:scan_execution_policy) }
{
name: 'Run DAST in every pipeline',
description: 'This policy enforces to run DAST for every pipeline within the project',
enabled: true,
rules: [{ type: 'pipeline', branches: %w[production] }],
actions: [
{ scan: 'dast', site_profile: 'Site Profile', scanner_profile: 'Scanner Profile' }
]
}
end
let_it_be(:type) { 'scan_execution_policy' } let_it_be(:type) { 'scan_execution_policy' }
let_it_be(:index) { project_security_policies_url(project) } let_it_be(:index) { project_security_policies_url(project) }
let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: type) } let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: type) }
......
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