Skip to content
Closed
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
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ELASTIC_RULES_BTN, RULES_TABLE, RULES_ROW } from '../screens/signal_detection_rules';

import {
changeToThreeHundredRowsPerPage,
loadPrebuiltDetectionRules,
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForPrebuiltDetectionRulesToBeLoaded,
waitForRulesToBeLoaded,
} from '../tasks/signal_detection_rules';
import {
goToManageSignalDetectionRules,
waitForSignalsIndexToBeCreated,
waitForSignalsPanelToBeLoaded,
} from '../tasks/detections';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS } from '../urls/navigation';

describe('Signal detection rules', () => {
before(() => {
loginAndWaitForPageWithoutDateRange(DETECTIONS);
});
it('Loads prebuilt rules', () => {
waitForSignalsPanelToBeLoaded();
waitForSignalsIndexToBeCreated();
goToManageSignalDetectionRules();
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded();
loadPrebuiltDetectionRules();
waitForPrebuiltDetectionRulesToBeLoaded();

const expectedElasticRulesBtnText = 'Elastic rules (92)';
cy.get(ELASTIC_RULES_BTN)
.invoke('text')
.should('eql', expectedElasticRulesBtnText);

changeToThreeHundredRowsPerPage();
waitForRulesToBeLoaded();

const expectedNumberOfRules = 92;
cy.get(RULES_TABLE).then($table => {
cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules);
});
});
});
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/screens/detections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const LOADING_SIGNALS_PANEL = '[data-test-subj="loading-signals-panel"]';

export const MANAGE_SIGNAL_DETECTION_RULES_BTN = '[data-test-subj="manage-signal-detection-rules"]';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const ELASTIC_RULES_BTN = '[data-test-subj="show-elastic-rules-filter-button"]';

export const LOAD_PREBUILT_RULES_BTN = '[data-test-subj="load-prebuilt-rules"]';

export const LOADING_INITIAL_PREBUILT_RULES_TABLE =
'[data-test-subj="initialLoadingPanelAllRulesTable"]';

export const LOADING_SPINNER = '[data-test-subj="loading-spinner"]';

export const PAGINATION_POPOVER_BTN = '[data-test-subj="tablePaginationPopoverButton"]';

export const RULES_TABLE = '[data-test-subj="rules-table"]';

export const RULES_ROW = '.euiTableRow';

export const THREE_HUNDRED_ROWS = '[data-test-subj="tablePagination-300-rows"]';
28 changes: 28 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/tasks/detections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { LOADING_SIGNALS_PANEL, MANAGE_SIGNAL_DETECTION_RULES_BTN } from '../screens/detections';

export const goToManageSignalDetectionRules = () => {
cy.get(MANAGE_SIGNAL_DETECTION_RULES_BTN)
.should('exist')
.click({ force: true });
};

export const waitForSignalsIndexToBeCreated = () => {
cy.request({ url: '/api/detection_engine/index', retryOnStatusCodeFailure: true }).then(
response => {
if (response.status !== 200) {
cy.wait(7500);
}
}
);
};

export const waitForSignalsPanelToBeLoaded = () => {
cy.get(LOADING_SIGNALS_PANEL).should('exist');
cy.get(LOADING_SIGNALS_PANEL).should('not.exist');
};
40 changes: 40 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/tasks/signal_detection_rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import {
LOAD_PREBUILT_RULES_BTN,
LOADING_INITIAL_PREBUILT_RULES_TABLE,
LOADING_SPINNER,
PAGINATION_POPOVER_BTN,
RULES_TABLE,
THREE_HUNDRED_ROWS,
} from '../screens/signal_detection_rules';

export const changeToThreeHundredRowsPerPage = () => {
cy.get(PAGINATION_POPOVER_BTN).click({ force: true });
cy.get(THREE_HUNDRED_ROWS).click();
};

