-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Tests: Filter by rule execution status (#160502)
**Resolves: #138903 ## Summary Adds an E2E Cypress test to check filtering by execution status in the rules table. <img width="953" alt="Screenshot 2023-06-26 at 14 10 10" src="https://github.com/elastic/kibana/assets/15949146/e1eb67ed-779c-42ad-8194-04a26598cfbc"> (cherry picked from commit c30a7d4)
- Loading branch information
1 parent
7507d73
commit 0b14664
Showing
6 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
x-pack/plugins/security_solution/cypress/e2e/detection_rules/rule_fiters.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { cleanKibana, resetRulesTableState, deleteAlertsAndRules } from '../../tasks/common'; | ||
import { login, visitWithoutDateRange } from '../../tasks/login'; | ||
import { esArchiverResetKibana } from '../../tasks/es_archiver'; | ||
import { | ||
expectRulesWithExecutionStatus, | ||
filterByExecutionStatus, | ||
expectNumberOfRulesShownOnPage, | ||
} from '../../tasks/rule_filters'; | ||
|
||
import { SECURITY_DETECTIONS_RULES_URL } from '../../urls/navigation'; | ||
|
||
import { waitForRulesTableToBeLoaded } from '../../tasks/alerts_detection_rules'; | ||
|
||
import { createRule, waitForRulesToFinishExecution } from '../../tasks/api_calls/rules'; | ||
import { deleteIndex, createIndex, createDocument } from '../../tasks/api_calls/elasticsearch'; | ||
|
||
import { getNewRule } from '../../objects/rule'; | ||
|
||
describe('Rule management filters', () => { | ||
before(() => { | ||
cleanKibana(); | ||
}); | ||
|
||
beforeEach(() => { | ||
login(); | ||
// Make sure persisted rules table state is cleared | ||
resetRulesTableState(); | ||
deleteAlertsAndRules(); | ||
esArchiverResetKibana(); | ||
}); | ||
|
||
describe('Last response filter', () => { | ||
it('Filters rules by last response', function () { | ||
deleteIndex('test_index'); | ||
|
||
createIndex('test_index', { | ||
'@timestamp': { | ||
type: 'date', | ||
}, | ||
}); | ||
|
||
createDocument('test_index', {}); | ||
|
||
createRule( | ||
getNewRule({ | ||
name: 'Successful rule', | ||
rule_id: 'successful_rule', | ||
index: ['test_index'], | ||
}) | ||
); | ||
|
||
createRule( | ||
getNewRule({ | ||
name: 'Warning rule', | ||
rule_id: 'warning_rule', | ||
index: ['non_existent_index'], | ||
}) | ||
); | ||
|
||
createRule( | ||
getNewRule({ | ||
name: 'Failed rule', | ||
rule_id: 'failed_rule', | ||
index: ['test_index'], | ||
// Setting a crazy large "Additional look-back time" to force a failure | ||
from: 'now-9007199254746990s', | ||
}) | ||
); | ||
|
||
waitForRulesToFinishExecution(['successful_rule', 'warning_rule', 'failed_rule'], new Date()); | ||
|
||
visitWithoutDateRange(SECURITY_DETECTIONS_RULES_URL); | ||
|
||
waitForRulesTableToBeLoaded(); | ||
|
||
// Initial table state - before filtering by status | ||
expectNumberOfRulesShownOnPage(3); | ||
expectRulesWithExecutionStatus(1, 'Succeeded'); | ||
expectRulesWithExecutionStatus(1, 'Warning'); | ||
expectRulesWithExecutionStatus(1, 'Failed'); | ||
|
||
// Table state after filtering by Succeeded status | ||
filterByExecutionStatus('Succeeded'); | ||
expectNumberOfRulesShownOnPage(1); | ||
expectRulesWithExecutionStatus(1, 'Succeeded'); | ||
|
||
// Table state after filtering by Warning status | ||
filterByExecutionStatus('Warning'); | ||
expectNumberOfRulesShownOnPage(1); | ||
expectRulesWithExecutionStatus(1, 'Warning'); | ||
|
||
// Table state after filtering by Failed status | ||
filterByExecutionStatus('Failed'); | ||
expectNumberOfRulesShownOnPage(1); | ||
expectRulesWithExecutionStatus(1, 'Failed'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/security_solution/cypress/tasks/rule_filters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
RULE_EXECUTION_STATUS_BADGE, | ||
EXECUTION_STATUS_FILTER_BUTTON, | ||
EXECUTION_STATUS_FILTER_OPTION, | ||
} from '../screens/alerts_detection_rules'; | ||
|
||
export const expectRulesWithExecutionStatus = (expectedCount: number, status: string) => { | ||
cy.get(`${RULE_EXECUTION_STATUS_BADGE}:contains("${status}")`).should( | ||
'have.length', | ||
expectedCount | ||
); | ||
}; | ||
|
||
export const expectNumberOfRulesShownOnPage = (expectedCount: number) => | ||
cy.get(RULE_EXECUTION_STATUS_BADGE).should('have.length', expectedCount); | ||
|
||
export const filterByExecutionStatus = (status: string) => { | ||
cy.get(EXECUTION_STATUS_FILTER_BUTTON).click(); | ||
cy.get(`${EXECUTION_STATUS_FILTER_OPTION}:contains("${status}")`).click(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters