Skip to content

Commit

Permalink
[Fleet] fix validate package policy error (elastic#208528)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#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
  • Loading branch information
juliaElastic authored Jan 29, 2025
1 parent 5672d88 commit 512bce0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 512bce0

Please sign in to comment.