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

[Backport 2.12] [Backport 2.x] Updated cypress version to match core OSD (#907) #953

Open
wants to merge 2 commits into
base: 2.12
Choose a base branch
from
Open
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
30 changes: 13 additions & 17 deletions cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dns_type_rule_data from '../fixtures/integration_tests/rule/create_dns_ru
import _ from 'lodash';
import { getMappingFields } from '../../public/pages/Detectors/utils/helpers';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';
import { setupIntercept } from '../support/helpers';

const cypressIndexDns = 'cypress-index-dns';
const cypressIndexWindows = 'cypress-index-windows';
Expand Down Expand Up @@ -157,8 +158,8 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
.focus()
.blur();

cy.intercept('POST', '/_plugins/_security_analytics/mappings').as('createMappingsRequest');
cy.intercept('POST', '/_plugins/_security_analytics/detectors').as('createDetectorRequest');
setupIntercept(cy, '/_plugins/_security_analytics/mappings', 'createMappingsRequest');
setupIntercept(cy, '/_plugins/_security_analytics/detectors', 'createDetectorRequest');

// create the detector
cy.getElementByText('button', 'Create').click({ force: true });
Expand Down Expand Up @@ -224,7 +225,7 @@ describe('Detectors', () => {

describe('...should validate form fields', () => {
beforeEach(() => {
cy.intercept('/_plugins/_security_analytics/detectors/_search').as('detectorsSearch');
setupIntercept(cy, '/_plugins/_security_analytics/detectors/_search', 'detectorsSearch');

// Visit Detectors page before any test
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/detectors`);
Expand Down Expand Up @@ -358,7 +359,7 @@ describe('Detectors', () => {

describe('...validate create detector flow', () => {
beforeEach(() => {
cy.intercept('/_plugins/_security_analytics/detectors/_search').as('detectorsSearch');
setupIntercept(cy, '/_plugins/_security_analytics/detectors/_search', 'detectorsSearch');

// Visit Detectors page before any test
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/detectors`);
Expand All @@ -376,7 +377,7 @@ describe('Detectors', () => {
});

it('...basic details can be edited', () => {
cy.intercept('GET', '/_plugins/_security_analytics/indices').as('getIndices');
setupIntercept(cy, '/_plugins/_security_analytics/indices', 'getIndices', 'GET');
openDetectorDetails(detectorName);

editDetectorDetails(detectorName, 'Detector details');
Expand Down Expand Up @@ -428,8 +429,8 @@ describe('Detectors', () => {
});

it('...should update field mappings if data source is changed', () => {
cy.intercept('mappings/view').as('getMappingsView');
cy.intercept('GET', '/indices').as('getIndices');
setupIntercept(cy, 'mappings/view', 'getMappingsView', 'GET');
setupIntercept(cy, '/indices', 'getIndices', 'GET');
openDetectorDetails(detectorName);

editDetectorDetails(detectorName, 'Detector details');
Expand All @@ -451,7 +452,7 @@ describe('Detectors', () => {
});

it('...should show field mappings if rule selection is changed', () => {
cy.intercept('mappings/view').as('getMappingsView');
setupIntercept(cy, 'mappings/view', 'getMappingsView', 'GET');

openDetectorDetails(detectorName);

Expand All @@ -474,22 +475,17 @@ describe('Detectors', () => {
});

it('...can be deleted', () => {
cy.intercept('/_plugins/_security_analytics/rules/_search?prePackaged=true').as(
'getSigmaRules'
);
cy.intercept('/_plugins/_security_analytics/rules/_search?prePackaged=false').as(
'getCustomRules'
);
setupIntercept(cy, '/rules/_search', 'getRules');

openDetectorDetails(detectorName);

cy.wait('@detectorsSearch');
cy.wait('@getCustomRules');
cy.wait('@getSigmaRules');
cy.wait('@getRules');

cy.getButtonByText('Actions')
.click({ force: true })
.then(() => {
cy.intercept('/detectors').as('detectors');
setupIntercept(cy, '/detectors', 'detectors');
cy.getElementByText('.euiContextMenuItem', 'Delete').click({ force: true });
cy.wait('@detectors').then(() => {
cy.contains('There are no existing detectors');
Expand Down
33 changes: 8 additions & 25 deletions cypress/integration/2_rules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { OPENSEARCH_DASHBOARDS_URL } from '../support/constants';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';
import { setupIntercept } from '../support/helpers';

const uniqueId = Cypress._.random(0, 1e6);
const SAMPLE_RULE = {
Expand Down Expand Up @@ -191,7 +192,7 @@ describe('Rules', () => {

describe('...should validate form fields', () => {
beforeEach(() => {
cy.intercept('/rules/_search').as('rulesSearch');
setupIntercept(cy, '/rules/_search', 'rulesSearch');
// Visit Rules page
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/rules`);
cy.wait('@rulesSearch').should('have.property', 'state', 'Complete');
Expand Down Expand Up @@ -482,7 +483,7 @@ describe('Rules', () => {

describe('...should validate create rule flow', () => {
beforeEach(() => {
cy.intercept('/rules/_search').as('rulesSearch');
setupIntercept(cy, '/rules/_search', 'rulesSearch');
// Visit Rules page
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/rules`);
cy.wait('@rulesSearch').should('have.property', 'state', 'Complete');
Expand All @@ -507,10 +508,7 @@ describe('Rules', () => {
cy.get('[data-test-subj="rule_yaml_editor"]').contains(line)
);

cy.intercept({
url: '/rules',
}).as('getRules');

setupIntercept(cy, '/rules/_search', 'getRules');
submitRule();

cy.wait('@getRules');
Expand Down Expand Up @@ -560,10 +558,7 @@ describe('Rules', () => {
getDescriptionField().type(SAMPLE_RULE.description);
getDescriptionField().should('have.value', SAMPLE_RULE.description);

cy.intercept({
url: '/rules',
}).as('getRules');

setupIntercept(cy, '/rules/_search', 'getRules');
submitRule();

cy.waitForPageLoad('rules', {
Expand All @@ -576,19 +571,8 @@ describe('Rules', () => {
});

it('...can be deleted', () => {
cy.intercept({
url: '/rules',
}).as('deleteRule');

cy.intercept('POST', 'rules/_search?prePackaged=true', {
delay: 5000,
}).as('getPrePackagedRules');

cy.intercept('POST', 'rules/_search?prePackaged=false', {
delay: 5000,
}).as('getCustomRules');
setupIntercept(cy, `/rules/_search`, 'getRules');

cy.wait('@rulesSearch');
cy.get(`input[placeholder="Search rules"]`).ospSearch(SAMPLE_RULE.name);

// Click the rule link to open the details flyout
Expand All @@ -606,9 +590,8 @@ describe('Rules', () => {
.click()
.then(() => cy.get('.euiModalFooter > .euiButton').contains('Delete').click());

cy.wait('@deleteRule');
cy.wait('@getCustomRules');
cy.wait('@getPrePackagedRules');
cy.wait(5000);
cy.wait('@getRules');

// Search for sample_detector, presumably deleted
cy.wait(3000);
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/3_alerts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import indexSettings from '../fixtures/sample_windows_index_settings.json';
import aliasMappings from '../fixtures/sample_alias_mappings.json';
import indexDoc from '../fixtures/sample_document.json';
import ruleSettings from '../fixtures/integration_tests/rule/create_windows_usb_rule.json';
import { createDetector } from '../support/helpers';
import { createDetector, setupIntercept } from '../support/helpers';
import { getLogTypeLabel } from '../../public/pages/LogTypes/utils/helpers';

const indexName = 'test-index';
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Alerts', () => {

beforeEach(() => {
// Visit Alerts table page
cy.intercept('/detectors/_search').as('detectorsSearch');
setupIntercept(cy, '/detectors/_search', 'detectorsSearch');
// Visit Detectors page
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/alerts`);
cy.wait('@detectorsSearch').should('have.property', 'state', 'Complete');
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,8 @@ export const createDetector = (
cySubject.detector = detectorConfig;
return cySubject;
};

export function setupIntercept(cy, url, interceptName, method = 'POST') {
const urlRegex = new RegExp(`.*${url}.*`);
cy.intercept(method, urlRegex).as(interceptName);
}
14 changes: 5 additions & 9 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"id": "securityAnalyticsDashboards",
"version": "2.12.0.0",
"opensearchDashboardsVersion": "2.12.0",
"configPath": [
"opensearch_security_analytics"
],
"requiredPlugins": [
"data"
],
"version": "2.13.0.0",
"opensearchDashboardsVersion": "2.13.0",
"configPath": ["opensearch_security_analytics"],
"requiredPlugins": ["data"],
"server": true,
"ui": true
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensearch_security_analytics_dashboards",
"version": "2.12.0.0",
"version": "2.13.0.0",
"description": "OpenSearch Dashboards plugin for Security Analytics",
"main": "index.js",
"license": "Apache-2.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"@testing-library/user-event": "^13.1.9",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.3.2",
"cypress": "^6.0.0",
"cypress": "9.5.4",
"cypress-real-events": "1.7.6",
"cypress-recurse": "^1.27.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
Expand All @@ -86,4 +86,4 @@
"formik": "^2.2.6",
"react-graph-vis": "^1.0.7"
}
}
}
Loading
Loading