-
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.
[Security Solution] User can filter Trusted Applications by Hash, Pat…
…h, Signer, or Trusted App name (#95532) * Allows filter param. Empty by default * Uses KQL for filter from Ui * Adds search bar to dispatch trusted apps search. Fixes some type errors. Added filter into the list View state * Fix tests and added a new one. Also split query on array to improve readability * Decouple query parser to be used outside the middleware * Reuse code using a map * Filter by term using wildcards. Updates test * Adds useCallback to memoize function
- Loading branch information
1 parent
36e567b
commit 1f033f3
Showing
15 changed files
with
230 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/utils.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,26 @@ | ||
/* | ||
* 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 { parseQueryFilterToKQL } from './utils'; | ||
|
||
describe('utils', () => { | ||
describe('parseQueryFilterToKQL', () => { | ||
it('should parse simple query without term', () => { | ||
expect(parseQueryFilterToKQL('')).toBe(''); | ||
}); | ||
it('should parse simple query with term', () => { | ||
expect(parseQueryFilterToKQL('simpleQuery')).toBe( | ||
'exception-list-agnostic.attributes.name:*simpleQuery* OR exception-list-agnostic.attributes.description:*simpleQuery* OR exception-list-agnostic.attributes.entries.value:*simpleQuery* OR exception-list-agnostic.attributes.entries.entries.value:*simpleQuery*' | ||
); | ||
}); | ||
it('should parse complex query with term', () => { | ||
expect(parseQueryFilterToKQL('complex query')).toBe( | ||
'exception-list-agnostic.attributes.name:*complex* *query* OR exception-list-agnostic.attributes.description:*complex* *query* OR exception-list-agnostic.attributes.entries.value:*complex* *query* OR exception-list-agnostic.attributes.entries.entries.value:*complex* *query*' | ||
); | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/utils.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,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const parseQueryFilterToKQL = (filter: string): string => { | ||
if (!filter) return ''; | ||
const kuery = [`name`, `description`, `entries.value`, `entries.entries.value`] | ||
.map( | ||
(field) => | ||
`exception-list-agnostic.attributes.${field}:*${filter.trim().replace(/\s/gm, '* *')}*` | ||
) | ||
.join(' OR '); | ||
|
||
return kuery; | ||
}; |
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
60 changes: 60 additions & 0 deletions
60
...y_solution/public/management/pages/trusted_apps/view/components/search_bar/index.test.tsx
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,60 @@ | ||
/* | ||
* 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 { mount } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { SearchBar } from '.'; | ||
|
||
let onSearchMock: jest.Mock; | ||
|
||
interface EuiFieldSearchPropsFake { | ||
onSearch(value: string): void; | ||
} | ||
|
||
describe('Search bar', () => { | ||
beforeEach(() => { | ||
onSearchMock = jest.fn(); | ||
}); | ||
|
||
const getElement = (defaultValue: string = '') => ( | ||
<SearchBar defaultValue={defaultValue} onSearch={onSearchMock} /> | ||
); | ||
|
||
it('should have a default value', () => { | ||
const expectedDefaultValue = 'this is a default value'; | ||
const element = mount(getElement(expectedDefaultValue)); | ||
const defaultValue = element.find('[data-test-subj="trustedAppSearchField"]').first().props() | ||
.defaultValue; | ||
expect(defaultValue).toBe(expectedDefaultValue); | ||
}); | ||
|
||
it('should dispatch search action when submit search field', () => { | ||
const expectedDefaultValue = 'this is a default value'; | ||
const element = mount(getElement()); | ||
expect(onSearchMock).toHaveBeenCalledTimes(0); | ||
const searchFieldProps = element | ||
.find('[data-test-subj="trustedAppSearchField"]') | ||
.first() | ||
.props() as EuiFieldSearchPropsFake; | ||
|
||
searchFieldProps.onSearch(expectedDefaultValue); | ||
|
||
expect(onSearchMock).toHaveBeenCalledTimes(1); | ||
expect(onSearchMock).toHaveBeenCalledWith(expectedDefaultValue); | ||
}); | ||
|
||
it('should dispatch search action when click on button', () => { | ||
const expectedDefaultValue = 'this is a default value'; | ||
const element = mount(getElement(expectedDefaultValue)); | ||
expect(onSearchMock).toHaveBeenCalledTimes(0); | ||
|
||
element.find('[data-test-subj="trustedAppSearchButton"]').first().simulate('click'); | ||
expect(onSearchMock).toHaveBeenCalledTimes(1); | ||
expect(onSearchMock).toHaveBeenCalledWith(expectedDefaultValue); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...curity_solution/public/management/pages/trusted_apps/view/components/search_bar/index.tsx
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,55 @@ | ||
/* | ||
* 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 React, { memo, useCallback, useState } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiFieldSearch, EuiButton } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
export interface SearchBarProps { | ||
defaultValue?: string; | ||
onSearch(value: string): void; | ||
} | ||
|
||
export const SearchBar = memo<SearchBarProps>(({ defaultValue = '', onSearch }) => { | ||
const [query, setQuery] = useState<string>(defaultValue); | ||
|
||
const handleOnChangeSearchField = useCallback( | ||
(ev: React.ChangeEvent<HTMLInputElement>) => setQuery(ev.target.value), | ||
[setQuery] | ||
); | ||
const handleOnSearch = useCallback(() => onSearch(query), [query, onSearch]); | ||
|
||
return ( | ||
<EuiFlexGroup direction="row" alignItems="center" gutterSize="l"> | ||
<EuiFlexItem> | ||
<EuiFieldSearch | ||
defaultValue={query} | ||
placeholder={i18n.translate( | ||
'xpack.securitySolution.trustedapps.list.search.placeholder', | ||
{ | ||
defaultMessage: 'Search', | ||
} | ||
)} | ||
onChange={handleOnChangeSearchField} | ||
onSearch={onSearch} | ||
isClearable | ||
fullWidth | ||
data-test-subj="trustedAppSearchField" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false} onClick={handleOnSearch} data-test-subj="trustedAppSearchButton"> | ||
<EuiButton iconType="refresh"> | ||
{i18n.translate('xpack.securitySolution.trustedapps.list.search.button', { | ||
defaultMessage: 'Refresh', | ||
})} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}); | ||
|
||
SearchBar.displayName = 'SearchBar'; |
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
Oops, something went wrong.