[Security Solution][Endpoint] Do not validate TA creation form with soft errors when required name field is empty (#111508)

* validate to true only if name is not empty as well

fixes elastic/kibana/issues/108509

* update test

* review changes
This commit is contained in:
Ashokaditya 2021-09-08 15:23:04 +02:00 committed by GitHub
parent 721cf1023d
commit 01218e4745
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 3 deletions

View file

@ -110,6 +110,9 @@ describe('When using the Trusted App Form', () => {
const getAllValidationErrors = (): HTMLElement[] => {
return Array.from(renderResult.container.querySelectorAll('.euiFormErrorText'));
};
const getAllValidationWarnings = (): HTMLElement[] => {
return Array.from(renderResult.container.querySelectorAll('.euiFormHelpText'));
};
beforeEach(() => {
resetHTMLElementOffsetWidth = forceHTMLElementOffsetWidth();
@ -192,7 +195,7 @@ describe('When using the Trusted App Form', () => {
expect(getConditionRemoveButton(defaultCondition).disabled).toBe(true);
});
it('should display 2 options for Field', () => {
it('should display 3 options for Field for Windows', () => {
const conditionFieldSelect = getConditionFieldSelect(getCondition());
reactTestingLibrary.act(() => {
fireEvent.click(conditionFieldSelect, { button: 1 });
@ -202,6 +205,7 @@ describe('When using the Trusted App Form', () => {
'.euiSuperSelect__listbox button.euiSuperSelect__item'
)
).map((button) => button.textContent);
expect(options.length).toEqual(3);
expect(options).toEqual([
'Hashmd5, sha1, or sha256',
'PathThe full path of the application',
@ -411,5 +415,48 @@ describe('When using the Trusted App Form', () => {
},
});
});
it('should not validate form to true if name input is empty', () => {
const props = {
name: 'some name',
description: '',
effectScope: {
type: 'global',
},
os: OperatingSystem.WINDOWS,
entries: [
{ field: ConditionEntryField.PATH, operator: 'included', type: 'wildcard', value: 'x' },
],
} as NewTrustedApp;
formProps.trustedApp = props;
render();
formProps.trustedApp = {
...props,
name: '',
};
rerender();
expect(getAllValidationErrors()).toHaveLength(0);
expect(getAllValidationWarnings()).toHaveLength(1);
expect(formProps.onChange).toHaveBeenLastCalledWith({
isValid: false,
item: {
name: '',
description: '',
os: OperatingSystem.WINDOWS,
effectScope: { type: 'global' },
entries: [
{
field: ConditionEntryField.PATH,
operator: 'included',
type: 'wildcard',
value: 'x',
},
],
},
});
});
});
});

View file

@ -161,8 +161,6 @@ const validateFormValues = (values: MaybeImmutable<NewTrustedApp>): ValidationRe
} else if (
!isPathValid({ os: values.os, field: entry.field, type: entry.type, value: entry.value })
) {
// show soft warnings and thus allow entry
isValid = true;
addResultToValidation(
validation,
'entries',