From b5160c0f8f7b5ee13c19c409cceafe5a25ad2737 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon Date: Tue, 11 Jul 2023 15:08:00 +0530 Subject: [PATCH 1/4] Add UI tests for editing claim mappings under Token Handling Options in Advanced Configurations --- ....spec.js => 09-add-edit-delete-km.spec.js} | 48 ++++++++++++++++--- tests/cypress/support/commands.js | 7 ++- 2 files changed, 46 insertions(+), 9 deletions(-) rename tests/cypress/integration/admin/{09-add-km.spec.js => 09-add-edit-delete-km.spec.js} (55%) diff --git a/tests/cypress/integration/admin/09-add-km.spec.js b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js similarity index 55% rename from tests/cypress/integration/admin/09-add-km.spec.js rename to tests/cypress/integration/admin/09-add-edit-delete-km.spec.js index c193c2f848e..0aa3d9aef3c 100644 --- a/tests/cypress/integration/admin/09-add-km.spec.js +++ b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js @@ -16,14 +16,14 @@ * under the License. */ +import Utils from "@support/utils"; + describe("Add key manager", () => { - const carbonUsername = 'admin'; - const carbonPassword = 'admin'; - before(function () { - cy.loginToAdmin(carbonUsername, carbonPassword); - }) - it.only("Add key manager", () => { + const { carbonUsername, carbonPassword, tenant, superTenant } = Utils.getUserInfo(); + + const addKeyManager = (usernameLocal, passwordLocal, tenant) => { + cy.loginToAdmin(usernameLocal, passwordLocal, tenant); const km = 'myAuth0'; const wellKnowUrl = 'https://my-tenant.us.auth0.com/.well-known/openid-configuration'; const clientId = 'test'; @@ -32,6 +32,10 @@ describe("Add key manager", () => { const introspectionEp = 'https://my-tenant.auth0.com/oauth/token'; const userInfoEp = 'https://my-tenant.auth0.com/oauth/userInfo'; const scopeManagementEp = 'https://my-tenant.auth0.com/oauth/scope'; + const claimKey1 = 'claimKey1'; + const claimValueRegex1 = 'claimValueRegex1'; + const claimKey2 = 'claimKey2'; + const claimValueRegex2 = 'claimValueRegex2'; cy.get('[data-testid="Key Managers"]').click(); cy.get('.MuiButton-label').contains('Add Key Manager').click(); @@ -51,16 +55,46 @@ describe("Add key manager", () => { cy.get('input[name="client_id"]').type(clientId); cy.get('input[name="client_secret"]').type(clientSecret); cy.get('input[name="audience"]').type(audience); + // adding claims under Token Handling Options for JWT type + cy.get('#mui-component-select-type').click(); + cy.contains('li', 'JWT').click(); + cy.get('input[name="claimKey"]').type(claimKey1); + cy.get('input[name="claimValueRegex"]').type(claimValueRegex1); + cy.get('[aria-label="[object Object]"]').click(); + cy.get('input[name="claimKey"]').type(claimKey2); + cy.get('input[name="claimValueRegex"]').type(claimValueRegex2); + cy.get('[aria-label="[object Object]"]').click(); + // validating added claims + cy.contains(claimKey1).should('exist'); + cy.contains(claimValueRegex1).should('exist'); + cy.contains(claimKey2).should('exist'); + cy.contains(claimValueRegex2).should('exist'); cy.get('button.MuiButton-containedPrimary span').contains('Add').click(); // validating cy.get('td > div').contains(km).should('exist'); }); + // edit key manager + cy.get('td > div').contains(km).click(); + // editing claims under Token Handling Options for JWT type (adding one more claim and deleting one claim) + cy.get('input[name="claimKey"]').type('claimKey3'); + cy.get('input[name="claimValueRegex"]').type('claimValueRegex3'); + cy.get('[aria-label="[object Object]"]').click(); + // deleting claimKey1 + cy.contains(claimKey1).parents('tr').find('button').click(); + cy.contains(claimKey1).should('not.exist'); + cy.get('button.MuiButton-containedPrimary span').contains('Update').click(); + // delete cy.get(`[data-testid="${km}-actions"] > span:first-child svg`).click(); cy.get('button > span').contains('Delete').click(); cy.get('td > div').contains(km).should('not.exist'); + } + it.only("Add key manager - super admin", () => { + addKeyManager(carbonUsername, carbonPassword, superTenant); + }); + it.only("Add key manager - tenant user", () => { + addKeyManager(carbonUsername, carbonPassword, tenant); }); - }) \ No newline at end of file diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 3ad92fefe10..a451257f503 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -50,6 +50,9 @@ Cypress.Commands.add('carbonLogout', () => { }) Cypress.Commands.add('portalLogin', (username, password, portal, tenant='carbon.super') => { + if (tenant != 'carbon.super') { + username = `${username}@${tenant}`; + } Cypress.log({ name: 'portalLogin', message: `${username} | ${password}`, @@ -76,8 +79,8 @@ Cypress.Commands.add('loginToDevportal', (username, password) => { cy.portalLogin(username, password, 'devportal'); }) -Cypress.Commands.add('loginToAdmin', (username, password) => { - cy.portalLogin(username, password, 'admin'); +Cypress.Commands.add('loginToAdmin', (username, password, tenant = 'carbon.super') => { + cy.portalLogin(username, password, 'admin', tenant); }) Cypress.Commands.add('addNewTenant', (tenant = 'wso2.com', username = 'admin', password = 'admin') => { From 36cffe3eea0d7ad1adf45251eb69543160613762 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon <42693357+thisaltennakoon@users.noreply.github.com> Date: Tue, 11 Jul 2023 15:41:22 +0530 Subject: [PATCH 2/4] Update 09-add-edit-delete-km.spec.js --- tests/cypress/integration/admin/09-add-edit-delete-km.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js index 0aa3d9aef3c..9692f201fd5 100644 --- a/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js +++ b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js @@ -70,6 +70,7 @@ describe("Add key manager", () => { cy.contains(claimKey2).should('exist'); cy.contains(claimValueRegex2).should('exist'); cy.get('button.MuiButton-containedPrimary span').contains('Add').click(); + cy.wait(1000); // validating cy.get('td > div').contains(km).should('exist'); @@ -97,4 +98,4 @@ describe("Add key manager", () => { it.only("Add key manager - tenant user", () => { addKeyManager(carbonUsername, carbonPassword, tenant); }); -}) \ No newline at end of file +}) From 2dc3149383fbc5f6a4424c43a0edb2839d812fb8 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon Date: Tue, 11 Jul 2023 18:33:49 +0530 Subject: [PATCH 3/4] Added getTenantUser function --- .../integration/admin/09-add-edit-delete-km.spec.js | 6 +++--- tests/cypress/support/commands.js | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js index 9692f201fd5..1e9644408c7 100644 --- a/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js +++ b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js @@ -22,8 +22,8 @@ describe("Add key manager", () => { const { carbonUsername, carbonPassword, tenant, superTenant } = Utils.getUserInfo(); - const addKeyManager = (usernameLocal, passwordLocal, tenant) => { - cy.loginToAdmin(usernameLocal, passwordLocal, tenant); + const addKeyManager = (usernameLocal, passwordLocal) => { + cy.loginToAdmin(usernameLocal, passwordLocal); const km = 'myAuth0'; const wellKnowUrl = 'https://my-tenant.us.auth0.com/.well-known/openid-configuration'; const clientId = 'test'; @@ -96,6 +96,6 @@ describe("Add key manager", () => { addKeyManager(carbonUsername, carbonPassword, superTenant); }); it.only("Add key manager - tenant user", () => { - addKeyManager(carbonUsername, carbonPassword, tenant); + addKeyManager(Utils.getTenantUser(carbonUsername, tenant), carbonPassword, tenant); }); }) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index a451257f503..3ad92fefe10 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -50,9 +50,6 @@ Cypress.Commands.add('carbonLogout', () => { }) Cypress.Commands.add('portalLogin', (username, password, portal, tenant='carbon.super') => { - if (tenant != 'carbon.super') { - username = `${username}@${tenant}`; - } Cypress.log({ name: 'portalLogin', message: `${username} | ${password}`, @@ -79,8 +76,8 @@ Cypress.Commands.add('loginToDevportal', (username, password) => { cy.portalLogin(username, password, 'devportal'); }) -Cypress.Commands.add('loginToAdmin', (username, password, tenant = 'carbon.super') => { - cy.portalLogin(username, password, 'admin', tenant); +Cypress.Commands.add('loginToAdmin', (username, password) => { + cy.portalLogin(username, password, 'admin'); }) Cypress.Commands.add('addNewTenant', (tenant = 'wso2.com', username = 'admin', password = 'admin') => { From 2ecb88dfd6d55db0906e48c8cfbdeb6a67296367 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon Date: Tue, 11 Jul 2023 20:30:50 +0530 Subject: [PATCH 4/4] Update 09-add-edit-delete-km.spec.js --- tests/cypress/integration/admin/09-add-edit-delete-km.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js index 1e9644408c7..92fd1adced0 100644 --- a/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js +++ b/tests/cypress/integration/admin/09-add-edit-delete-km.spec.js @@ -93,9 +93,9 @@ describe("Add key manager", () => { cy.get('td > div').contains(km).should('not.exist'); } it.only("Add key manager - super admin", () => { - addKeyManager(carbonUsername, carbonPassword, superTenant); + addKeyManager(carbonUsername, carbonPassword); }); it.only("Add key manager - tenant user", () => { - addKeyManager(Utils.getTenantUser(carbonUsername, tenant), carbonPassword, tenant); + addKeyManager(Utils.getTenantUser(carbonUsername, tenant), carbonPassword); }); })