[8.7] [Security Solution][Exceptions] - Fix exception operator logic when mapping conflict (#155071) (#155094)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Security Solution][Exceptions] - Fix exception operator logic when
mapping conflict
(#155071)](https://github.com/elastic/kibana/pull/155071)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Yara
Tercero","email":"yctercero@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-04-17T21:05:55Z","message":"[Security
Solution][Exceptions] - Fix exception operator logic when mapping
conflict (#155071)\n\n## Summary\r\n\r\nAddresses
https://github.com/elastic/kibana/issues/154962
.","sha":"9a095602f87c945dcfd832451e0f6136ec9df5df","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:
SecuritySolution","Team:Security Solution
Platform","v8.8.0","v8.7.1"],"number":155071,"url":"https://github.com/elastic/kibana/pull/155071","mergeCommit":{"message":"[Security
Solution][Exceptions] - Fix exception operator logic when mapping
conflict (#155071)\n\n## Summary\r\n\r\nAddresses
https://github.com/elastic/kibana/issues/154962
.","sha":"9a095602f87c945dcfd832451e0f6136ec9df5df"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/155071","number":155071,"mergeCommit":{"message":"[Security
Solution][Exceptions] - Fix exception operator logic when mapping
conflict (#155071)\n\n## Summary\r\n\r\nAddresses
https://github.com/elastic/kibana/issues/154962
.","sha":"9a095602f87c945dcfd832451e0f6136ec9df5df"}},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Yara Tercero <yctercero@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-04-17 21:50:06 -04:00 committed by GitHub
parent ca61fca444
commit e33260d701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 12 deletions

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { getMappingConflictsInfo } from '.';
import { getMappingConflictsInfo, fieldSupportsMatches } from '.';
describe('Helpers', () => {
describe('getMappingConflictsInfo', () => {
@ -143,4 +143,42 @@ describe('Helpers', () => {
]);
});
});
describe('fieldSupportsMatches', () => {
test('it returns true if esTypes is keyword', () => {
expect(
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['keyword'] })
).toBeTruthy();
});
test('it returns true if one of the esTypes is kibana type string and another is not', () => {
expect(
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['keyword', 'object'] })
).toBeTruthy();
});
test('it returns true if one of the esTypes is keyword', () => {
expect(
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['keyword', 'unmapped'] })
).toBeTruthy();
});
test('it returns true if one of the esTypes is text', () => {
expect(
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['text', 'unmapped'] })
).toBeTruthy();
});
test('it returns true if all of the esTypes is map to kibana type string', () => {
expect(
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['text', 'keyword'] })
).toBeTruthy();
});
test('it returns false if none of the esTypes map to kibana type string', () => {
expect(
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['bool', 'unmapped'] })
).toBeFalsy();
});
});
});

View file

@ -35,6 +35,7 @@ import {
getDataViewFieldSubtypeNested,
isDataViewFieldSubtypeNested,
} from '@kbn/es-query';
import { castEsToKbnFieldTypeName, KBN_FIELD_TYPES } from '@kbn/field-types';
import {
ALL_OPERATORS,
@ -676,8 +677,13 @@ export const getEntryOnOperatorChange = (
}
};
const fieldSupportsMatches = (field: DataViewFieldBase) => {
return field.type === 'string';
export const isKibanaStringType = (type: string) => {
const kbnFieldType = castEsToKbnFieldTypeName(type);
return kbnFieldType === KBN_FIELD_TYPES.STRING;
};
export const fieldSupportsMatches = (field: DataViewFieldBase) => {
return field.esTypes?.some(isKibanaStringType);
};
/**

View file

@ -26,6 +26,10 @@ import {
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
} from '@kbn/securitysolution-list-constants';
export interface DataViewField extends DataViewFieldBase {
conflictDescriptions?: Record<string, string[]>;
}
export interface OperatorOption {
message: string;
value: string;
@ -35,7 +39,7 @@ export interface OperatorOption {
export interface FormattedBuilderEntry {
id: string;
field: DataViewFieldBase | undefined;
field: DataViewField | undefined;
operator: OperatorOption;
value: string | string[] | undefined;
nested: 'parent' | 'child' | undefined;
@ -117,7 +121,3 @@ export const exceptionListAgnosticSavedObjectType = EXCEPTION_LIST_NAMESPACE_AGN
export type SavedObjectType =
| typeof EXCEPTION_LIST_NAMESPACE
| typeof EXCEPTION_LIST_NAMESPACE_AGNOSTIC;
export interface DataViewField extends DataViewFieldBase {
conflictDescriptions?: Record<string, string[]>;
}

View file

@ -16,7 +16,8 @@
"@kbn/securitysolution-io-ts-list-types",
"@kbn/securitysolution-io-ts-utils",
"@kbn/securitysolution-list-constants",
"@kbn/securitysolution-utils"
"@kbn/securitysolution-utils",
"@kbn/field-types"
],
"exclude": [
"target/**/*",

View file

@ -221,7 +221,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
<>
<EuiSpacer size="s" />
<EuiAccordion
id={'1'}
id={`${entry.id}`}
buttonContent={
<>
<EuiIcon tabIndex={0} type="alert" size="s" css={warningIconCss} />
@ -229,6 +229,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
</>
}
arrowDisplay="none"
data-test-subj="mappingConflictsAccordion"
>
{conflictsInfo.map((info) => {
const groupDetails = info.groupedIndices.map(
@ -254,8 +255,9 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
const customOptionText =
entry.nested == null && allowCustomOptions ? i18n.CUSTOM_COMBOBOX_OPTION_TEXT : undefined;
const helpText =
entry.field?.type !== 'conflict' ? (
entry.field?.conflictDescriptions == null ? (
customOptionText
) : (
<>
@ -411,7 +413,9 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
}
const warning = validateFilePathInput({ os, value: wildcardValue });
actualWarning =
warning === FILENAME_WILDCARD_WARNING ? getWildcardWarning(warning) : warning;
warning === FILENAME_WILDCARD_WARNING
? warning && getWildcardWarning(warning)
: warning;
}
return (