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

[Osquery] Add Osquery cypress tests to buildkite #115902

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
11 changes: 11 additions & 0 deletions .buildkite/pipelines/pull_request/osquery_cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- command: .buildkite/scripts/steps/functional/osquery_cypress.sh
label: 'Osquery Cypress Tests'
agents:
queue: ci-group-6
depends_on: build
timeout_in_minutes: 120
retry:
automatic:
- exit_status: '*'
limit: 1
10 changes: 10 additions & 0 deletions .buildkite/scripts/pipelines/pull_request/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ const uploadPipeline = (pipelineContent) => {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/fleet_cypress.yml'));
}

if (
(await doAnyChangesMatch([
/^x-pack\/plugins\/osquery/,
/^x-pack\/test\/osquery_cypress/,
])) ||
process.env.GITHUB_PR_LABELS.includes('ci:all-cypress-suites')
) {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/osquery_cypress.yml'));
}

if (await doAnyChangesMatch([/^x-pack\/plugins\/uptime/])) {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/uptime.yml'));
}
Expand Down
20 changes: 20 additions & 0 deletions .buildkite/scripts/steps/functional/osquery_cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -euo pipefail

source .buildkite/scripts/common/util.sh

.buildkite/scripts/bootstrap.sh
.buildkite/scripts/download_build_artifacts.sh

export JOB=kibana-osquery-cypress

echo "--- Osquery Cypress tests"

cd "$XPACK_DIR"

checks-reporter-with-killswitch "Osquery Cypress Tests" \
node scripts/functional_tests \
--debug --bail \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--config test/osquery_cypress/cli_config.ts
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"**/hoist-non-react-statics": "^3.3.2",
"**/html-minifier/uglify-js": "^3.14.3",
"**/isomorphic-fetch/node-fetch": "^2.6.1",
"**/istanbul-instrumenter-loader/schema-utils": "1.0.0",
"**/istanbul-lib-coverage": "^3.2.0",
"**/json-schema": "^0.4.0",
"**/minimist": "^1.2.5",
"**/node-jose/node-forge": "^0.10.0",
Expand Down Expand Up @@ -436,6 +436,7 @@
"@babel/types": "^7.16.0",
"@bazel/ibazel": "^0.15.10",
"@bazel/typescript": "^3.8.0",
"@cypress/code-coverage": "^3.9.11",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.6.0",
"@elastic/eslint-config-kibana": "link:bazel-bin/packages/elastic-eslint-config-kibana",
Expand Down Expand Up @@ -694,7 +695,9 @@
"cypress-file-upload": "^5.0.8",
"cypress-multi-reporters": "^1.5.0",
"cypress-pipe": "^2.0.0",
"cypress-react-selector": "^2.3.13",
"cypress-real-events": "^1.5.1",
"cypress-recurse": "^1.13.1",
"debug": "^2.6.9",
"delete-empty": "^2.0.0",
"dependency-check": "^4.1.0",
Expand Down Expand Up @@ -749,7 +752,6 @@
"http-proxy": "^1.18.1",
"is-glob": "^4.0.1",
"is-path-inside": "^3.0.2",
"istanbul-instrumenter-loader": "^3.0.1",
"jest": "^26.6.3",
"jest-canvas-mock": "^2.3.1",
"jest-circus": "^26.6.3",
Expand Down Expand Up @@ -786,7 +788,7 @@
"ncp": "^2.0.0",
"node-sass": "^6.0.1",
"null-loader": "^3.0.0",
"nyc": "^15.0.1",
"nyc": "^15.1.0",
"oboe": "^2.1.4",
"parse-link-header": "^1.0.1",
"pbf": "3.2.1",
Expand Down
15 changes: 15 additions & 0 deletions test/scripts/jenkins_osquery_cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

source test/scripts/jenkins_test_setup_xpack.sh

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

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

echo ""
echo ""
8 changes: 8 additions & 0 deletions vars/tasks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ def functionalXpack(Map params = [:]) {
}
}

