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

Add different access level test cases in workspace update flow #1630

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { ADMIN_AUTH } from '../../../../utils/commands';
import { NONE_DASHBOARDS_ADMIN_USER } from '../../../../utils/dashboards/workspace-plugin/constants';

const miscUtils = new MiscUtils(cy);
const workspaceName = 'test_workspace_320sdfouAz';
Expand All @@ -23,26 +25,26 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
library_read: { users: [NONE_DASHBOARDS_ADMIN_USER.username] },
read: { users: [NONE_DASHBOARDS_ADMIN_USER.username] },
},
},
}).then((value) => (workspaceId = value));
});

beforeEach(() => {
// Visit workspace update page
miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`);

cy.intercept('PUT', `/w/${workspaceId}/api/workspaces/${workspaceId}`).as(
'updateWorkspaceRequest'
);
});

after(() => {
cy.deleteWorkspaceById(workspaceId);
});

describe('workspace details', () => {
beforeEach(() => {
// Visit workspace update page
miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`);

cy.intercept(
'PUT',
`/w/${workspaceId}/api/workspaces/${workspaceId}`
).as('updateWorkspaceRequest');
cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click();
});

Expand Down Expand Up @@ -144,5 +146,115 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
});
});
});

if (Cypress.env('SECURITY_ENABLED')) {
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
describe('update with different workspace access level', () => {
let originalUser = ADMIN_AUTH.username;
let originalPassword = ADMIN_AUTH.password;
beforeEach(() => {
originalUser = ADMIN_AUTH.username;
originalPassword = ADMIN_AUTH.password;
});
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to update originalUser and originalPassword in before each? Shall we simply do a const

Suggested change
let originalUser = ADMIN_AUTH.username;
let originalPassword = ADMIN_AUTH.password;
beforeEach(() => {
originalUser = ADMIN_AUTH.username;
originalPassword = ADMIN_AUTH.password;
});
const originalUser = ADMIN_AUTH.username;
const originalPassword = ADMIN_AUTH.password;

afterEach(() => {
ADMIN_AUTH.newUser = originalUser;
ADMIN_AUTH.newPassword = originalPassword;
});
it('should not able to update workspace meta for non workspace admin', () => {
ADMIN_AUTH.newUser = 'kibanaserver';
ADMIN_AUTH.newPassword = 'kibanaserver';

// Visit workspace list page
miscUtils.visitPage(`/app/workspace_list`);

cy.getElementByTestId('headerApplicationTitle')
.contains('Workspaces')
.should('be.exist');

cy.get('[role="main"]').contains(workspaceName).should('be.exist');

cy.get(`#${workspaceId}-actions`).click();
cy.getElementByTestId('workspace-list-edit-icon').click();

cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click();

cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).clear({
force: true,
});

cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.getElementByTestId('globalToastList')
.contains('Invalid workspace permission')
.should('be.exist');
});

it('should able to update workspace meta for workspace admin', () => {
const kibanaServerAdminWorkspace = {
name: 'kibana-server-workspace-admin',
features: ['use-case-all'],
settings: {
permissions: {
library_write: { users: [NONE_DASHBOARDS_ADMIN_USER.username] },
write: { users: [NONE_DASHBOARDS_ADMIN_USER.username] },
},
},
};
cy.deleteWorkspaceByName(kibanaServerAdminWorkspace.name);
cy.createWorkspace(kibanaServerAdminWorkspace)
.as('adminWorkspaceId')
.then(() => {
ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USER.username;
ADMIN_AUTH.newPassword = NONE_DASHBOARDS_ADMIN_USER.username;
wanglam marked this conversation as resolved.
Show resolved Hide resolved
});

// Visit workspace list page
miscUtils.visitPage(`/app/workspace_list`);

cy.getElementByTestId('headerApplicationTitle')
.contains('Workspaces')
.should('be.exist');

cy.get('[role="main"]')
.contains(kibanaServerAdminWorkspace.name)
.should('be.exist');

cy.get('@adminWorkspaceId').then((adminWorkspaceId) => {
cy.get(`#${adminWorkspaceId}-actions`).click();
});
cy.getElementByTestId('workspace-list-edit-icon').click();

cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click();

cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).clear({
force: true,
});

cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('This is a new workspace description.');

cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.getElementByTestId('globalToastList')
.contains('Update workspace successfully')
.should('be.exist');

cy.get('@adminWorkspaceId').then((adminWorkspaceId) => {
const expectedWorkspace = {
...kibanaServerAdminWorkspace,
description: 'This is a new workspace description.',
};
cy.checkWorkspace(adminWorkspaceId, expectedWorkspace);
cy.deleteWorkspaceById(adminWorkspaceId);
});
});
});
}
});
}
5 changes: 5 additions & 0 deletions cypress/utils/dashboards/workspace-plugin/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
*/

export const WORKSPACE_API_PREFIX = '/api/workspaces';

export const NONE_DASHBOARDS_ADMIN_USER = {
Copy link
Member

Choose a reason for hiding this comment

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

What about create internal user with command createInternalUser so the workspace tests don't rely on specific user and pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've tried this way before. But not only do we need to call createInternalUser, we also need to create a role and map the internal user to it too. It will be more complicated.

username: 'kibanaserver',
password: 'kibanaserver',
};
Loading