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

[Security Solution] Fix rules table refresh after rule's import #144359

Merged
merged 3 commits into from
Nov 2, 2022
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 @@ -5,7 +5,7 @@
* 2.0.
*/

import { TOASTER } from '../../screens/alerts_detection_rules';
import { RULES_ROW, RULES_TABLE, TOASTER } from '../../screens/alerts_detection_rules';
import { importRules, importRulesWithOverwriteAll } from '../../tasks/alerts_detection_rules';
import { cleanKibana, deleteAlertsAndRules, reload } from '../../tasks/common';
import { login, visitWithoutDateRange } from '../../tasks/login';
Expand All @@ -24,6 +24,9 @@ describe('Import rules', () => {
});

it('Imports a custom rule with exceptions', function () {
const expectedNumberOfRules = 1;
const expectedImportedRuleName = 'Test Custom Rule';

importRules('7_16_rules.ndjson');

cy.wait('@import').then(({ response }) => {
Expand All @@ -32,6 +35,13 @@ describe('Import rules', () => {
'have.text',
'Successfully imported 1 ruleSuccessfully imported 2 exceptions.'
);

cy.get(RULES_TABLE).then(($table) => {
const rulesRow = cy.wrap($table.find(RULES_ROW));

rulesRow.should('have.length', expectedNumberOfRules);
rulesRow.should('include.text', expectedImportedRuleName);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useCallback } from 'react';
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';

import { APP_UI_ID } from '../../../../../common/constants';
Expand All @@ -32,6 +32,7 @@ import { useListsConfig } from '../../../../detections/containers/detection_engi
import { redirectToDetections } from '../../../../detections/pages/detection_engine/rules/helpers';

import { useInvalidateFindRulesQuery } from '../../../rule_management/api/hooks/use_find_rules_query';
import { useInvalidateFetchPrebuiltRulesStatusQuery } from '../../../rule_management/api/hooks/use_fetch_prebuilt_rules_status_query';
import { importRules } from '../../../rule_management/logic';
import { usePrePackagedRulesInstallationStatus } from '../../../rule_management/logic/use_pre_packaged_rules_installation_status';
import { usePrePackagedTimelinesInstallationStatus } from '../../../rule_management/logic/use_pre_packaged_timelines_installation_status';
Expand All @@ -47,6 +48,11 @@ const RulesPageComponent: React.FC = () => {
const [isValueListFlyoutVisible, showValueListFlyout, hideValueListFlyout] = useBoolState();
const { navigateToApp } = useKibana().services.application;
const invalidateFindRulesQuery = useInvalidateFindRulesQuery();
const invalidateFetchPrebuiltRulesStatusQuery = useInvalidateFetchPrebuiltRulesStatusQuery();
const invalidateRules = useCallback(() => {
invalidateFindRulesQuery();
invalidateFetchPrebuiltRulesStatusQuery();
}, [invalidateFindRulesQuery, invalidateFetchPrebuiltRulesStatusQuery]);

const [
{
Expand Down Expand Up @@ -94,7 +100,7 @@ const RulesPageComponent: React.FC = () => {
description={i18n.SELECT_RULE}
errorMessage={i18n.IMPORT_FAILED}
failedDetailed={i18n.IMPORT_FAILED_DETAILED}
importComplete={invalidateFindRulesQuery}
importComplete={invalidateRules}
importData={importRules}
successMessage={i18n.SUCCESSFULLY_IMPORTED_RULES}
showModal={isImportModalVisible}
Expand Down