Skip to content

Commit

Permalink
[8.7] [Security Solution][Exceptions] - Fix exception operator logic …
Browse files Browse the repository at this point in the history
…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)](#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
#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
#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
#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>
  • Loading branch information
kibanamachine and yctercero authored Apr 18, 2023
1 parent ca61fca commit e33260d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { getMappingConflictsInfo } from '.';
import { getMappingConflictsInfo, fieldSupportsMatches } from '.';

describe('Helpers', () => {
describe('getMappingConflictsInfo', () => {
Expand Down Expand Up @@ -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();
});
});
});
10 changes: 8 additions & 2 deletions packages/kbn-securitysolution-list-utils/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getDataViewFieldSubtypeNested,
isDataViewFieldSubtypeNested,
} from '@kbn/es-query';
import { castEsToKbnFieldTypeName, KBN_FIELD_TYPES } from '@kbn/field-types';

import {
ALL_OPERATORS,
Expand Down Expand Up @@ -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);
};

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-securitysolution-list-utils/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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[]>;
}
3 changes: 2 additions & 1 deletion packages/kbn-securitysolution-list-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,15 @@ 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} />
{i18n.FIELD_CONFLICT_INDICES_WARNING_DESCRIPTION}
</>
}
arrowDisplay="none"
data-test-subj="mappingConflictsAccordion"
>
{conflictsInfo.map((info) => {
const groupDetails = info.groupedIndices.map(
Expand All @@ -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
) : (
<>
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit e33260d

Please sign in to comment.