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

Cypress Integ test for dynamic multi-tenancy features #609

Merged
merged 1 commit into from
Apr 13, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"securitytenant": ["global"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"securitytenant": ["private"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { SAVED_OBJECTS_PATH } from '../../../utils/dashboards/constants';

import { CURRENT_TENANT } from '../../../utils/commands';
import tenantDescription from '../../../fixtures/plugins/security-dashboards-plugin/tenants/testTenant';

const tenantName = 'test';

if (Cypress.env('SECURITY_ENABLED')) {
describe('Multi Tenancy Default Tenant Tests: ', () => {
before(() => {
cy.server();
cy.createTenant(tenantName, tenantDescription);
cy.changeDefaultTenant({
multitenancy_enabled: true,
private_tenant_enabled: true,
default_tenant: tenantName,
});
});
it('Test Changed Default Tenant ', () => {
CURRENT_TENANT.newTenant = null;
cy.visit(SAVED_OBJECTS_PATH);
cy.waitForLoader();
cy.get('#user-icon-btn').click();
cy.wait(1000);
cy.get('#tenantName').contains(tenantName);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
SAVED_OBJECTS_PATH,
TENANTS_MANAGE_PATH,
} from '../../../utils/dashboards/constants';

import { CURRENT_TENANT } from '../../../utils/commands';

import indexPatternPrivateTenantHeaderSetUp from '../../../fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternPrivateTenantHeader';
import indexPatternGlobalTenantHeaderSetUp from '../../../fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternGlobalTenantHeader';
import tenantDescription from '../../../fixtures/plugins/security-dashboards-plugin/tenants/testTenant.json';

const tenantName = 'test';

if (Cypress.env('SECURITY_ENABLED')) {
describe('Multi Tenancy Tests: ', () => {
before(() => {
cy.server();
cy.createTenant(tenantName, tenantDescription);
cy.createIndexPattern(
'index-pattern1',
{
title: 's*',
timeFieldName: 'timestamp',
},
indexPatternGlobalTenantHeaderSetUp
);

cy.createIndexPattern(
'index-pattern2',
{
title: 'se*',
timeFieldName: 'timestamp',
},
indexPatternPrivateTenantHeaderSetUp
);
});
it('Test 1 Disable Multi Tenancy ', () => {
CURRENT_TENANT.newTenant = 'private';

// Load into Private Tenant initially and check if index Pattern matches to the one saved in Private tenant.
cy.visit(SAVED_OBJECTS_PATH);
cy.waitForLoader();
cy.contains('a', 'Saved objects');
cy.contains('a', 'se*');

// Switch tenants button should exist when multi-tenancy is enabled.
cy.get('#user-icon-btn').click();
cy.contains('button', 'Switch tenants').should('exist');

// Disable multi-tenancy.
cy.visit(TENANTS_MANAGE_PATH);
cy.waitForLoader();

cy.contains('button', 'Configure').click();
cy.waitForLoader();
cy.get('#EnableMultitenancyCheckBox').uncheck({ force: true });
cy.contains('button', 'Save Changes').click();

cy.get('#tenancyChangeCheckbox').check({ force: true });
cy.contains('button', 'Apply changes').click();

cy.reload();
cy.waitForLoader();

// Switch tenants button should not exist when multi-tenancy is disabled.
cy.get('#user-icon-btn').click();
cy.contains('button', 'Switch tenants').should('not.exist');

//Tenancy disbaled warning should show on manage page.
cy.contains('Tenancy is disabled').should('exist');

// Saved index pattern should only have the ones saved in Global tenant.
cy.visit(SAVED_OBJECTS_PATH);
cy.waitForLoader();
cy.contains('a', 'Saved objects');
cy.contains('a', 's*');

// Enable Multi-tenancy before closing test.
cy.visit(TENANTS_MANAGE_PATH);
cy.waitForLoader();
cy.contains('button', 'Configure').click();
cy.waitForLoader();
cy.get('#EnableMultitenancyCheckBox').check({ force: true });
cy.contains('button', 'Save Changes').click();
cy.get('#tenancyChangeCheckbox').check({ force: true });
cy.contains('button', 'Apply changes').click();
cy.reload();
cy.waitForLoader();
});
it('Test 2 Disable Private Tenancy ', () => {
CURRENT_TENANT.newTenant = 'private';

// Load into Private Tenant initially and check if index Pattern matches to the one saved in Private tenant.
cy.visit(SAVED_OBJECTS_PATH);
cy.waitForLoader();
cy.contains('a', 'Saved objects');
cy.contains('a', 'se*');

// Check if switching to private tenant is enabled.
cy.get('#user-icon-btn').click();
cy.contains('button', 'Switch tenants').click();
cy.get('#private').should('be.enabled');
cy.contains('button', 'Cancel').click();

// Disable private tenant.
cy.visit(TENANTS_MANAGE_PATH);
cy.waitForLoader();

cy.contains('button', 'Configure').click();
cy.waitForLoader();
cy.get('#EnablePrivateTenantCheckBox').uncheck({ force: true });
cy.contains('button', 'Save Changes').click();

cy.get('#privateTenancyChangeCheckbox').check({ force: true });
cy.contains('button', 'Apply changes').click();

cy.reload();
cy.waitForLoader();

// Check if switching to private tenant is enabled.
cy.get('#user-icon-btn').click();
cy.contains('button', 'Switch tenants').click();
cy.get('#private').should('be.disabled');
cy.contains('button', 'Cancel').click();

// Saved index pattern should only have the ones saved in Global tenant.
cy.visit(SAVED_OBJECTS_PATH);
cy.waitForLoader();
cy.contains('a', 'Saved objects');
cy.contains('a', 's*');

// Enable private tenant before exiting test.
cy.visit(TENANTS_MANAGE_PATH);
cy.waitForLoader();
cy.contains('button', 'Configure').click();
cy.waitForLoader();
cy.get('#EnablePrivateTenantCheckBox').check({ force: true });
cy.contains('button', 'Save Changes').click();
cy.get('#privateTenancyChangeCheckbox').check({ force: true });
cy.contains('button', 'Apply changes').click();
cy.reload();
cy.waitForLoader();
});
});
}
16 changes: 16 additions & 0 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@ Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => {
});
});

Cypress.Commands.add('changeDefaultTenant', (attributes, header = {}) => {
const url =
Cypress.env('openSearchUrl') + '/_plugins/_security/api/tenancy/config';

cy.request({
method: 'PUT',
url,
headers: {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
...header,
},
body: JSON.stringify(attributes),
});
});

Cypress.Commands.add('deleteIndexPattern', (id, options = {}) =>
cy.deleteSavedObject('index-pattern', id, options)
);
Expand Down
2 changes: 2 additions & 0 deletions cypress/utils/dashboards/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { BASE_PATH } from '../base_constants';

// STACK MANAGEMENT PATH
export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management';
export const TENANTS_MANAGE_PATH =
BASE_PATH + '/app/security-dashboards-plugin#/tenants';

export const INDEX_PATTERN_PATH =
STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns';
Expand Down
16 changes: 16 additions & 0 deletions cypress/utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ declare namespace Cypress {
header: string,
): Chainable<S>;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment header here is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks @ashwin-pc for pointing this out.

/**
* Changes the Default tenant for the domain.
* @example
* cy.changeDefaultTenant({multitenancy_enabled: true, private_tenant_enabled: true, default_tenant: tenantName, });
*/
changeDefaultTenant<S = any>(
attributes: {
multitenancy_enabled: boolean,
private_tenant_enabled: boolean,
default_tenant: string;
},
// header: string,
// default_tenant: string
): Chainable<S>;

/**
* Delete an index pattern
* @example
Expand Down