Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Fix draggables to work with escapeId for the ML severity column #41621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface Columns<T, U = T> {
sortable?: boolean | Func<T>;
truncateText?: boolean;
hideForMobile?: boolean;
render?: (item: T, node: U) => void;
render?: (item: T, node: U) => React.ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing this type

width?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import { getAnomaliesHostTableColumnsCurated } from './get_anomalies_host_table_columns';
import { HostsType } from '../../../store/hosts/model';
import * as i18n from './translations';
import { AnomaliesByHost } from '../types';
import { Columns } from '../../load_more_table';
import { TestProviders } from '../../../mock';
import { mount } from 'enzyme';
import React from 'react';

const startDate = new Date(2001).valueOf();
const endDate = new Date(3000).valueOf();
Expand Down Expand Up @@ -58,4 +63,62 @@ describe('get_anomalies_host_table_columns', () => {
);
expect(columns.some(col => col.name === i18n.HOST_NAME)).toEqual(false);
});

test('on host page, we should escape the draggable id', () => {
const columns = getAnomaliesHostTableColumnsCurated(
HostsType.page,
startDate,
endDate,
interval,
narrowDateRange
);
const column = columns.find(col => col.name === i18n.SCORE) as Columns<string, AnomaliesByHost>;
const anomaly: AnomaliesByHost = {
hostName: 'host.name',
anomaly: {
detectorIndex: 0,
entityName: 'entity-name-1',
entityValue: 'entity-value-1',
influencers: [],
jobId: 'job-1',
rowId: 'row-1',
severity: 100,
time: new Date('01/01/2000').valueOf(),
source: {
job_id: 'job-1',
result_type: 'result-1',
probability: 50,
multi_bucket_impact: 0,
record_score: 0,
initial_record_score: 0,
bucket_span: 0,
detector_index: 0,
is_interim: true,
timestamp: new Date('01/01/2000').valueOf(),
by_field_name: 'some field name',
by_field_value: 'some field valuke',
partition_field_name: 'partition field name',
partition_field_value: 'partition field value',
function: 'function-1',
function_description: 'description-1',
typical: [5, 3],
actual: [7, 4],
influencers: [],
},
},
};
if (column != null && column.render != null) {
const wrapper = mount(<TestProviders>{column.render('', anomaly)}</TestProviders>);
expect(
wrapper
.find(
'[draggableId="draggableId.content.anomalies-host-table-severity-host_name-entity-name-1-entity-value-1-100-job-1"]'
)
.first()
.exists()
).toBe(true);
} else {
expect(column).not.toBe(null);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { createExplorerLink } from '../links/create_explorer_link';
import { LocalizedDateTooltip } from '../../localized_date_tooltip';
import { PreferenceFormattedDate } from '../../formatted_date';
import { HostsType } from '../../../store/hosts/model';
import { escapeDataProviderId } from '../../drag_and_drop/helpers';

export const getAnomaliesHostTableColumns = (
startDate: number,
Expand Down Expand Up @@ -68,7 +69,9 @@ export const getAnomaliesHostTableColumns = (
sortable: true,
render: (_, anomaliesByHost) => (
<DraggableScore
id={`anomalies-host-table-severity-${createCompoundHostKey(anomaliesByHost)}`}
id={escapeDataProviderId(
`anomalies-host-table-severity-${createCompoundHostKey(anomaliesByHost)}`
)}
score={anomaliesByHost.anomaly}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import { getAnomaliesNetworkTableColumnsCurated } from './get_anomalies_network_table_columns';
import { NetworkType } from '../../../store/network/model';
import * as i18n from './translations';
import { AnomaliesByNetwork } from '../types';
import { Columns } from '../../load_more_table';
import { mount } from 'enzyme';
import React from 'react';
import { TestProviders } from '../../../mock';

const startDate = new Date(2001).valueOf();
const endDate = new Date(3000).valueOf();
Expand Down Expand Up @@ -58,4 +63,66 @@ describe('get_anomalies_network_table_columns', () => {
);
expect(columns.some(col => col.name === i18n.NETWORK_NAME)).toEqual(false);
});

test('on network page, we should escape the draggable id', () => {
const columns = getAnomaliesNetworkTableColumnsCurated(
NetworkType.page,
startDate,
endDate,
interval,
narrowDateRange
);
const column = columns.find(col => col.name === i18n.SCORE) as Columns<
string,
AnomaliesByNetwork
>;
const anomaly: AnomaliesByNetwork = {
type: 'source.ip',
ip: '127.0.0.1',
anomaly: {
detectorIndex: 0,
entityName: 'entity-name-1',
entityValue: 'entity-value-1',
influencers: [],
jobId: 'job-1',
rowId: 'row-1',
severity: 100,
time: new Date('01/01/2000').valueOf(),
source: {
job_id: 'job-1',
result_type: 'result-1',
probability: 50,
multi_bucket_impact: 0,
record_score: 0,
initial_record_score: 0,
bucket_span: 0,
detector_index: 0,
is_interim: true,
timestamp: new Date('01/01/2000').valueOf(),
by_field_name: 'some field name',
by_field_value: 'some field valuke',
partition_field_name: 'partition field name',
partition_field_value: 'partition field value',
function: 'function-1',
function_description: 'description-1',
typical: [5, 3],
actual: [7, 4],
influencers: [],
},
},
};
if (column != null && column.render != null) {
const wrapper = mount(<TestProviders>{column.render('', anomaly)}</TestProviders>);
expect(
wrapper
.find(
'[draggableId="draggableId.content.anomalies-network-table-severity-127_0_0_1-entity-name-1-entity-value-1-100-job-1"]'
)
.first()
.exists()
).toBe(true);
} else {
expect(column).not.toBe(null);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { createExplorerLink } from '../links/create_explorer_link';
import { LocalizedDateTooltip } from '../../localized_date_tooltip';
import { PreferenceFormattedDate } from '../../formatted_date';
import { NetworkType } from '../../../store/network/model';
import { escapeDataProviderId } from '../../drag_and_drop/helpers';

export const getAnomaliesNetworkTableColumns = (
startDate: number,
Expand Down Expand Up @@ -66,7 +67,9 @@ export const getAnomaliesNetworkTableColumns = (
sortable: true,
render: (_, anomaliesByNetwork) => (
<DraggableScore
id={`anomalies-network-table-severity-${createCompoundNetworkKey(anomaliesByNetwork)}`}
id={escapeDataProviderId(
`anomalies-network-table-severity-${createCompoundNetworkKey(anomaliesByNetwork)}`
)}
score={anomaliesByNetwork.anomaly}
/>
),
Expand Down