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] Adds 'Load prebuilt rules' Cypress test #59529

Merged
merged 3 commits into from
Mar 6, 2020
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
@@ -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 @@ -129,7 +129,12 @@ const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
}
title={i18n.PAGE_TITLE}
>
<EuiButton fill href={getRulesUrl()} iconType="gear">
<EuiButton
fill
href={getRulesUrl()}
iconType="gear"
data-test-subj="manage-signal-detection-rules"
>
{i18n.BUTTON_MANAGE_RULES}
</EuiButton>
</DetectionEngineHeaderPage>
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
5 changes: 5 additions & 0 deletions x-pack/test/siem_cypress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { resolve } from 'path';

import { FtrConfigProviderContext } from '@kbn/test/types/ftr';

import { CA_CERT_PATH } from '@kbn/dev-utils';

import { SiemCypressTestRunner } from './runner';

export default async function({ readConfigFile }: FtrConfigProviderContext) {
Expand All @@ -32,6 +34,8 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
serverArgs: [
...xpackFunctionalTestsConfig.get('esTestCluster.serverArgs'),
// define custom es server here
'xpack.security.authc.api_key.enabled=true',
'xpack.security.enabled=true',
],
},

Expand All @@ -41,6 +45,7 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
...xpackFunctionalTestsConfig.get('kbnTestServer.serverArgs'),
'--csp.strict=false',
// define custom kibana server args here
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
],
},
};
Expand Down