Skip to content

Commit 41ca546

Browse files
cwperksHailong-am
andauthored
Fix security Cypress 13 test stability (#2003)
* Fix Cypress 13 compatibility issues in security tests 1. Remove invalid bare cy.intercept() calls: The Cypress 13 upgrade (PR #2000) replaced cy.server() with cy.intercept() (no arguments). In Cypress 13, cy.intercept() requires at least a URL pattern or RouteMatcher - calling it with no arguments throws an error. These bare calls served no purpose and are simply removed. 2. Add .json to webpack resolve extensions: The webpack preprocessor config was missing .json in its resolve.extensions array, causing module-not-found errors for fixture imports that omit the .json extension. Signed-off-by: Craig Perkins <cwperx@amazon.com> * Fix security Cypress 13 test stability Signed-off-by: Craig Perkins <craig5008@gmail.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Craig Perkins <craig5008@gmail.com> Co-authored-by: Hailong Cui <ihailong@amazon.com>
1 parent 9ca2200 commit 41ca546

17 files changed

Lines changed: 88 additions & 90 deletions

cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ const kibanaRoleName = 'kibana_user';
2626

2727
if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) {
2828
describe('Saved objects table test', () => {
29-
// start a server so that server responses can be mocked via fixtures
30-
// in all of the below test cases
3129
before(() => {
32-
cy.intercept();
3330
cy.createTenant(tenantName, tenantDescription);
3431

3532
cy.createIndexPattern('index-pattern1', {

cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ if (Cypress.env('SECURITY_ENABLED')) {
1111
const tenantName = 'private';
1212

1313
before(() => {
14-
cy.intercept();
1514
localStorage.setItem('home:welcome:show', false);
1615
localStorage.setItem('home:newThemeModal:show', false);
16+
localStorage.setItem('home:enhancedDiscover:dismissed', 'true');
1717
});
1818
it('Checks that the tenant switcher can switch tenants despite a different tenant being present in the tenant query parameter.', function () {
1919
CURRENT_TENANT.newTenant = tenantName;
@@ -22,7 +22,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
2222
cy.waitForLoader();
2323
switchTenantTo('global');
2424
cy.waitForLoader();
25-
cy.getElementByTestId('account-popover').click();
25+
cy.getElementByTestId('account-popover').click({ force: true });
2626
cy.get('#tenantName').should('contain.text', 'Global');
2727
});
2828
});

cypress/integration/plugins/security-dashboards-plugin/default_tenant.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const tenantName = 'test';
1313
if (Cypress.env('SECURITY_ENABLED')) {
1414
describe('Multi Tenancy Default Tenant Tests: ', () => {
1515
before(() => {
16-
cy.intercept();
1716
cy.createTenant(tenantName, tenantDescription);
1817
cy.changeDefaultTenant({
1918
multitenancy_enabled: true,

cypress/integration/plugins/security-dashboards-plugin/multi_tenancy.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const tenantName = 'test';
1919
if (Cypress.env('SECURITY_ENABLED')) {
2020
describe('Multi Tenancy Tests: ', () => {
2121
before(() => {
22-
cy.intercept();
2322
cy.createTenant(tenantName, tenantDescription);
2423
cy.createIndexPattern(
2524
'index-pattern1',

cypress/integration/plugins/security-dashboards-plugin/readonly.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const TEST_CONFIG = {
3333
if (Cypress.env('SECURITY_ENABLED')) {
3434
describe('Read Only mode', () => {
3535
before(() => {
36-
cy.intercept();
37-
3836
cy.createTenant(TEST_CONFIG.tenant.name, {
3937
description: TEST_CONFIG.tenant.description,
4038
});
@@ -63,6 +61,10 @@ if (Cypress.env('SECURITY_ENABLED')) {
6361
);
6462
window.localStorage.setItem('home:newThemeModal:show', false);
6563
window.localStorage.setItem('home:welcome:show', false);
64+
window.localStorage.setItem(
65+
'home:enhancedDiscover:dismissed',
66+
'true'
67+
);
6668
},
6769
});
6870
cy.waitForLoader();

cypress/integration/plugins/security-dashboards-plugin/switch_tenant.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
export function switchTenantTo(newTenant) {
7-
cy.getElementByTestId('account-popover').click();
7+
cy.getElementByTestId('account-popover').click({ force: true });
88
cy.intercept({
99
method: 'GET',
1010
url: '/api/v1/auth/dashboardsinfo*',
@@ -15,24 +15,26 @@ export function switchTenantTo(newTenant) {
1515
url: '/api/v1/configuration/account*',
1616
}).as('waitForAccountInfo');
1717

18-
cy.getElementByTestId('switch-tenants').click();
18+
cy.getElementByTestId('switch-tenants').click({ force: true });
1919

2020
if (['global', 'private'].includes(newTenant)) {
2121
cy.get('[id="' + newTenant + '"][name="tenantSwitchRadios"]').should(
2222
'be.enabled'
2323
);
24-
cy.get('.euiRadio__label[for="' + newTenant + '"]').click();
24+
cy.get('.euiRadio__label[for="' + newTenant + '"]').click({
25+
force: true,
26+
});
2527
} else {
2628
cy.get('[id="custom"][name="tenantSwitchRadios"]').should('be.enabled');
2729

2830
cy.getElementByTestId('tenant-switch-modal')
2931
.find('[data-test-subj="comboBoxInput"]')
30-
.click();
32+
.click({ force: true });
3133

3234
// typo in data-test-subj
3335
cy.getElementByTestId('comboBoxOptionsList ')
3436
.find(`[title="${newTenant}"]`)
35-
.click();
37+
.click({ force: true });
3638
}
3739

3840
cy.intercept({
@@ -41,7 +43,7 @@ export function switchTenantTo(newTenant) {
4143
}).as('waitForUpdatingTenants');
4244
cy.getElementByTestId('tenant-switch-modal')
4345
.find('[data-test-subj="confirm"]')
44-
.click();
46+
.click({ force: true });
4547

4648
cy.wait('@waitForUpdatingTenants');
4749

cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { switchTenantTo } from './switch_tenant';
88

99
if (Cypress.env('SECURITY_ENABLED')) {
1010
describe('Multi Tenancy Tests: ', () => {
11-
before(() => {
12-
cy.intercept();
13-
});
14-
1511
it('Tests that when the short URL is copied and pasted, it will route correctly with the right tenant', function () {
1612
const randomNumber = Cypress._.random(0, 1e6);
1713
const dashboardName = 'Cypress dashboard - ' + randomNumber;

cypress/integration/plugins/security/audit_log_spec.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ import {
1010

1111
if (Cypress.env('SECURITY_ENABLED')) {
1212
describe('Audit logs page', () => {
13-
// start a server so that server responses can be mocked via fixtures
14-
// in all of the below test cases
15-
before(() => {
16-
cy.intercept();
17-
});
18-
1913
it('should load Audit logs page properly', () => {
2014
cy.mockAuditLogsAction(
2115
SEC_AUDIT_FIXTURES_PATH + '/audit_info_response.json',
2216
() => {
2317
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
24-
}
18+
},
19+
{ reloadAfterAction: true }
2520
);
2621

2722
cy.contains('h1', 'Audit logging');
@@ -30,7 +25,13 @@ if (Cypress.env('SECURITY_ENABLED')) {
3025
});
3126

3227
it('should toggle enable-disable switch for audit logging', () => {
33-
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
28+
cy.mockAuditLogsAction(
29+
SEC_AUDIT_FIXTURES_PATH + '/audit_info_response.json',
30+
() => {
31+
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
32+
},
33+
{ reloadAfterAction: true }
34+
);
3435

3536
// enabled by default
3637
cy.contains('.euiSwitch', 'Enabled');
@@ -61,7 +62,13 @@ if (Cypress.env('SECURITY_ENABLED')) {
6162
});
6263

6364
it('should configure general settings successfully', () => {
64-
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
65+
cy.mockAuditLogsAction(
66+
SEC_AUDIT_FIXTURES_PATH + '/audit_info_response.json',
67+
() => {
68+
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
69+
},
70+
{ reloadAfterAction: true }
71+
);
6572

6673
cy.get('button[data-test-subj="general-settings-configure"]')
6774
.first()
@@ -96,7 +103,13 @@ if (Cypress.env('SECURITY_ENABLED')) {
96103
});
97104

98105
it('should configure compliance settings successfully', () => {
99-
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
106+
cy.mockAuditLogsAction(
107+
SEC_AUDIT_FIXTURES_PATH + '/audit_info_response.json',
108+
() => {
109+
cy.visit(SEC_UI_AUDIT_LOGGING_PATH);
110+
},
111+
{ reloadAfterAction: true }
112+
);
100113

101114
cy.get('button[data-test-subj="compliance-settings-configure"]')
102115
.first()

cypress/integration/plugins/security/auth_spec.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import {
1010

1111
if (Cypress.env('SECURITY_ENABLED')) {
1212
describe('Authc and Authz page', () => {
13-
// start a server so that server responses can be mocked via fixtures
14-
// in all of the below test cases
15-
before(() => {
16-
cy.intercept();
17-
});
18-
1913
it('authentication and authorization section should exist', () => {
20-
cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => {
21-
cy.visit(SEC_UI_AUTH_PATH);
22-
});
14+
cy.mockAuthAction(
15+
SEC_FIXTURES_BASE_PATH + '/auth_response.json',
16+
() => {
17+
cy.visit(SEC_UI_AUTH_PATH);
18+
},
19+
{ reloadAfterAction: true }
20+
);
2321

2422
cy.contains('h3', 'Authentication sequences');
2523
cy.contains('span', 'kerberos_auth_domain');
@@ -29,9 +27,13 @@ if (Cypress.env('SECURITY_ENABLED')) {
2927
});
3028

3129
it('View Expression Modal should display and close correctly', () => {
32-
cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => {
33-
cy.visit(SEC_UI_AUTH_PATH);
34-
});
30+
cy.mockAuthAction(
31+
SEC_FIXTURES_BASE_PATH + '/auth_response.json',
32+
() => {
33+
cy.visit(SEC_UI_AUTH_PATH);
34+
},
35+
{ reloadAfterAction: true }
36+
);
3537

3638
cy.get('.euiModal').should('not.exist');
3739

cypress/integration/plugins/security/get_started_spec.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import {
1010

1111
if (Cypress.env('SECURITY_ENABLED')) {
1212
describe('Home(Get Started) page', () => {
13-
// start a server so that server responses can be mocked via fixtures
14-
// in all of the below test cases
15-
before(() => {
16-
cy.intercept();
17-
});
18-
1913
it('should load Home page properly', () => {
2014
cy.visit(BASE_SEC_UI_PATH);
2115

0 commit comments

Comments
 (0)