1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# frozen_string_literal: true
RSpec.shared_context 'with scan result policy blocking protected branches' do
include RepoHelpers
let(:policy_path) { Security::OrchestrationPolicyConfiguration::POLICY_PATH }
let_it_be(:policy_project) { create(:project, :repository) }
let(:default_branch) { policy_project.default_branch }
let(:policy_yaml) do
build(:orchestration_policy_yaml, scan_execution_policy: [], scan_result_policy: [scan_result_policy])
end
let(:scan_result_policy) do
build(:scan_result_policy, branches: [branch_name], approval_settings: { block_branch_modification: true })
end
before do
policy_configuration.update_attribute(:security_policy_management_project, policy_project)
create_file_in_repo(policy_project, default_branch, default_branch, policy_path, policy_yaml)
stub_licensed_features(security_orchestration_policies: true)
end
end
RSpec.shared_context 'with scan result policy preventing force pushing' do
include RepoHelpers
let(:policy_path) { Security::OrchestrationPolicyConfiguration::POLICY_PATH }
let(:default_branch) { policy_project.default_branch }
let(:prevent_pushing_and_force_pushing) { true }
let(:scan_result_policy) do
build(:scan_result_policy, branches: [branch_name],
approval_settings: { prevent_pushing_and_force_pushing: prevent_pushing_and_force_pushing })
end
let(:policy_yaml) do
build(:orchestration_policy_yaml, scan_result_policy: [scan_result_policy])
end
before do
create_file_in_repo(policy_project, default_branch, default_branch, policy_path, policy_yaml)
stub_licensed_features(security_orchestration_policies: true)
end
after do
policy_project.repository.delete_file(
policy_project.creator,
policy_path,
message: 'Automatically deleted policy',
branch_name: default_branch
)
end
end
|