UNPKG

@wso2/identity-cypress-test-base

Version:

Commonly used commands, configs, utilities for cypress integration & e2e tests in WSO2 Identity Server front-end applications.

49 lines 2.06 kB
/* * Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) * All rights reserved. * * This software is the property of WSO2 Inc. and its suppliers, if any. * Dissemination of any information or reproduction of any material contained * herein in any form is strictly forbidden, unless permitted by WSO2 expressly. * You may not alter or remove any copyright or other notice from copies of this content. */ import { RequestContentTypes } from "../models/api-requests"; /** * This command use to get the Basic Authorization header * @param {string} username - Username of the user. * @param {string} password - Password of the user. */ Cypress.Commands.add("getBasicAuthorization", function (username, password) { var encodedCredentials = btoa(username + ":" + password); return cy.wrap("Basic ".concat(encodedCredentials)); }); /** * This command use to get the Bearer Authorization header, * @param {string} token - A valid token retreived by any grant type. */ Cypress.Commands.add("getBearerAuthorization", function (token) { return cy.wrap("Bearer ".concat(token)); }); /** * This command use to get the Authentication token via a Client Credential grant type * @param {string} serverHost - Server host endopoint * @param {string} clientID - API authetication application client ID * @param {string} clientSecret - API authetication application client Secret */ Cypress.Commands.add("getTokenViaClientCredential", function (serverHost, clientID, clientSecret) { var encodedCredentials = btoa(clientID + ":" + clientSecret); // Retrieve a token from Basic auth type via `oauth2/token` endpoint . return cy.request({ body: { "grant_type": "client_credentials", "scope": "SYSTEM" }, headers: { "Authorization": "Basic ".concat(encodedCredentials), "Content-Type": RequestContentTypes.URLENCODED }, method: "POST", url: "".concat(serverHost, "/oauth2/token") }); }); //# sourceMappingURL=auth.js.map