Skip to content

Commit

Permalink
Set up utils for customize commands
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Nov 22, 2023
1 parent 21c0cc3 commit 80192ed
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .cypress/utils/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { SEC_API } from "./constants";

Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => {
cy.request(
'PUT',
`${Cypress.env('openSearchUrl')}${SEC_API.ROLE_MAPPING_BASE}/${roleID}`,
rolemappingJson
);
cy.wait(10000);
});
34 changes: 34 additions & 0 deletions .cypress/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/**
*****************************
SECURITY DASHBOARDS PLUGIN CONSTANTS
*****************************
*/

//Security API Constants
export const SEC_API_PREFIX = '/_plugins/_security/api';
export const SEC_API = {
TENANTS_BASE: `${SEC_API_PREFIX}/tenants`,
INTERNALUSERS_BASE: `${SEC_API_PREFIX}/internalusers`,
ROLE_BASE: `${SEC_API_PREFIX}/roles`,
ROLE_MAPPING_BASE: `${SEC_API_PREFIX}/rolesmapping`,
};
16 changes: 16 additions & 0 deletions .cypress/utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// type definitions for custom commands like "createDefaultTodos"
/// <reference types="cypress" />

declare namespace Cypress {
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>;
}
}
3 changes: 3 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ module.exports = defineConfig({
baseUrl: 'http://localhost:5601',
specPattern: '.cypress/e2e/**/*.spec.js',
},
env: {
openSearchUrl: 'https://localhost:9200',
},
});

0 comments on commit 80192ed

Please sign in to comment.