Skip to content

Commit

Permalink
Merge branch 'main' into upgrade_18
Browse files Browse the repository at this point in the history
  • Loading branch information
pavinduLakshan authored Mar 9, 2024
2 parents 2f15cd3 + 180a8fb commit 808da29
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 188 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wso2/identity-cypress-test-base",
"version": "0.2.17",
"version": "0.2.31",
"description": "Commonly used commands, configs, utilities for cypress integration & e2e tests in WSO2 Identity Server front-end applications.",
"author": "WSO2",
"license": "Apache-2.0",
Expand All @@ -18,7 +18,7 @@
"scripts": {
"build": "npm run compile",
"clean": "npm run rimraf ./dist",
"compile": "run-script-os",
"compile": "tsc -p tsconfig.json",
"compile:win32": ".\\node_modules\\.bin\\tsc -p tsconfig.json",
"compile:default": "./node_modules/.bin/tsc -p tsconfig.json",
"rimraf": "run-script-os",
Expand Down
85 changes: 45 additions & 40 deletions src/api/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,54 @@
* 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 Authentication method with the prefered token and grant type
* @example cy.scimCreateUser("https://<hostname>/domain/", "admin", "admin123",reqBody, true)
* @param {string} serverHost - Host name
* @param {string} username - API authetication username/client-ID
* @param {string} password - API authetication credentials password/client-secret
* @param {jsonbody} grantType - Prefeered grant type
* @param {boolean} authType - Prefeered authentication type
*
* Ex:
* if using the Basic Authentication ,
* cy.getAuthorization("https://localhost:9443/t/carbon.super","admin","admin","","Basic" )
*
* if using Bearer Authentication
* cy.getAuthorization("https://localhost:9443/t/carbon.super","admin","admin","client_credentails","Bearer" )
* 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("getAuthentication", (serverHost: string, username: string, password: string,
grantType: string, authType: "Basic" | "Bearer") => {

Cypress.Commands.add("getBasicAuthorization", (username: string, password: string) => {

const encodedCredentials = btoa(username + ":" + password);

// Retrive token from Basic auth type
if (authType === "Basic") {
return cy.wrap(encodedCredentials);
}

// Retrieve a bearer token from Bearer auth type `oauth2/token` endpoint.
else {
return cy.request({
body: {
"grant_type": grantType,
"scope": "SYSTEM",
},
headers:
{
"Authorization": `Basic ${encodedCredentials}`,
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
url: `${serverHost}/oauth2/token`
});
}

throw new Error("Invalid Authentication type");
return cy.wrap(`Basic ${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", (token: string) => {

return cy.wrap(`Bearer ${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", (serverHost: string, clientID: string, clientSecret: string) => {

const 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 ${encodedCredentials}`,
"Content-Type": RequestContentTypes.URLENCODED
},
method: "POST",
url: `${serverHost}/oauth2/token`
});
});
43 changes: 17 additions & 26 deletions src/api/commands/user-managment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,28 @@

/// <reference types="cypress" />

import { RequestContentTypes, RequestMethodTypes } from "../constants/api-constants";
import { UserManagmentConstants } from "../constants/user-management-constants";
import { RequestContentTypes, RequestType } from "../models/api-requests";
import { UserManagmentConstants } from "../models/user-management";

/**
* This command use to create users from scim2.0 POST method
* @example cy.scimCreateUser("https://<hostname>/domain/", "admin", "admin123",reqBody, true)
* @param {string} host - host
* @param {string} authrzUserName - API authetication credentials user name
* @param {string} authrzPassword - API authetication credentials passowrd
* @param {jsonbody} reqBody - request body with user profile informations
* @param {boolean} failOnStatusCode- Whether to fail on response codes other than 2xx and 3xx
* @param {string} authzHeader - Authorization token
* @param {jsonbody} reqBody - Request body with user profile informations
* @param {boolean} failOnStatusCode - Whether to fail on response codes other than 2xx and 3xx
* */
Cypress.Commands.add("createUserViaAPI", (host: string, username: string, password: string, reqBody: Cypress.ObjectLike,
grantType: string, authType: "Basic" | "Bearer", failOnStatusCode = true) => {
Cypress.Commands.add("createUserViaAPI", (host: string ,authzHeader: string, reqBody: Cypress.ObjectLike,
failOnStatusCode = true ) => {

cy.getAuthentication(host, username,
password, grantType, authType).then(response => {

const token: string = response.body.access_token;

return cy.request({
"method": RequestMethodTypes.POST,
"url": host + UserManagmentConstants.SCIM2_ENDPOINT + UserManagmentConstants.SCIM2_USER_ENDPOINT,
"failOnStatusCode": failOnStatusCode,
"auth": {
token
},
"headers": {
"Content-Type": RequestContentTypes.URLENCODED
},
"body": reqBody
});
return cy.request({
"method": RequestType.POST,
"url": host + UserManagmentConstants.SCIM2_END_POINT + UserManagmentConstants.SCIM2_USER_ENDPOINT,
"failOnStatusCode": failOnStatusCode,
"headers": {
"Content-Type": RequestContentTypes.SCIMJSON,
"accept": RequestContentTypes.SCIMJSON,
"Authorization": authzHeader
},
"body": reqBody
});
});
41 changes: 0 additions & 41 deletions src/api/constants/api-constants.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/api/constants/index.ts

This file was deleted.

34 changes: 0 additions & 34 deletions src/api/constants/user-management-constants.ts

This file was deleted.

15 changes: 15 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2024 WSO2 Inc. (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.
*/

/// <reference types="cypress" />
/// <reference path="../../types/api/commands.d.ts" />

import "./commands";
export * from "./models";
3 changes: 2 additions & 1 deletion src/api/models/api-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

export enum RequestType {
POST = "POST",
GET = "get"
GET = "GET"
}

export enum RequestContentTypes {
URLENCODED = "application/x-www-form-urlencoded",
SCIMJSON = "application/scim+json"
}

2 changes: 1 addition & 1 deletion src/api/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
///<reference types="cypress" />
/// <reference path="../../../types/api/commands.d.ts" />

import "./api-requests/";
import "./api-requests";
import "./user-management";
4 changes: 2 additions & 2 deletions src/ui/constants/login-page-dom-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class LoginPageDomConstants {

// TODO: Use data test id's here.
// Tracker: https://github.com/wso2-enterprise/asgardeo-product/issues/999
public static readonly USERNAME_INPUT_DATA_ATTR: string = "#usernameUserInput";
public static readonly USERNAME_INPUT_DATA_ATTR: string = "login-page-username-input";
public static readonly PASSWORD_INPUT_DATA_ATTR: string = "login-page-password-input";
public static readonly CONTINUE_BUTTON_DATA_ATTR: string = "Continue";
public static readonly CONTINUE_BUTTON_DATA_ATTR: string = "identifier-auth-continue-button";
public static readonly SUBMIT_BUTTON_DATA_ATTR: string = "login-page-continue-login-button";
}
5 changes: 3 additions & 2 deletions src/ui/page-objects/login-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export class LoginPage {
* Get the data attribute for login page user input field.
* @return {Cypress.Chainable<JQuery<HTMLElement>>}
*/
public getLoginUsernameInputField(): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.get(LoginPageDomConstants.USERNAME_INPUT_DATA_ATTR);
public getLoginUsernameInputField(): Cypress.Chainable<Element> {

return cy.dataTestId(LoginPageDomConstants.USERNAME_INPUT_DATA_ATTR);
}

/**
Expand Down
35 changes: 22 additions & 13 deletions types/api/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@ declare namespace Cypress {
/**
* Custom command to create users from scim2.0 POST method
*/
createUserViaAPI(host: string, username: string, password: string, reqBody: Cypress.ObjectLike,
grantType: string, authType: "Basic" | "Bearer", failOnStatusCode?: boolean): Cypress.Chainable<any>;
createUserViaAPI(host: string, authzHeader: string, reqBody: Cypress.ObjectLike,
failOnStatusCode?: boolean): Cypress.Chainable<any>;

/**
* This command use to get the Authentication method with the prefered token and grant type
* @example cy.scimCreateUser("https://<hostname>/domain/", "admin", "admin123", reqBody, true)
* @param {string} serverHost - Host name
* @param {string} username - API authetication username/client-ID
* @param {string} password - API authetication credentials password/client-secret
* @param {jsonbody} grantType - Prefeered grant type
* @param {boolean} authType - Prefeered authentication type
* */
getAuthentication(host: string, username: string, password: string, grantType: string,
authType: "Basic" | "Bearer"): Cypress.Chainable<any>;
/**
* This command use to get the Basic Authorization header
* @param {string} username - Username of the user.
* @param {string} password - Password of the user.
*/
getBasicAuthorization(username: string, password: string): Cypress.Chainable<any>;

/**
* This command use to get the Bearer Authorization header,
* @param {string} token - A valid token retreived by any grant type.
*/
getBearerAuthorization(token: string): Cypress.Chainable<any>;

/**
* 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
*/
getTokenViaClientCredential(serverHost: string, clientID: string, clientSecret: string): Cypress.Chainable<any>;
}
}

0 comments on commit 808da29

Please sign in to comment.