Skip to content

Commit

Permalink
[Security Solution][Endpoint] Do not validate TA creation form with s…
Browse files Browse the repository at this point in the history
…oft errors when required name field is empty (#111508) (#111533)

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

fixes /issues/108509

* update test

* review changes

Co-authored-by: Ashokaditya <am.struktr@gmail.com>
  • Loading branch information
kibanamachine and ashokaditya authored Sep 8, 2021
1 parent c2a189e commit 38e5f2c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 });
Expand All @@ -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',
Expand Down Expand Up @@ -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',
},
],
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 38e5f2c

Please sign in to comment.