[Fleet] fix validate package policy error (#208528)

## Summary

Closes https://github.com/elastic/kibana/issues/208519

To verify:
- Add Network Packet Capture integration
- verify that there is no UI error when adding the package policy

<img width="1418" alt="image"
src="https://github.com/user-attachments/assets/2806f717-995a-4c7a-9532-08be30f0cd10"
/>

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Julia Bardi 2025-01-29 11:17:38 +01:00 committed by GitHub
parent 5672d8815a
commit 512bce0b87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -1243,6 +1243,25 @@ describe('Fleet - validatePackagePolicyConfig', () => {
expect(res).toEqual(['myvariable is required']);
});
it('should accept integer', () => {
const res = validatePackagePolicyConfig(
{
type: 'text',
value: [1],
},
{
name: 'myvariable',
type: 'text',
multi: true,
required: true,
},
'myvariable',
load
);
expect(res).toBeNull();
});
});
describe('Integer', () => {

View file

@ -370,7 +370,8 @@ export const validatePackagePolicyConfig = (
}
if (varDef.required && Array.isArray(parsedValue)) {
const hasEmptyString =
varDef.type === 'text' && parsedValue.some((item) => item.trim() === '');
varDef.type === 'text' &&
parsedValue.some((item) => typeof item === 'string' && item.trim() === '');
if (hasEmptyString || parsedValue.length === 0) {
errors.push(