whenChanged([
'x-pack/plugins/osquery/',
]) {
if (githubPr.isPr()) {
task(kibanaPipeline.functionalTestProcess('xpack-osqueryCypress', './test/scripts/jenkins_osquery_cypress.sh'))
}
}

}
}

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/osquery/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"excludeAfterRemap": true,
"include": ["public"]
}
14 changes: 8 additions & 6 deletions x-pack/plugins/osquery/cypress/cypress.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"baseUrl": "http://localhost:5620",
"defaultCommandTimeout": 60000,
"execTimeout": 120000,
"pageLoadTimeout": 120000,
"nodeVersion": "system",
"defaultCommandTimeout": 6000,
"execTimeout": 12000,
"pageLoadTimeout": 12000,
"retries": {
"runMode": 2
},
"screenshotsFolder": "../../../target/kibana-osquery/cypress/screenshots",
"trashAssetsBeforeRuns": false,
"video": false,
"videosFolder": "../../../target/kibana-osquery/cypress/videos",
"viewportHeight": 900,
"viewportWidth": 1440
}
"viewportWidth": 1440,
"experimentalStudio": true
}
60 changes: 60 additions & 0 deletions x-pack/plugins/osquery/cypress/integration/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 { FLEET_AGENT_POLICIES, navigateTo } from '../tasks/navigation';
import { addIntegration } from '../tasks/integrations';
import { checkResults, inputQuery, selectAllAgents, submitQuery } from '../tasks/live_query';
import { login } from '../tasks/login';

describe('Add Integration', () => {
const integration = 'Osquery Manager';

before(() => {
login();
});

it.skip('should open Osquery app', () => {
cy.visit('/app/osquery/live_queries');
cy.wait(3000);
cy.contains('Live queries history', { timeout: 60000 });
cy.contains('New live query').click();
cy.wait(3000);
cy.contains('Saved queries').click();
cy.wait(3000);
cy.contains('Saved queries', { timeout: 60000 });
cy.contains('Add saved query').click();
cy.wait(3000);
cy.contains('Packs').click();
cy.wait(3000);
cy.contains('Packs', { timeout: 60000 });
cy.contains('Add pack').click();
cy.wait(3000);
});

it('should display Osquery integration in the Policies list once installed ', () => {
addAndVerifyIntegration();
});

it.skip('should run live query', () => {
navigateTo('/app/osquery/live_queries/new');
cy.wait(1000);
selectAllAgents();
inputQuery();
submitQuery();
checkResults();
});

function addAndVerifyIntegration() {
navigateTo(FLEET_AGENT_POLICIES);
cy.contains('Default Fleet Server policy').click();
cy.contains('Add integration').click();

cy.contains(integration).click();
addIntegration();
cy.contains('osquery_manager-');
}
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/// <reference types="cypress" />
// / <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
Expand All @@ -22,8 +21,11 @@
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module.exports = (_on, _config) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
module.exports = (on: any, config: any) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies
require('@cypress/code-coverage/task')(on, config);
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
return config;
};
11 changes: 11 additions & 0 deletions x-pack/plugins/osquery/cypress/screens/fleet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.
*/

export const ADD_AGENT_BUTTON = 'addAgentButton';

export const AGENT_POLICIES_TAB = 'fleet-agent-policies-tab';
export const ENROLLMENT_TOKENS_TAB = 'fleet-enrollment-tokens-tab';
19 changes: 17 additions & 2 deletions x-pack/plugins/osquery/cypress/screens/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@
* 2.0.
*/

export const ADD_POLICY_BTN = '[data-test-subj="addIntegrationPolicyButton"]';
export const CREATE_PACKAGE_POLICY_SAVE_BTN = '[data-test-subj="createPackagePolicySaveButton"]';
export const ADD_POLICY_BTN = 'addIntegrationPolicyButton';
export const CREATE_PACKAGE_POLICY_SAVE_BTN = 'createPackagePolicySaveButton';

export const DATA_COLLECTION_SETUP_STEP = 'dataCollectionSetupStep';
export const INTEGRATIONS_CARD = '.euiCard__titleAnchor';

export const INTEGRATION_NAME_LINK = 'integrationNameLink';

export const CONFIRM_MODAL_BTN = 'confirmModalConfirmButton';
export const CONFIRM_MODAL_BTN_SEL = `[data-test-subj=${CONFIRM_MODAL_BTN}]`;

export const SETTINGS_TAB = 'tab-settings';
export const POLICIES_TAB = 'tab-policies';

export const UPDATE_PACKAGE_BTN = 'updatePackageBtn';
export const LATEST_VERSION = 'latestVersion';

export const PACKAGE_VERSION = 'packageVersionText';
export const SAVE_PACKAGE_CONFIRM = '[data-test-subj=confirmModalConfirmButton]';
Loading