Skip to content

Commit

Permalink
move placeholder text logic to utils
Browse files Browse the repository at this point in the history
review changes /pull/97623#discussion_r621673881

refs 6f2d0d7
  • Loading branch information
ashokaditya committed Apr 28, 2021
1 parent 0bf8199 commit 2dc4fd3
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getPlaceholderText, placeholderText } from './path_placeholder';
import { ConditionEntryField, OperatingSystem, TrustedAppEntryTypes } from '../endpoint/types';

const trustedAppEntry = {
os: OperatingSystem.LINUX,
field: ConditionEntryField.HASH,
type: 'match' as TrustedAppEntryTypes,
};

describe('Trusted Apps: Path placeholder text', () => {
it('returns no placeholder text when field IS NOT PATH', () => {
expect(getPlaceholderText({ ...trustedAppEntry })).toEqual(undefined);
});

it('returns a placeholder text when field IS PATH', () => {
expect(getPlaceholderText({ ...trustedAppEntry, field: ConditionEntryField.PATH })).toEqual(
placeholderText.others.exact
);
});

it('returns LINUX/MAC equivalent placholder when field IS PATH', () => {
expect(
getPlaceholderText({
...trustedAppEntry,
os: OperatingSystem.MAC,
field: ConditionEntryField.PATH,
})
).toEqual(placeholderText.others.exact);
});

it('returns LINUX/MAC equivalent placholder text when field IS PATH and WILDCARD operator is selected', () => {
expect(
getPlaceholderText({
...trustedAppEntry,
os: OperatingSystem.LINUX,
field: ConditionEntryField.PATH,
type: 'wildcard',
})
).toEqual(placeholderText.others.wildcard);
});

it('returns WINDOWS equivalent placholder text when field IS PATH', () => {
expect(
getPlaceholderText({
...trustedAppEntry,
os: OperatingSystem.WINDOWS,
field: ConditionEntryField.PATH,
})
).toEqual(placeholderText.windows.exact);
});

it('returns WINDOWS equivalent placholder text when field IS PATH and WILDCARD operator is selected', () => {
expect(
getPlaceholderText({
...trustedAppEntry,
os: OperatingSystem.WINDOWS,
field: ConditionEntryField.PATH,
type: 'wildcard',
})
).toEqual(placeholderText.windows.wildcard);
});
});
43 changes: 43 additions & 0 deletions x-pack/plugins/security_solution/common/utils/path_placeholder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ConditionEntryField, OperatingSystem, TrustedAppEntryTypes } from '../endpoint/types';

export const placeholderText = {
windows: {
wildcard: 'C:\\sample\\**\\*',
exact: 'C:\\sample\\path.exe',
},
others: {
wildcard: '/opt/**/*',
exact: '/opt/bin',
},
};

export const getPlaceholderText = ({
os,
field,
type,
}: {
os: OperatingSystem;
field: ConditionEntryField;
type: TrustedAppEntryTypes;
}): string | undefined => {
if (field === ConditionEntryField.PATH) {
if (os === OperatingSystem.WINDOWS) {
if (type === 'wildcard') {
return placeholderText.windows.wildcard;
}
return placeholderText.windows.exact;
} else {
if (type === 'wildcard') {
return placeholderText.others.wildcard;
}
return placeholderText.others.exact;
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
OPERATOR_TITLES,
} from '../../translations';
import { useTestIdGenerator } from '../../../../../components/hooks/use_test_id_generator';
import { getPlaceholderText } from '../../../../../../../common/utils/path_placeholder';

const ConditionEntryCell = memo<{
showLabel: boolean;
Expand Down Expand Up @@ -191,17 +192,11 @@ export const ConditionEntryInput = memo<ConditionEntryInputProps>(
<EuiFieldText
name="value"
value={entry.value}
placeholder={
entry.field === ConditionEntryField.PATH
? entry.type === 'wildcard'
? os === OperatingSystem.WINDOWS
? `C:\\sample\\**\\*`
: `/opt/**/*`
: os === OperatingSystem.WINDOWS
? `C:\\sample\\path.exe`
: `/opt/bin/`
: undefined
}
placeholder={getPlaceholderText({
os,
field: entry.field,
type: entry.type,
})}
fullWidth
required
onChange={handleValueUpdate}
Expand Down

0 comments on commit 2dc4fd3

Please sign in to comment.