Skip to content

Commit

Permalink
[EDR Workflows] Verify flaky osquery tests (elastic#169749)
Browse files Browse the repository at this point in the history
(cherry picked from commit a15a948)

# Conflicts:
#	.buildkite/scripts/lifecycle/post_command.sh
#	x-pack/plugins/osquery/cypress/e2e/all/alerts_automated_action_results.cy.ts
#	x-pack/plugins/osquery/cypress/e2e/all/alerts_response_actions_form.cy.ts
#	x-pack/plugins/osquery/cypress/e2e/all/packs_integration.cy.ts
#	x-pack/plugins/osquery/cypress/support/e2e.ts
  • Loading branch information
tomsonpl committed Nov 7, 2023
1 parent 19e5f24 commit 5bede9f
Show file tree
Hide file tree
Showing 32 changed files with 363 additions and 259 deletions.
2 changes: 2 additions & 0 deletions .buildkite/scripts/lifecycle/post_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [[ "$IS_TEST_EXECUTION_STEP" == "true" ]]; then
buildkite-agent artifact upload 'target/kibana-coverage/functional/**/*'
buildkite-agent artifact upload 'target/kibana-*'
buildkite-agent artifact upload 'target/kibana-security-solution/**/*.png'
buildkite-agent artifact upload 'target/kibana-osquery/**/*.png'
buildkite-agent artifact upload 'target/kibana-osquery/**/*.mp4'
buildkite-agent artifact upload 'target/kibana-fleet/**/*.png'
buildkite-agent artifact upload 'target/test-metrics/*'
buildkite-agent artifact upload 'target/test-suites-ci-plan.json'
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/osquery/cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import path from 'path';
import { safeLoad as loadYaml } from 'js-yaml';
import { readFileSync } from 'fs';

import { getFailedSpecVideos } from './support/filter_videos';
import type { YamlRoleDefinitions } from '../../../test_serverless/shared/lib';
import { setupUserDataLoader } from '../../../test_serverless/functional/test_suites/security/cypress/support/setup_data_loader_tasks';
const ROLES_YAML_FILE_PATH = path.join(
Expand All @@ -31,8 +32,9 @@ export default defineCypressConfig({

screenshotsFolder: '../../../target/kibana-osquery/cypress/screenshots',
trashAssetsBeforeRuns: false,
video: false,
video: true,
videosFolder: '../../../target/kibana-osquery/cypress/videos',
videoCompression: 15,
viewportHeight: 900,
viewportWidth: 1440,
experimentalStudio: true,
Expand All @@ -54,6 +56,7 @@ export default defineCypressConfig({
numTestsKeptInMemory: 3,
setupNodeEvents(on, config) {
setupUserDataLoader(on, config, { roleDefinitions, additionalRoleName: 'viewer' });
on('after:spec', getFailedSpecVideos);

return config;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,52 @@
* 2.0.
*/

import { initializeDataViews } from '../../tasks/login';
import { cleanupRule, loadRule } from '../../tasks/api_fixtures';
import { checkActionItemsInResults, loadRuleAlerts } from '../../tasks/live_query';

const UUID_REGEX = '[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}';

describe(
'Alert Flyout Automated Action Results',
{
tags: ['@ess', '@serverless'],
},
() => {
let ruleId: string;
describe('Alert Flyout Automated Action Results', () => {
let ruleId: string;

beforeEach(() => {
loadRule(true).then((data) => {
ruleId = data.id;
loadRuleAlerts(data.name);
before(() => {
initializeDataViews();
});

beforeEach(() => {
loadRule(true).then((data) => {
ruleId = data.id;
loadRuleAlerts(data.name);
});
});

afterEach(() => {
cleanupRule(ruleId);
});

it('can visit discover from response action results', { tags: ['@ess'] }, () => {
const discoverRegex = new RegExp(`action_id: ${UUID_REGEX}`);
cy.getBySel('expand-event').first().click();
cy.getBySel('securitySolutionFlyoutResponseSectionHeader').click();
cy.getBySel('securitySolutionFlyoutResponseButton').click();
cy.getBySel('responseActionsViewWrapper').should('exist');
checkActionItemsInResults({
lens: true,
discover: true,
cases: true,
timeline: true,
});
cy.contains('View in Discover')
.should('exist')
.should('have.attr', 'href')
.then(($href) => {
// @ts-expect-error-next-line href string - check types
cy.visit($href);
cy.getBySel('discoverDocTable', { timeout: 60000 }).within(() => {
cy.contains('action_data{ "query":');
});
cy.contains(discoverRegex);
});
});

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/osquery/cypress/e2e/all/alerts_cases.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { initializeDataViews } from '../../tasks/login';
import { OSQUERY_FLYOUT_BODY_EDITOR } from '../../screens/live_query';
import {
cleanupCase,
Expand All @@ -29,6 +30,9 @@ describe('Alert Event Details - Cases', { tags: ['@ess', '@serverless'] }, () =>
let packId: string;
let packName: string;
const packData = packFixture();
before(() => {
initializeDataViews();
});

beforeEach(() => {
loadPack(packData).then((data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { initializeDataViews } from '../../tasks/login';
import { cleanupRule, loadRule } from '../../tasks/api_fixtures';
import { RESPONSE_ACTIONS_ITEM_0, RESPONSE_ACTIONS_ITEM_1 } from '../../tasks/response_actions';
import {
Expand All @@ -25,7 +26,9 @@ describe(
() => {
let ruleId: string;
let ruleName: string;

before(() => {
initializeDataViews();
});
beforeEach(() => {
loadRule().then((data) => {
ruleId = data.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { initializeDataViews } from '../../tasks/login';
import { cleanupRule, loadRule } from '../../tasks/api_fixtures';
import {
inputQuery,
Expand All @@ -24,6 +25,7 @@ describe(
let ruleName: string;

before(() => {
initializeDataViews();
loadRule(true).then((data) => {
ruleId = data.id;
ruleName = data.name;
Expand Down
Loading

0 comments on commit 5bede9f

Please sign in to comment.