Commit ecb025c5 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'add_validation_for_approvers_with_empty_array' into 'master'

Add validation for approvers with empty array

See merge request gitlab-org/gitlab!80847
parents db6ad441 234a71a4
...@@ -335,6 +335,7 @@ ...@@ -335,6 +335,7 @@
}, },
"user_approvers": { "user_approvers": {
"type": "array", "type": "array",
"minItems": 1,
"additionalItems": false, "additionalItems": false,
"items": { "items": {
"minLength": 1, "minLength": 1,
...@@ -343,6 +344,7 @@ ...@@ -343,6 +344,7 @@
}, },
"user_approvers_ids": { "user_approvers_ids": {
"type": "array", "type": "array",
"minItems": 1,
"additionalItems": false, "additionalItems": false,
"items": { "items": {
"minLength": 1, "minLength": 1,
...@@ -351,6 +353,7 @@ ...@@ -351,6 +353,7 @@
}, },
"group_approvers": { "group_approvers": {
"type": "array", "type": "array",
"minItems": 1,
"additionalItems": false, "additionalItems": false,
"items": { "items": {
"minLength": 1, "minLength": 1,
...@@ -359,6 +362,7 @@ ...@@ -359,6 +362,7 @@
}, },
"group_approvers_ids": { "group_approvers_ids": {
"type": "array", "type": "array",
"minItems": 1,
"additionalItems": false, "additionalItems": false,
"items": { "items": {
"minLength": 1, "minLength": 1,
......
...@@ -178,6 +178,35 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -178,6 +178,35 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end end
end end
end end
context 'with scan result policies' do
let(:scan_result_policy) { build(:scan_result_policy, name: 'Contains security critical severities') }
let(:policy_yaml) { build(:orchestration_policy_yaml, scan_result_policy: [scan_result_policy]) }
it { is_expected.to eq(true) }
context 'with various approvers' do
using RSpec::Parameterized::TableSyntax
where(:user_approvers, :user_approvers_ids, :group_approvers, :group_approvers_ids, :is_valid) do
[] | nil | nil | nil | false
['username'] | nil | nil | nil | true
nil | [] | nil | nil | false
nil | [1] | nil | nil | true
nil | nil | [] | nil | false
nil | nil | ['group_path'] | nil | true
nil | nil | nil | [] | false
nil | nil | nil | [2] | true
end
with_them do
let(:action) { { type: 'require_approval', approvals_required: 1, user_approvers: user_approvers, user_approvers_ids: user_approvers_ids, group_approvers: group_approvers, group_approvers_ids: group_approvers_ids }.compact }
let(:scan_result_policy) { build(:scan_result_policy, name: 'Contains security critical severities', actions: [action]) }
it { is_expected.to eq(is_valid) }
end
end
end
end end
describe '#policy_configuration_validation_errors' do describe '#policy_configuration_validation_errors' do
...@@ -389,7 +418,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -389,7 +418,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
end end
end end
describe '#active_result_execution_policies' do describe '#active_scan_result_policies' do
let(:scan_result_yaml) { build(:orchestration_policy_yaml, scan_result_policy: [build(:scan_result_policy)]) } let(:scan_result_yaml) { build(:orchestration_policy_yaml, scan_result_policy: [build(:scan_result_policy)]) }
let(:policy_yaml) { fixture_file('security_orchestration.yml', dir: 'ee') } let(:policy_yaml) { fixture_file('security_orchestration.yml', dir: 'ee') }
......
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