diff --git a/ee/app/assets/javascripts/threat_monitoring/components/policy_editor/utils.js b/ee/app/assets/javascripts/threat_monitoring/components/policy_editor/utils.js index 88d80faeda84a26fe7ca037d443a6b231e190fe8..f4fd9afbb0851af0d4987316d747bd2067288ba7 100644 --- a/ee/app/assets/javascripts/threat_monitoring/components/policy_editor/utils.js +++ b/ee/app/assets/javascripts/threat_monitoring/components/policy_editor/utils.js @@ -71,7 +71,7 @@ const updatePolicy = async ({ }; /** - * Updates the assigned security policy project's policy file with the new policy yaml or creates one (project or file) if one does not exist + * Updates the assigned security policy project's policy file with the new policy yaml or creates one file if one does not exist * @param {Object} payload contains the currently assigned security policy project (if one exists), the path to the project, and the policy yaml value * @returns {Object} contains the currently assigned security policy project and the created merge request */ diff --git a/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb b/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb index 767480760cf2d0c39e16546a23fd3885b20cb274..51f4506149e4faf9d582e9f35d72f69d22dad788 100644 --- a/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb +++ b/ee/app/services/security/security_orchestration_policies/validate_policy_service.rb @@ -22,10 +22,12 @@ def policy_disabled? def invalid_policy_type? return true if policy[:type].blank? - !Security::OrchestrationPolicyConfiguration::AVAILABLE_POLICY_TYPES.include?(policy[:type].to_sym) + !Security::OrchestrationPolicyConfiguration::AVAILABLE_POLICY_TYPES.include?(policy_type) end def blank_branch_for_rule? + return false if policy_type == :scan_result_policy + policy[:rules].any? { |rule| rule[:clusters].blank? && rule[:branches].blank? } end @@ -55,6 +57,10 @@ def branches_for_project repository.branch_names end end + + def policy_type + policy[:type].to_sym + end end end end diff --git a/ee/spec/services/security/security_orchestration_policies/validate_policy_service_spec.rb b/ee/spec/services/security/security_orchestration_policies/validate_policy_service_spec.rb index 1ce8d2be88b62e55191e9177ce975216f2f9f88a..b6fe118965a3ccd4e9d602f0f265244ec32b864a 100644 --- a/ee/spec/services/security/security_orchestration_policies/validate_policy_service_spec.rb +++ b/ee/spec/services/security/security_orchestration_policies/validate_policy_service_spec.rb @@ -76,12 +76,21 @@ end context 'when branches are missing' do + using RSpec::Parameterized::TableSyntax + let(:branches) { nil } - it { expect(result[:status]).to eq(:error) } - it { expect(result[:message]).to eq('Policy cannot be enabled without branch information') } + where(:policy_type, :status, :message) do + 'scan_result_policy' | :success | nil + 'scan_execution_policy' | :error | 'Policy cannot be enabled without branch information' + end - it_behaves_like 'checks only if policy is enabled' + with_them do + it { expect(result[:status]).to eq(status) } + it { expect(result[:message]).to eq(message) } + + it_behaves_like 'checks only if policy is enabled' + end end context 'when branches are provided' do