Skip to content

Commit

Permalink
Modify the constants path and fix the 'createIndexPattern()' command
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Oct 20, 2022
1 parent cb98fd3 commit 08de7d0
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 84 deletions.
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"VISBUILDER_ENABLED": false,
"DATASOURCE_MANAGEMENT_ENABLED": false
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"securitytenant": ["test"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
"cluster_permissions": [
"cluster_all"
],
"index_permissions": [{
"index_patterns": [
"*"
],
"dls": "",
"fls": [],
"masked_fields": [],
"allowed_actions": [
"indices_all"
]
}],
"tenant_permissions": [{
"tenant_patterns": [
"test"
],
"allowed_actions": [
"kibana_all_write"
]
}]
}
"index_permissions": [{
"index_patterns": [
"*"
],
"dls": "",
"fls": [],
"masked_fields": [],
"allowed_actions": [
"indices_all"
]
}],
"tenant_permissions": [{
"tenant_patterns": [
"test"
],
"allowed_actions": [
"kibana_all_write"
]
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"cluster_permissions": [
"cluster_all"
],
"index_permissions": [{
"index_patterns": [
"*"
],
"dls": "",
"fls": [],
"masked_fields": [],
"allowed_actions": [
"indices_all"
]
}],
"tenant_permissions": [{
"tenant_patterns": [],
"allowed_actions": []
}]
}
"index_permissions": [{
"index_patterns": [
"*"
],
"dls": "",
"fls": [],
"masked_fields": [],
"allowed_actions": [
"indices_all"
]
}],
"tenant_permissions": [{
"tenant_patterns": [],
"allowed_actions": []
}]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"backend_roles" : [ "kibanauser" ],
"users" : [ "test1", "test2" ]
}
"backend_roles" : [ "kibanauser" ],
"users" : [ "test1", "test2" ]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"users" : [ "test1" ]
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"users" : [ "test2" ]
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"description": "This test tenant for aggregation view feature testing."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

import {
ADMIN_AUTH,
Expand Down Expand Up @@ -51,12 +51,13 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) {
title: 's*',
timeFieldName: 'timestamp',
});
cy.createIndexPatternWithTenantHeader('index-pattern2', {
cy.createIndexPattern('index-pattern2', {
title: 'se*',
timeFieldName: 'timestamp',
},
indexPatternTenantHeaderSetUp
);
cy.wait(120000);
});

it('should check the saved objects as global tenant', () => {
Expand Down Expand Up @@ -103,4 +104,4 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) {
CURRENT_TENANT.newTenant = 'private';
});
});
}
}
21 changes: 1 addition & 20 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,7 @@ Cypress.Commands.add('bulkUploadDocs', (fixturePath, index) => {
});
});

Cypress.Commands.add('createIndexPattern', (id, attributes) => {
const url = `${
Cypress.config().baseUrl
}/api/saved_objects/index-pattern/${id}`;

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

Cypress.Commands.add('createIndexPatternWithTenantHeader', (id, attributes, header = {}) => {
Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => {
const url = `${
Cypress.config().baseUrl
}/api/saved_objects/index-pattern/${id}`;
Expand Down
8 changes: 8 additions & 0 deletions cypress/utils/dashboards/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { BASE_PATH } from '../base_constants';

// STACK MANAGEMENT PATH
export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management';

export const INDEX_PATTERN_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns';
export const SAVED_OBJECTS_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/objects';
11 changes: 1 addition & 10 deletions cypress/utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,9 @@ declare namespace Cypress {
/**
* Adds an index pattern
* @example
* cy.createIndexPattern('patterId', 'patt*', 'timestamp')
* cy.createIndexPattern('patterId', { title: 'patt*', timeFieldName: 'timestamp' })
*/
createIndexPattern<S = any>(
id: string,
attributes: {
title: string;
timeFieldName?: string;
[key: string]: any;
}
): Chainable<S>;

createIndexPatternWithTenantHeader<S = any>(
id: string,
attributes: {
title: string;
Expand Down
5 changes: 4 additions & 1 deletion cypress/utils/plugins/security-dashboards-plugin/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SEC_API } from '../../constants';
`${Cypress.env('openSearchUrl')}${SEC_API.TENANTS_BASE}/${tenantID}`,
tenantJson
);
cy.wait(10000);
});

Cypress.Commands.add('createInternalUser', (userID, userJson) => {
Expand All @@ -25,6 +26,7 @@ Cypress.Commands.add('createInternalUser', (userID, userJson) => {
`${Cypress.env('openSearchUrl')}${SEC_API.INTERNALUSERS_BASE}/${userID}`,
userJson
);
cy.wait(10000);
});

Cypress.Commands.add('createRole', (roleID, roleJson) => {
Expand All @@ -33,6 +35,7 @@ Cypress.Commands.add('createRole', (roleID, roleJson) => {
`${Cypress.env('openSearchUrl')}${SEC_API.ROLE_BASE}/${roleID}`,
roleJson
);
cy.wait(10000);
});

Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => {
Expand All @@ -41,5 +44,5 @@ Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => {
`${Cypress.env('openSearchUrl')}${SEC_API.ROLE_MAPPING_BASE}/${roleID}`,
rolemappingJson
);
cy.wait(10000);
});

52 changes: 52 additions & 0 deletions cypress/utils/plugins/security-dashboards-plugin/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// type definitions for custom commands like "createDefaultTodos"
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
/**
* Create a test tenant by calling REST API
* @example
* cy.createTenant('test_tenant', tenantJsonFixture )
*/
createTenant<S = any>(
tenantID: string,
tenantJson: string
): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create an internal user by calling REST API
* @example
* cy.createInternalUser('test_user', userJsonFixture )
*/
createInternalUser<S = any>(
userID: string,
userJson: string
): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create a role by calling REST API
* @example
* cy.createRole('role_name', roleJsonFixture )
*/
createRole<S = any>(
roleID: string,
roleJson: string
): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create a role mapping by calling REST API
* @example
* cy.createRoleMapping('role_name', rolemappingJsonFixture )
*/
createRoleMapping<S = any>(
roleID: string,
rolemappingJson: string
): Chainable<S>;
}
}
6 changes: 0 additions & 6 deletions cypress/utils/plugins/security/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,3 @@ export const SEC_API_CACHE_PURGE_PATH = BASE_SEC_API_PATH + '/cache';

export const SEC_API_AUTHINFO_PATH = BASE_PATH + '/api/v1/auth/authinfo';
export const SEC_API_TENANT_PATH = BASE_PATH + '/api/v1/multitenancy/tenant';

// STACK MANAGEMENT PATH
export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management';

export const INDEX_PATTERN_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns';
export const SAVED_OBJECTS_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/objects';

0 comments on commit 08de7d0

Please sign in to comment.