diff --git a/x-pack/plugins/fleet/common/services/validate_package_policy.test.ts b/x-pack/plugins/fleet/common/services/validate_package_policy.test.ts index 306d31879e0c6..98056d6906c59 100644 --- a/x-pack/plugins/fleet/common/services/validate_package_policy.test.ts +++ b/x-pack/plugins/fleet/common/services/validate_package_policy.test.ts @@ -253,7 +253,7 @@ describe('Fleet - validatePackagePolicy()', () => { enabled: true, vars: { 'foo-input-var-name': { value: undefined, type: 'text' }, - 'foo-input2-var-name': { value: '', type: 'text' }, + 'foo-input2-var-name': { value: undefined, type: 'text' }, 'foo-input3-var-name': { value: [], type: 'text' }, }, streams: [ @@ -555,6 +555,57 @@ describe('Fleet - validatePackagePolicy()', () => { inputs: null, }); }); + + it('returns no errors when required field is present but empty', () => { + expect( + validatePackagePolicy( + { + ...validPackagePolicy, + inputs: [ + { + type: 'foo', + policy_template: 'pkgPolicy1', + enabled: true, + vars: { + 'foo-input-var-name': { value: '', type: 'text' }, + 'foo-input2-var-name': { value: '', type: 'text' }, + 'foo-input3-var-name': { value: ['test'], type: 'text' }, + }, + streams: [ + { + data_stream: { dataset: 'foo', type: 'logs' }, + enabled: true, + vars: { 'var-name': { value: 'test_yaml: value', type: 'yaml' } }, + }, + ], + }, + ], + }, + mockPackage, + safeLoad + ) + ).toEqual({ + name: null, + description: null, + namespace: null, + inputs: { + foo: { + streams: { + foo: { + vars: { + 'var-name': null, + }, + }, + }, + vars: { + 'foo-input-var-name': null, + 'foo-input2-var-name': null, + 'foo-input3-var-name': null, + }, + }, + }, + }); + }); }); describe('works for packages with multiple policy templates (aka integrations)', () => { diff --git a/x-pack/plugins/fleet/common/services/validate_package_policy.ts b/x-pack/plugins/fleet/common/services/validate_package_policy.ts index 8e2744d970371..b6befdf8c790e 100644 --- a/x-pack/plugins/fleet/common/services/validate_package_policy.ts +++ b/x-pack/plugins/fleet/common/services/validate_package_policy.ts @@ -217,7 +217,7 @@ export const validatePackagePolicyConfig = ( } if (varDef.required) { - if (parsedValue === undefined || (typeof parsedValue === 'string' && !parsedValue)) { + if (parsedValue === undefined || (varDef.type === 'yaml' && parsedValue === '')) { errors.push( i18n.translate('xpack.fleet.packagePolicyValidation.requiredErrorMessage', { defaultMessage: '{fieldName} is required',