export const loadPrebuiltDetectionRules = () => {
cy.get(LOAD_PREBUILT_RULES_BTN)
.should('exist')
.click({ force: true });
};

export const waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded = () => {
cy.get(LOADING_INITIAL_PREBUILT_RULES_TABLE).should('exist');
cy.get(LOADING_INITIAL_PREBUILT_RULES_TABLE).should('not.exist');
};

export const waitForPrebuiltDetectionRulesToBeLoaded = () => {
cy.get(LOAD_PREBUILT_RULES_BTN).should('not.exist');
cy.get(RULES_TABLE).should('exist');
};

export const waitForRulesToBeLoaded = () => {
cy.get(LOADING_SPINNER).should('exist');
cy.get(LOADING_SPINNER).should('not.exist');
};
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/siem/cypress/urls/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const DETECTIONS = 'app/siem#/detections';
export const HOSTS_PAGE = '/app/siem#/hosts/allHosts';
export const HOSTS_PAGE_TAB_URLS = {
allHosts: '/app/siem#/hosts/allHosts',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Loader = React.memo<LoaderProps>(({ children, overlay, overlayBackg
<Aside overlay={overlay} overlayBackground={overlayBackground}>
<FlexGroup overlay={{ overlay }}>
<EuiFlexItem grow={false}>
<EuiLoadingSpinner size={size} />
<EuiLoadingSpinner data-test-subj="loading-spinner" size={size} />
</EuiFlexItem>

{children && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const SignalsTableComponent: React.FC<SignalsTableComponentProps> = ({
return (
<EuiPanel>
<HeaderSection title={i18n.SIGNALS_TABLE_TITLE} />
<EuiLoadingContent />
<EuiLoadingContent data-test-subj="loading-signals-panel" />
</EuiPanel>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { useParams } from 'react-router-dom';
import { StickyContainer } from 'react-sticky';
import { connect, ConnectedProps } from 'react-redux';

import { useGlobalTime } from '../../containers/global_time';
import { useWithSource } from '../../containers/source';
import { GlobalTime } from '../../containers/global_time';
import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../containers/source';
import { AlertsTable } from '../../components/alerts_viewer/alerts_table';
import { FiltersGlobal } from '../../components/filters_global';
import {
Expand Down Expand Up @@ -88,10 +88,6 @@ const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
signalIndexName,
]);

const { indexPattern, contentAvailable } = useWithSource(indexToAdd);

const { to, from, deleteQuery, setQuery } = useGlobalTime();

if (isUserAuthenticated != null && !isUserAuthenticated && !loading) {
return (
<WrapperPage>
Expand All @@ -113,81 +109,94 @@ const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
<>
{hasEncryptionKey != null && !hasEncryptionKey && <NoApiIntegrationKeyCallOut />}
{hasIndexWrite != null && !hasIndexWrite && <NoWriteSignalsCallOut />}
{contentAvailable ? (
<StickyContainer>
<FiltersGlobal>
<SiemSearchBar id="global" indexPattern={indexPattern} />
</FiltersGlobal>
<WrapperPage>
<DetectionEngineHeaderPage
subtitle={
lastSignals != null && (
<>
{i18n.LAST_SIGNAL}
{': '}
{lastSignals}
</>
)
}
title={i18n.PAGE_TITLE}
>
<EuiButton fill href={getRulesUrl()} iconType="gear">
{i18n.BUTTON_MANAGE_RULES}
</EuiButton>
</DetectionEngineHeaderPage>

<>
<SiemNavigation navTabs={detectionsTabs} />
<EuiSpacer />
{tabName === DetectionEngineTab.signals && (
<>
<SignalsHistogramPanel
deleteQuery={deleteQuery}
filters={filters}
from={from}
query={query}
setQuery={setQuery}
showTotalSignalsCount={true}
signalIndexName={signalIndexName}
stackByOptions={signalsHistogramOptions}
to={to}
updateDateRange={updateDateRangeCallback}
/>
<EuiSpacer size="l" />
<SignalsTable
loading={loading}
hasIndexWrite={hasIndexWrite ?? false}
canUserCRUD={(canUserCRUD ?? false) && (hasEncryptionKey ?? false)}
from={from}
signalsIndex={signalIndexName ?? ''}
to={to}
/>
</>
)}
{tabName === DetectionEngineTab.alerts && (
<>
<AlertsByCategory
deleteQuery={deleteQuery}
filters={filters}
from={from}
hideHeaderChildren={true}
indexPattern={indexPattern}
query={query}
setQuery={setQuery}
to={to}
/>
<AlertsTable endDate={to} startDate={from} />
</>
)}
</>
</WrapperPage>
</StickyContainer>
) : (
<WrapperPage>
<DetectionEngineHeaderPage border title={i18n.PAGE_TITLE} />
<DetectionEngineEmptyPage />
</WrapperPage>
)}
<WithSource sourceId="default" indexToAdd={indexToAdd}>
{({ indicesExist, indexPattern }) => {
return indicesExistOrDataTemporarilyUnavailable(indicesExist) ? (
<StickyContainer>
<FiltersGlobal>
<SiemSearchBar id="global" indexPattern={indexPattern} />
</FiltersGlobal>
<WrapperPage>
<DetectionEngineHeaderPage
subtitle={
lastSignals != null && (
<>
{i18n.LAST_SIGNAL}
{': '}
{lastSignals}
</>
)
}
title={i18n.PAGE_TITLE}
>
<EuiButton
fill
href={getRulesUrl()}
iconType="gear"
data-test-subj="manage-signal-detection-rules"
>
{i18n.BUTTON_MANAGE_RULES}
</EuiButton>
</DetectionEngineHeaderPage>

<GlobalTime>
{({ to, from, deleteQuery, setQuery }) => (
<>
<SiemNavigation navTabs={detectionsTabs} />
<EuiSpacer />
{tabName === DetectionEngineTab.signals && (
<>
<SignalsHistogramPanel
deleteQuery={deleteQuery}
filters={filters}
from={from}
query={query}
setQuery={setQuery}
showTotalSignalsCount={true}
signalIndexName={signalIndexName}
stackByOptions={signalsHistogramOptions}
to={to}
updateDateRange={updateDateRangeCallback}
/>
<EuiSpacer size="l" />
<SignalsTable
loading={loading}
hasIndexWrite={hasIndexWrite ?? false}
canUserCRUD={(canUserCRUD ?? false) && (hasEncryptionKey ?? false)}
from={from}
signalsIndex={signalIndexName ?? ''}
to={to}
/>
</>
)}
{tabName === DetectionEngineTab.alerts && (
<>
<AlertsByCategory
deleteQuery={deleteQuery}
filters={filters}
from={from}
hideHeaderChildren={true}
indexPattern={indexPattern}
query={query}
setQuery={setQuery}
to={to}
/>
<AlertsTable endDate={to} startDate={from} />
</>
)}
</>
)}
</GlobalTime>
</WrapperPage>
</StickyContainer>
) : (
<WrapperPage>
<DetectionEngineHeaderPage border title={i18n.PAGE_TITLE} />
<DetectionEngineEmptyPage />
</WrapperPage>
);
}}
</WithSource>
<SpyRoute />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export const AllRules = React.memo<AllRulesProps>(
</UtilityBarSection>
</UtilityBar>
<MyEuiBasicTable
data-test-subj="rules-table"
columns={columns}
isSelectable={!hasNoPermissions ?? false}
itemId="id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const PrePackagedRulesPromptComponent: React.FC<PrePackagedRulesPromptProps> = (
isDisabled={userHasNoPermissions}
isLoading={loading}
onClick={handlePreBuiltCreation}
data-test-subj="load-prebuilt-rules"
>
{i18n.PRE_BUILT_ACTION}
</EuiButton>
Expand Down
Loading