Skip to content

Commit

Permalink
[SIEM] Cypress preparation for Jenkins (#59013)
Browse files Browse the repository at this point in the history
* updates events viewer test

* updates login tasks

* updates ml conditional links

* updates url state

* updates timeline screen

* updates timeline tasks

* updates test files

* adds jenkins needed files

* ignoring isAttached lines due to a known error in Cypress (cypress-io/cypress#4408)

* updates loop script

* updates readme with new cypress command explanation

* removes skip

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
MadameSheema and elasticmachine authored Mar 3, 2020
1 parent 690e3a6 commit 02f89f0
Show file tree
Hide file tree
Showing 20 changed files with 4,210 additions and 64 deletions.
21 changes: 21 additions & 0 deletions test/scripts/jenkins_siem_cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

source test/scripts/jenkins_test_setup.sh

installDir="$PARENT_DIR/install/kibana"
destDir="${installDir}-${CI_WORKER_NUMBER}"
cp -R "$installDir" "$destDir"

export KIBANA_INSTALL_DIR="$destDir"

echo " -> Running SIEM cypress tests"
cd "$XPACK_DIR"

checks-reporter-with-killswitch "SIEM Cypress Tests" \
node scripts/functional_tests \
--debug --bail \
--kibana-install-dir "$KIBANA_INSTALL_DIR" \
--config test/siem_cypress/config.ts

echo ""
echo ""
24 changes: 24 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,30 @@ cd x-pack/legacy/plugins/siem
CYPRESS_baseUrl=http://localhost:5601 CYPRESS_ELASTICSEARCH_USERNAME=elastic CYPRESS_ELASTICSEARCH_PASSWORD=<password> yarn cypress:run
```

## Running (Headless) Tests on the Command Line as a Jenkins execution

To run (headless) tests as a Jenkins execution.

1. First bootstrap kibana changes from the Kibana root directory:

```sh
yarn kbn bootstrap
```

2. Launch Cypress command line test runner:

```sh
cd x-pack/legacy/plugins/siem
yarn cypress:run-as-ci
```

Note that with this type of execution you don't need to have running a kibana and elasticsearch instance. This is because
the command, as it would happen in the CI, will launch the instances. The elasticsearch instance will be fed with the data
placed in: `x-pack/test/siem_cypress/es_archives`.

As in this case we want to mimic a CI execution we want to execute the tests with the same set of data, this is why
in this case does not make sense to override Cypress environment variables.

## Reporting

When Cypress tests are run on the command line via `yarn cypress:run`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('Events Viewer', () => {
});

it('filters the events by applying filter criteria from the search bar at the top of the page', () => {
const filterInput = '4bf34c1c-eaa9-46de-8921-67a4ccc49829'; // this will never match real data
const filterInput = 'aa7ca589f1b8220002f2fc61c64cfbf1'; // this will never match real data
cy.get(HEADER_SUBTITLE)
.invoke('text')
.then(initialNumberOfEvents => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { KQL_INPUT } from '../screens/siem_header';

import { loginAndWaitForPage } from '../tasks/login';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import {
mlHostMultiHostKqlQuery,
Expand All @@ -26,7 +26,7 @@ import {

describe('ml conditional links', () => {
it('sets the KQL from a single IP with a value for the query', () => {
loginAndWaitForPage(mlNetworkSingleIpKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkSingleIpKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -35,7 +35,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a multiple IPs with a null for the query', () => {
loginAndWaitForPage(mlNetworkMultipleIpNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkMultipleIpNullKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -44,7 +44,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a multiple IPs with a value for the query', () => {
loginAndWaitForPage(mlNetworkMultipleIpKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkMultipleIpKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -53,7 +53,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a $ip$ with a value for the query', () => {
loginAndWaitForPage(mlNetworkKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -62,7 +62,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a single host name with a value for query', () => {
loginAndWaitForPage(mlHostSingleHostKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostSingleHostKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -71,7 +71,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a multiple host names with null for query', () => {
loginAndWaitForPage(mlHostMultiHostNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostMultiHostNullKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -80,7 +80,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a multiple host names with a value for query', () => {
loginAndWaitForPage(mlHostMultiHostKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostMultiHostKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -89,7 +89,7 @@ describe('ml conditional links', () => {
});

it('sets the KQL from a undefined/null host name but with a value for query', () => {
loginAndWaitForPage(mlHostVariableHostKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostVariableHostKqlQuery);
cy.get(KQL_INPUT).should(
'have.attr',
'value',
Expand All @@ -98,103 +98,103 @@ describe('ml conditional links', () => {
});

it('redirects from a single IP with a null for the query', () => {
loginAndWaitForPage(mlNetworkSingleIpNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkSingleIpNullKqlQuery);
cy.url().should(
'include',
'/app/siem#/network/ip/127.0.0.1/source?timerange=(global:(linkTo:!(timeline),timerange:(from:1566990000000,kind:absolute,to:1567000799999)),timeline:(linkTo:!(global),timerange:(from:1566990000000,kind:absolute,to:1567000799999)))'
);
});

it('redirects from a single IP with a value for the query', () => {
loginAndWaitForPage(mlNetworkSingleIpKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkSingleIpKqlQuery);
cy.url().should(
'include',
"/app/siem#/network/ip/127.0.0.1/source?query=(language:kuery,query:'(process.name:%20%22conhost.exe%22%20or%20process.name:%20%22sc.exe%22)')&timerange=(global:(linkTo:!(timeline),timerange:(from:1566990000000,kind:absolute,to:1567000799999)),timeline:(linkTo:!(global),timerange:(from:1566990000000,kind:absolute,to:1567000799999)))"
);
});

it('redirects from a multiple IPs with a null for the query', () => {
loginAndWaitForPage(mlNetworkMultipleIpNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkMultipleIpNullKqlQuery);
cy.url().should(
'include',
"app/siem#/network/flows?query=(language:kuery,query:'((source.ip:%20%22127.0.0.1%22%20or%20destination.ip:%20%22127.0.0.1%22)%20or%20(source.ip:%20%22127.0.0.2%22%20or%20destination.ip:%20%22127.0.0.2%22))')&timerange=(global:(linkTo:!(timeline),timerange:(from:1566990000000,kind:absolute,to:1567000799999)),timeline:(linkTo:!(global),timerange:(from:1566990000000,kind:absolute,to:1567000799999))"
);
});

it('redirects from a multiple IPs with a value for the query', () => {
loginAndWaitForPage(mlNetworkMultipleIpKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkMultipleIpKqlQuery);
cy.url().should(
'include',
"/app/siem#/network/flows?query=(language:kuery,query:'((source.ip:%20%22127.0.0.1%22%20or%20destination.ip:%20%22127.0.0.1%22)%20or%20(source.ip:%20%22127.0.0.2%22%20or%20destination.ip:%20%22127.0.0.2%22))%20and%20((process.name:%20%22conhost.exe%22%20or%20process.name:%20%22sc.exe%22))')&timerange=(global:(linkTo:!(timeline),timerange:(from:1566990000000,kind:absolute,to:1567000799999)),timeline:(linkTo:!(global),timerange:(from:1566990000000,kind:absolute,to:1567000799999)))"
);
});

it('redirects from a $ip$ with a null query', () => {
loginAndWaitForPage(mlNetworkNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkNullKqlQuery);
cy.url().should(
'include',
'/app/siem#/network/flows?timerange=(global:(linkTo:!(timeline),timerange:(from:1566990000000,kind:absolute,to:1567000799999)),timeline:(linkTo:!(global),timerange:(from:1566990000000,kind:absolute,to:1567000799999)))'
);
});

it('redirects from a $ip$ with a value for the query', () => {
loginAndWaitForPage(mlNetworkKqlQuery);
loginAndWaitForPageWithoutDateRange(mlNetworkKqlQuery);
cy.url().should(
'include',
"/app/siem#/network/flows?query=(language:kuery,query:'(process.name:%20%22conhost.exe%22%20or%20process.name:%20%22sc.exe%22)')&timerange=(global:(linkTo:!(timeline),timerange:(from:1566990000000,kind:absolute,to:1567000799999)),timeline:(linkTo:!(global),timerange:(from:1566990000000,kind:absolute,to:1567000799999)))"
);
});

it('redirects from a single host name with a null for the query', () => {
loginAndWaitForPage(mlHostSingleHostNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostSingleHostNullKqlQuery);
cy.url().should(
'include',
'/app/siem#/hosts/siem-windows/anomalies?timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))'
);
});

it('redirects from a host name with a variable in the query', () => {
loginAndWaitForPage(mlHostSingleHostKqlQueryVariable);
loginAndWaitForPageWithoutDateRange(mlHostSingleHostKqlQueryVariable);
cy.url().should(
'include',
'/app/siem#/hosts/siem-windows/anomalies?timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))'
);
});

it('redirects from a single host name with a value for query', () => {
loginAndWaitForPage(mlHostSingleHostKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostSingleHostKqlQuery);
cy.url().should(
'include',
"/app/siem#/hosts/siem-windows/anomalies?query=(language:kuery,query:'(process.name:%20%22conhost.exe%22%20or%20process.name:%20%22sc.exe%22)')&timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))"
);
});

it('redirects from a multiple host names with null for query', () => {
loginAndWaitForPage(mlHostMultiHostNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostMultiHostNullKqlQuery);
cy.url().should(
'include',
"/app/siem#/hosts/anomalies?query=(language:kuery,query:'(host.name:%20%22siem-windows%22%20or%20host.name:%20%22siem-suricata%22)')&timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))"
);
});

it('redirects from a multiple host names with a value for query', () => {
loginAndWaitForPage(mlHostMultiHostKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostMultiHostKqlQuery);
cy.url().should(
'include',
"/app/siem#/hosts/anomalies?query=(language:kuery,query:'(host.name:%20%22siem-windows%22%20or%20host.name:%20%22siem-suricata%22)%20and%20((process.name:%20%22conhost.exe%22%20or%20process.name:%20%22sc.exe%22))')&timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))"
);
});

it('redirects from a undefined/null host name with a null for the KQL', () => {
loginAndWaitForPage(mlHostVariableHostNullKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostVariableHostNullKqlQuery);
cy.url().should(
'include',
'/app/siem#/hosts/anomalies?timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))'
);
});

it('redirects from a undefined/null host name but with a value for query', () => {
loginAndWaitForPage(mlHostVariableHostKqlQuery);
loginAndWaitForPageWithoutDateRange(mlHostVariableHostKqlQuery);
cy.url().should(
'include',
"/app/siem#/hosts/anomalies?query=(language:kuery,query:'(process.name:%20%22conhost.exe%22%20or%20process.name:%20%22sc.exe%22)')&timerange=(global:(linkTo:!(timeline),timerange:(from:1559800800000,kind:absolute,to:1559887199999)),timeline:(linkTo:!(global),timerange:(from:1559800800000,kind:absolute,to:1559887199999)))"
Expand Down
Loading

0 comments on commit 02f89f0

Please sign in to comment.