Skip to content

Commit

Permalink
fixed log type labels; cypress tests
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan committed Jul 31, 2023
1 parent 91d7014 commit e44d3cc
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 183 deletions.
1 change: 0 additions & 1 deletion cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ const fillDetailsForm = (detectorName, dataSource) => {
getDataSourceField().selectComboboxItem(dataSource);
getLogTypeField().selectComboboxItem(cypressLogTypeDns);
getLogTypeField().blur();
// selectDnsLogType();
};

const createDetector = (detectorName, dataSource, expectFailure) => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/3_alerts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Alerts', () => {
expect($tr, `timestamp`).to.contain(date);
expect($tr, `rule name`).to.contain('Cypress USB Rule');
expect($tr, `detector name`).to.contain(testDetector.name);
expect($tr, `log type`).to.contain('Windows');
expect($tr, `log type`).to.contain('windows');
});

// Close the flyout
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/4_findings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Findings', () => {
cy.contains('No items found').should('not.exist');

// Check for expected findings
cy.contains('Windows');
cy.contains('windows');
cy.contains('High');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CorrelationFinding, CorrelationGraphData, DateTimeFilter } from '../../
import React from 'react';
import { RouteComponentProps } from 'react-router-dom';
import {
defaultLogTypeFilterItemOptions,
getDefaultLogTypeFilterItemOptions,
defaultSeverityFilterItemOptions,
emptyGraphData,
getAbbrFromLogType,
Expand Down Expand Up @@ -85,7 +85,7 @@ export class Correlations extends React.Component<CorrelationsProps, Correlation
this.state = {
recentlyUsedRanges: [DEFAULT_DATE_RANGE],
graphData: { ...emptyGraphData },
logTypeFilterOptions: [...defaultLogTypeFilterItemOptions],
logTypeFilterOptions: [...getDefaultLogTypeFilterItemOptions()],
severityFilterOptions: [...defaultSeverityFilterItemOptions],
specificFindingInfo: undefined,
loadingGraphData: false,
Expand Down
18 changes: 16 additions & 2 deletions public/pages/Correlations/containers/CreateCorrelationRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
isInvalid={isInvalidInputForQuery('logType')}
placeholder="Select a log type"
data-test-subj={'rule_type_dropdown'}
options={ruleTypes.map(({ value, label }) => ({ value, label }))}
options={ruleTypes.map(({ label }) => ({
value: label.toLowerCase(),
label,
}))}
singleSelection={{ asPlainText: true }}
onChange={(e) => {
props.handleChange(`queries[${queryIdx}].logType`)(
Expand All @@ -283,7 +286,18 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
}}
onBlur={props.handleBlur(`queries[${queryIdx}].logType`)}
selectedOptions={
query.logType ? [{ value: query.logType, label: query.logType }] : []
query.logType
? [
{
value: query.logType,
label:
ruleTypes.find(
(logType) =>
logType.label.toLowerCase() === query.logType.toLowerCase()
)?.label || query.logType,
},
]
: []
}
isClearable={true}
onCreateOption={(e) => {
Expand Down
15 changes: 6 additions & 9 deletions public/pages/Correlations/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ export const graphRenderOptions = {
},
};

export const defaultLogTypeFilterItemOptions: FilterItem[] = Object.values(ruleTypes).map(
(type) => {
return {
name: `${type.abbr}: ${type.label}`,
id: type.value,
checked: 'on',
};
}
);
export const getDefaultLogTypeFilterItemOptions: () => FilterItem[] = () =>
Object.values(ruleTypes).map((type) => ({
name: `${type.label}`,
id: type.label.toLowerCase(),
checked: 'on',
}));

export const defaultSeverityFilterItemOptions: FilterItem[] = Object.values(ruleSeverity).map(
(sev) => {
Expand Down
2 changes: 1 addition & 1 deletion public/pages/LogTypes/components/LogTypeDetailsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const LogTypeDetailsTab: React.FC<LogTypeDetailsTabProps> = ({
})
}
placeholder="Enter name for log type"
disabled={!isEditMode || !!logTypeDetails.detectionRules}
disabled={!isEditMode || !!logTypeDetails.detectionRulesCount}
/>
</EuiFormRow>
<EuiSpacer />
Expand Down
5 changes: 3 additions & 2 deletions public/pages/LogTypes/components/LogTypeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const LogTypeForm: React.FC<LogTypeFormProps> = ({
updateErrors(newLogType);
}}
placeholder="Enter name for the log type"
disabled={!isEditMode || !!logTypeDetails.detectionRules}
readOnly={!isEditMode}
disabled={isEditMode && !!logTypeDetails.detectionRulesCount}
/>
</EuiFormRow>
<EuiSpacer />
Expand All @@ -100,7 +101,7 @@ export const LogTypeForm: React.FC<LogTypeFormProps> = ({
updateErrors(newLogType);
}}
placeholder="Description of the log type"
disabled={!isEditMode}
readOnly={!isEditMode}
/>
</EuiFormRow>
{isEditMode ? (
Expand Down
2 changes: 1 addition & 1 deletion public/pages/LogTypes/containers/CreateLogType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const CreateLogType: React.FC<CreateLogTypeProps> = ({ history, notificat
hideHeaderBorder={true}
>
<LogTypeForm
logTypeDetails={{ ...logTypeDetails, id: '', detectionRules: 0 }}
logTypeDetails={{ ...logTypeDetails, id: '', detectionRulesCount: 0 }}
isEditMode={true}
confirmButtonText={'Create rule category'}
notifications={notifications}
Expand Down
28 changes: 15 additions & 13 deletions public/pages/LogTypes/containers/LogType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const LogType: React.FC<LogTypeProps> = ({ notifications, history }) => {

const updateRules = useCallback(async (details: LogTypeItem, intialDetails: LogTypeItem) => {
const rulesRes = await DataStore.rules.getAllRules({
'rule.category': [logTypeId],
'rule.category': [details.name.toLowerCase()],
});
const ruleItems = rulesRes.map((rule) => ({
title: rule._source.title,
Expand All @@ -74,22 +74,15 @@ export const LogType: React.FC<LogTypeProps> = ({ notifications, history }) => {
setLoadingRules(false);
setLogTypeDetails({
...details,
detectionRules: ruleItems.length,
detectionRulesCount: ruleItems.length,
});
setInitialLogTypeDetails({
...intialDetails,
detectionRules: ruleItems.length,
detectionRulesCount: ruleItems.length,
});
}, []);

useEffect(() => {
context?.chrome.setBreadcrumbs([
BREADCRUMBS.SECURITY_ANALYTICS,
BREADCRUMBS.DETECTORS,
BREADCRUMBS.LOG_TYPES,
{ text: logTypeId },
]);

const getLogTypeDetails = async () => {
const details = await DataStore.logTypes.getLogType(logTypeId);

Expand All @@ -98,7 +91,14 @@ export const LogType: React.FC<LogTypeProps> = ({ notifications, history }) => {
return;
}

updateRules(details, details);
context?.chrome.setBreadcrumbs([
BREADCRUMBS.SECURITY_ANALYTICS,
BREADCRUMBS.DETECTORS,
BREADCRUMBS.LOG_TYPES,
{ text: details.name },
]);
const logTypeItem = { ...details, detectionRulesCount: details.detectionRules.length };
updateRules(logTypeItem, logTypeItem);
};

getLogTypeDetails();
Expand Down Expand Up @@ -152,7 +152,7 @@ export const LogType: React.FC<LogTypeProps> = ({ notifications, history }) => {
{showDeleteModal && (
<DeleteLogTypeModal
logTypeName={logTypeDetails.name}
detectionRulesCount={logTypeDetails.detectionRules}
detectionRulesCount={logTypeDetails.detectionRulesCount}
closeModal={() => setShowDeleteModal(false)}
onConfirm={deleteLogType}
/>
Expand Down Expand Up @@ -186,7 +186,9 @@ export const LogType: React.FC<LogTypeProps> = ({ notifications, history }) => {
</EuiFlexItem>
<EuiFlexItem>
<EuiDescriptionList
listItems={[{ title: 'Detection rules', description: logTypeDetails.detectionRules }]}
listItems={[
{ title: 'Detection rules', description: logTypeDetails.detectionRulesCount },
]}
/>
</EuiFlexItem>
<EuiFlexItem>
Expand Down
137 changes: 0 additions & 137 deletions public/pages/LogTypes/containers/LogTypeDetails.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion public/pages/Rules/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const getRulesTableColumns = (
width: '10%',
truncateText: true,
render: (category: string) =>
ruleTypes.find((ruleType) => ruleType.value === category)?.label || DEFAULT_EMPTY_DATA,
ruleTypes.find((ruleType) => ruleType.label.toLowerCase() === category)?.label ||
DEFAULT_EMPTY_DATA,
},
{
field: 'source',
Expand Down
18 changes: 16 additions & 2 deletions public/services/LogTypeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@ export default class LogTypeService {

searchLogTypes = async (id?: string): Promise<ServerResponse<SearchLogTypesResponse>> => {
const url = `..${API.LOGTYPE_BASE}/_search`;
const query = id ? JSON.stringify({ terms: { _id: [id] } }) : undefined;
return (await this.httpClient.post(url, { body: query })) as ServerResponse<
const query = id
? {
terms: { _id: [id] },
}
: {
bool: {
must: {
query_string: {
query:
'(source: Sigma and !(name: others*) and !(name: test*)) or (source: Custom)',
},
},
},
};
const queryString = JSON.stringify(query);
return (await this.httpClient.post(url, { body: queryString })) as ServerResponse<
SearchLogTypesResponse
>;
};
Expand Down
Loading

0 comments on commit e44d3cc

Please sign in to comment.