diff --git a/x-pack/solutions/security/packages/kbn-securitysolution-utils/src/path_validations/index.ts b/x-pack/solutions/security/packages/kbn-securitysolution-utils/src/path_validations/index.ts index 965a5b9fbe0fe..4835cbf20fb38 100644 --- a/x-pack/solutions/security/packages/kbn-securitysolution-utils/src/path_validations/index.ts +++ b/x-pack/solutions/security/packages/kbn-securitysolution-utils/src/path_validations/index.ts @@ -199,7 +199,7 @@ const isWindowsWildcardPathValid = (path: string): boolean => { trimmedValue.length !== path.length || firstCharacter === '^' || lastCharacter === '\\' || - !hasWildcard({ path, isWindowsPath: true }) + !hasWildcardInPath({ path, isWindowsPath: true }) ) { return false; } else { @@ -219,7 +219,7 @@ const isLinuxMacWildcardPathValid = (path: string): boolean => { lastCharacter === '/' || path.length > 1024 === true || path.includes('//') === true || - !hasWildcard({ path, isWindowsPath: false }) + !hasWildcardInPath({ path, isWindowsPath: false }) ) { return false; } else { @@ -227,7 +227,7 @@ const isLinuxMacWildcardPathValid = (path: string): boolean => { } }; -const hasWildcard = ({ +const hasWildcardInPath = ({ path, isWindowsPath, }: { diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx index a9cd7b9b89092..b578fd15d59c4 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx @@ -313,29 +313,63 @@ describe('Trusted apps form', () => { expect(getConditionValue(getCondition()).required).toEqual(true); }); - it('should show path malformed warning', () => { - render(); - expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull(); + describe('IS operator', () => { + it('should show path malformed warning', () => { + render(); + expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull(); + + const propsItem: Partial = { + entries: [createEntry(ConditionEntryField.PATH, 'match', 'malformed-path')], + }; + formProps.item = { ...formProps.item, ...propsItem }; + render(); + expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull(); + }); - const propsItem: Partial = { - entries: [createEntry(ConditionEntryField.PATH, 'match', 'malformed-path')], - }; - formProps.item = { ...formProps.item, ...propsItem }; - render(); - expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull(); + it('should show path malformed path warning for linux/mac without an executable name', () => { + render(); + expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull(); + expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull(); + + const propsItem: Partial = { + os_types: [OperatingSystem.LINUX], + entries: [createEntry(ConditionEntryField.PATH, 'match', '/')], + }; + formProps.item = { ...formProps.item, ...propsItem }; + render(); + expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull(); + expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull(); + }); + + it('should show path malformed path warning for windows with no executable name', () => { + render(); + expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull(); + expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull(); + + const propsItem: Partial = { + os_types: [OperatingSystem.WINDOWS], + entries: [createEntry(ConditionEntryField.PATH, 'match', 'c:\\fold\\')], + }; + formProps.item = { ...formProps.item, ...propsItem }; + render(); + expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull(); + expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull(); + }); }); - it('should show wildcard in path warning', () => { - render(); - expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull(); + describe('MATCHES operator', () => { + it('should show wildcard in path warning', () => { + render(); + expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull(); - const propsItem: Partial = { - os_types: [OperatingSystem.LINUX], - entries: [createEntry(ConditionEntryField.PATH, 'wildcard', '/sys/wil*/*.app')], - }; - formProps.item = { ...formProps.item, ...propsItem }; - render(); - expect(screen.getByText(INPUT_ERRORS.wildcardPathWarning(0))).not.toBeNull(); + const propsItem: Partial = { + os_types: [OperatingSystem.LINUX], + entries: [createEntry(ConditionEntryField.PATH, 'wildcard', '/sys/wil*/*.app')], + }; + formProps.item = { ...formProps.item, ...propsItem }; + render(); + expect(screen.getByText(INPUT_ERRORS.wildcardPathWarning(0))).not.toBeNull(); + }); }); it('should display the `AND` button', () => { diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.tsx index 8a9bd0e2dd840..8a6803e0fdb61 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.tsx @@ -200,12 +200,16 @@ const validateValues = (values: ArtifactFormComponentProps['item']): ValidationR type: entry.type as EntryTypes, }) ) { - addResultToValidation( - validation, - 'entries', - 'warnings', - INPUT_ERRORS.wildcardPathWarning(index) - ); + if (entry.type === 'wildcard') { + addResultToValidation( + validation, + 'entries', + 'warnings', + INPUT_ERRORS.wildcardPathWarning(index) + ); + } else { + addResultToValidation(validation, 'entries', 'warnings', INPUT_ERRORS.pathWarning(index)); + } } }); }