Skip to content

Commit

Permalink
Replace kibanaserver with self created workspace test user
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Nov 13, 2024
1 parent cb2a839 commit 4aaa782
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"cluster_permissions": ["*"],
"index_permissions": [
{
"index_patterns": ["*"],
"fls": [],
"masked_fields": [],
"allowed_actions": ["*"]
}
],
"tenant_permissions": [
{
"tenant_patterns": ["*"],
"allowed_actions": ["kibana_all_write"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"users": ["workspace-test"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"password": "testUserPassword123"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

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';
import workspaceTestUser from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestUser.json';
import workspaceTestRole from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestRole.json';
import workspaceTestRoleMapping from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestRoleMapping.json';

const NONE_DASHBOARDS_ADMIN_USERNAME = 'workspace-test';
const WORKSPACE_TEST_ROLE_NAME = 'workspace-test-role';

const miscUtils = new MiscUtils(cy);
const workspaceName = 'test_workspace_320sdfouAz';
Expand All @@ -16,6 +21,17 @@ let workspaceFeatures = ['use-case-observability'];
if (Cypress.env('WORKSPACE_ENABLED')) {
describe('Workspace detail', () => {
before(() => {
if (Cypress.env('SECURITY_ENABLED')) {
cy.createInternalUser(
NONE_DASHBOARDS_ADMIN_USERNAME,
workspaceTestUser
);
cy.createRole(WORKSPACE_TEST_ROLE_NAME, workspaceTestRole);
cy.createRoleMapping(
WORKSPACE_TEST_ROLE_NAME,
workspaceTestRoleMapping
);
}
cy.deleteWorkspaceByName(workspaceName);
cy.createWorkspace({
name: workspaceName,
Expand All @@ -25,15 +41,18 @@ 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] },
library_read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] },
read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] },
},
},
}).then((value) => (workspaceId = value));
});

after(() => {
cy.deleteWorkspaceById(workspaceId);
if (Cypress.env('SECURITY_ENABLED')) {
cy.deleteInternalUser(NONE_DASHBOARDS_ADMIN_USERNAME);
}
});

describe('workspace details', () => {
Expand Down Expand Up @@ -163,8 +182,8 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
ADMIN_AUTH.newPassword = originalPassword;
});
it('should not able to update workspace meta for non workspace admin', () => {
ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USER.username;
ADMIN_AUTH.newPassword = NONE_DASHBOARDS_ADMIN_USER.password;
ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME;
ADMIN_AUTH.newPassword = workspaceTestUser.password;

// Visit workspace list page
miscUtils.visitPage(`/app/workspace_list`);
Expand Down Expand Up @@ -200,17 +219,17 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
features: ['use-case-all'],
settings: {
permissions: {
library_write: { users: [NONE_DASHBOARDS_ADMIN_USER.username] },
write: { users: [NONE_DASHBOARDS_ADMIN_USER.username] },
library_write: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] },
write: { users: [NONE_DASHBOARDS_ADMIN_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.password;
ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME;
ADMIN_AUTH.newPassword = workspaceTestUser.password;
});

// Visit workspace list page
Expand Down
5 changes: 0 additions & 5 deletions cypress/utils/dashboards/workspace-plugin/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@
*/

export const WORKSPACE_API_PREFIX = '/api/workspaces';

export const NONE_DASHBOARDS_ADMIN_USER = {
username: 'kibanaserver',
password: 'kibanaserver',
};
8 changes: 8 additions & 0 deletions cypress/utils/plugins/security-dashboards-plugin/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Cypress.Commands.add('createInternalUser', (userID, userJson) => {
cy.wait(10000);
});

Cypress.Commands.add('deleteInternalUser', (userID) => {
cy.request(
'DELETE',
`${Cypress.env('openSearchUrl')}${SEC_API.INTERNALUSERS_BASE}/${userID}`
);
cy.wait(10000);
});

Cypress.Commands.add('createRole', (roleID, roleJson) => {
cy.request(
'PUT',
Expand Down

0 comments on commit 4aaa782

Please sign in to comment.