Skip to content

Commit

Permalink
Updated cypress version to match core OSD (#907)
Browse files Browse the repository at this point in the history
* updated cypress version

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* updated cypress workflow to use files from the branch

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* updated tests for newer cypress version

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* updated test

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

---------

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Mar 12, 2024
1 parent 8fb301d commit d3aefba
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 478 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ env:
OPENSEARCH_VERSION: '3.0.0-SNAPSHOT'
SECURITY_ANALYTICS_BRANCH: 'main'
GRADLE_VERSION: '7.6.1'

# If this variable is not empty, the package.json, opensearch_dashboards.json, and yarn.lock files will be replaced
# with those files from the 'opensearch-project/security-analytics-dashboards-plugin' branch or commit specified.
OVERRIDE_REFERENCE: 'main'
jobs:
tests:
name: Run Cypress E2E tests
Expand Down Expand Up @@ -74,19 +70,6 @@ jobs:
with:
path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin

# This job replaces the package.json, opensearch_dashboards.json, and yarn.lock files from the
# 'opensearch-project/security-analytics-dashboards-plugin' branch or commit specified in env variable.
# This is most useful on the 'main' branch as it will enable us to specify which version to use for the build when
# one of this package's dependencies is not building reliably without having to adjust the actual version of this package.
- name: Override Package Version
if: ${{ env.OVERRIDE_REFERENCE != '' }}
run: |
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
git fetch --all
git checkout origin/${{ env.OVERRIDE_REFERENCE }} opensearch_dashboards.json
git checkout origin/${{ env.OVERRIDE_REFERENCE }} package.json
git checkout origin/${{ env.OVERRIDE_REFERENCE }} yarn.lock
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand Down
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);
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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

0 comments on commit d3aefba

Please sign in to comment.