-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move placeholder text logic to utils
review changes /pull/97623#discussion_r621673881 refs 6f2d0d7
- Loading branch information
1 parent
0bf8199
commit 2dc4fd3
Showing
3 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/security_solution/common/utils/path_placeholder.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
x-pack/plugins/security_solution/common/utils/path_placeholder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters