Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down