diff --git a/cypress/integration/realm_settings_test.spec.ts b/cypress/integration/realm_settings_test.spec.ts index 8a8be02d28..6437a0cbfa 100644 --- a/cypress/integration/realm_settings_test.spec.ts +++ b/cypress/integration/realm_settings_test.spec.ts @@ -13,71 +13,72 @@ const masthead = new Masthead(); const modalUtils = new ModalUtils(); const realmSettingsPage = new RealmSettingsPage(); -describe("Realm settings", () => { - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); +describe("Realm settings tests", () => { + describe("Realm settings tabs tests", () => { + const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); - beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); - sidebarPage.goToRealm(realmName); - }); + beforeEach(() => { + keycloakBefore(); + loginPage.logIn(); + sidebarPage.goToRealm(realmName); + }); - before(async () => { - await new AdminClient().createRealm(realmName); - }); + before(async () => { + await new AdminClient().createRealm(realmName); + }); - after(async () => { - await new AdminClient().deleteRealm(realmName); - }); + after(async () => { + await new AdminClient().deleteRealm(realmName); + }); - const goToKeys = () => { - const keysUrl = `/auth/admin/realms/${realmName}/keys`; - cy.intercept(keysUrl).as("keysFetch"); - cy.findByTestId("rs-keys-tab").click(); - cy.findByTestId("rs-keys-list-tab").click(); - cy.wait(["@keysFetch"]); + const goToKeys = () => { + const keysUrl = `/auth/admin/realms/${realmName}/keys`; + cy.intercept(keysUrl).as("keysFetch"); + cy.findByTestId("rs-keys-tab").click(); + cy.findByTestId("rs-keys-list-tab").click(); + cy.wait(["@keysFetch"]); - return this; - }; + return this; + }; - const goToDetails = () => { - const keysUrl = `/auth/admin/realms/${realmName}/keys`; - cy.intercept(keysUrl).as("keysFetch"); + const goToDetails = () => { + const keysUrl = `/auth/admin/realms/${realmName}/keys`; + cy.intercept(keysUrl).as("keysFetch"); - cy.findByTestId("rs-keys-tab").click(); - cy.findByTestId("rs-providers-tab").click(); - cy.findAllByTestId("provider-name-link") - .contains("test_aes-generated") - .click(); + cy.findByTestId("rs-keys-tab").click(); + cy.findByTestId("rs-providers-tab").click(); + cy.findAllByTestId("provider-name-link") + .contains("test_aes-generated") + .click(); - sidebarPage.goToRealmSettings(); + sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-keys-tab").click(); - cy.findByTestId("rs-providers-tab").click(); - cy.findAllByTestId("provider-name-link") - .contains("test_hmac-generated") - .click(); + cy.findByTestId("rs-keys-tab").click(); + cy.findByTestId("rs-providers-tab").click(); + cy.findAllByTestId("provider-name-link") + .contains("test_hmac-generated") + .click(); - sidebarPage.goToRealmSettings(); + sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-keys-tab").click(); - cy.findByTestId("rs-providers-tab").click(); - cy.findAllByTestId("provider-name-link").contains("test_rsa").click(); + cy.findByTestId("rs-keys-tab").click(); + cy.findByTestId("rs-providers-tab").click(); + cy.findAllByTestId("provider-name-link").contains("test_rsa").click(); - sidebarPage.goToRealmSettings(); + sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-keys-tab").click(); - cy.findByTestId("rs-providers-tab").click(); - cy.findAllByTestId("provider-name-link") - .contains("test_rsa-generated") - .click(); + cy.findByTestId("rs-keys-tab").click(); + cy.findByTestId("rs-providers-tab").click(); + cy.findAllByTestId("provider-name-link") + .contains("test_rsa-generated") + .click(); - cy.wait(["@keysFetch"]); + cy.wait(["@keysFetch"]); - return this; - }; + return this; + }; - /*const deleteProvider = (providerName: string) => { + /*const deleteProvider = (providerName: string) => { const url = `/auth/admin/realms/${realmName}/users/*`; cy.intercept(url).as("reload"); cy.findByTestId("provider-name") @@ -93,160 +94,162 @@ describe("Realm settings", () => { return this; };*/ - const addBundle = () => { - const localizationUrl = `/auth/admin/realms/${realmName}/localization/en`; - cy.intercept(localizationUrl).as("localizationFetch"); + const addBundle = () => { + const localizationUrl = `/auth/admin/realms/${realmName}/localization/en`; + cy.intercept(localizationUrl).as("localizationFetch"); - realmSettingsPage.addKeyValuePair( - "key_" + (Math.random() + 1).toString(36).substring(7), - "value_" + (Math.random() + 1).toString(36).substring(7) - ); + realmSettingsPage.addKeyValuePair( + "key_" + (Math.random() + 1).toString(36).substring(7), + "value_" + (Math.random() + 1).toString(36).substring(7) + ); - cy.wait(["@localizationFetch"]); + cy.wait(["@localizationFetch"]); - return this; - }; + return this; + }; - it("Go to general tab", function () { - sidebarPage.goToRealmSettings(); - realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch); - realmSettingsPage.save(realmSettingsPage.generalSaveBtn); - masthead.checkNotificationMessage("Realm successfully updated"); - realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch); - realmSettingsPage.save(realmSettingsPage.generalSaveBtn); - masthead.checkNotificationMessage("Realm successfully updated"); - }); - - it("Go to login tab", () => { - sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-login-tab").click(); - realmSettingsPage.toggleSwitch(realmSettingsPage.userRegSwitch); - realmSettingsPage.toggleSwitch(realmSettingsPage.forgotPwdSwitch); - realmSettingsPage.toggleSwitch(realmSettingsPage.rememberMeSwitch); - }); - - it("Go to email tab", () => { - sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-email-tab").click(); - - realmSettingsPage.addSenderEmail("example@example.com"); - - realmSettingsPage.toggleCheck(realmSettingsPage.enableSslCheck); - realmSettingsPage.toggleCheck(realmSettingsPage.enableStartTlsCheck); - - realmSettingsPage.save(realmSettingsPage.emailSaveBtn); - - realmSettingsPage.fillHostField("localhost"); - cy.findByTestId(realmSettingsPage.testConnectionButton).click(); - - realmSettingsPage.fillEmailField( - "example" + (Math.random() + 1).toString(36).substring(7) + "@example.com" - ); - - cy.findByTestId(realmSettingsPage.modalTestConnectionButton).click(); - - masthead.checkNotificationMessage("Error! Failed to send email."); - }); - - it("Go to themes tab", () => { - sidebarPage.goToRealmSettings(); - cy.intercept(`/auth/admin/realms/${realmName}/keys`).as("load"); - - cy.findByTestId("rs-themes-tab").click(); - cy.wait(["@load"]); - - realmSettingsPage.selectLoginThemeType("keycloak"); - realmSettingsPage.selectAccountThemeType("keycloak"); - realmSettingsPage.selectAdminThemeType("base"); - realmSettingsPage.selectEmailThemeType("base"); - - realmSettingsPage.saveThemes(); - }); - - describe("Events tab", () => { - const listingPage = new ListingPage(); - - it("Enable user events", () => { - cy.intercept("GET", `/auth/admin/realms/${realmName}/keys`).as("load"); + it("Go to general tab", function () { sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-realm-events-tab").click(); + realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch); + realmSettingsPage.save(realmSettingsPage.generalSaveBtn); + masthead.checkNotificationMessage("Realm successfully updated"); + realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch); + realmSettingsPage.save(realmSettingsPage.generalSaveBtn); + masthead.checkNotificationMessage("Realm successfully updated"); + }); + + it("Go to login tab", () => { + sidebarPage.goToRealmSettings(); + cy.findByTestId("rs-login-tab").click(); + realmSettingsPage.toggleSwitch(realmSettingsPage.userRegSwitch); + realmSettingsPage.toggleSwitch(realmSettingsPage.forgotPwdSwitch); + realmSettingsPage.toggleSwitch(realmSettingsPage.rememberMeSwitch); + }); + + it("Go to email tab", () => { + sidebarPage.goToRealmSettings(); + cy.findByTestId("rs-email-tab").click(); + + realmSettingsPage.addSenderEmail("example@example.com"); + + realmSettingsPage.toggleCheck(realmSettingsPage.enableSslCheck); + realmSettingsPage.toggleCheck(realmSettingsPage.enableStartTlsCheck); + + realmSettingsPage.save(realmSettingsPage.emailSaveBtn); + + realmSettingsPage.fillHostField("localhost"); + cy.findByTestId(realmSettingsPage.testConnectionButton).click(); + + realmSettingsPage.fillEmailField( + "example" + + (Math.random() + 1).toString(36).substring(7) + + "@example.com" + ); + + cy.findByTestId(realmSettingsPage.modalTestConnectionButton).click(); + + masthead.checkNotificationMessage("Error! Failed to send email."); + }); + + it("Go to themes tab", () => { + sidebarPage.goToRealmSettings(); + cy.intercept(`/auth/admin/realms/${realmName}/keys`).as("load"); + + cy.findByTestId("rs-themes-tab").click(); cy.wait(["@load"]); - realmSettingsPage - .toggleSwitch(realmSettingsPage.enableEvents) - .save(realmSettingsPage.eventsUserSave); - masthead.checkNotificationMessage("Successfully saved configuration"); + realmSettingsPage.selectLoginThemeType("keycloak"); + realmSettingsPage.selectAccountThemeType("keycloak"); + realmSettingsPage.selectAdminThemeType("base"); + realmSettingsPage.selectEmailThemeType("base"); - realmSettingsPage.clearEvents("user"); - - modalUtils - .checkModalMessage( - "If you clear all events of this realm, all records will be permanently cleared in the database" - ) - .confirmModal(); - - masthead.checkNotificationMessage("The user events have been cleared"); - - const events = ["Client info", "Client info error"]; - - cy.intercept("GET", `/auth/admin/realms/${realmName}/events/config`).as( - "fetchConfig" - ); - realmSettingsPage.addUserEvents(events).clickAdd(); - masthead.checkNotificationMessage("Successfully saved configuration"); - cy.wait(["@fetchConfig"]); - sidebarPage.waitForPageLoad(); - - for (const event of events) { - listingPage.searchItem(event, false).itemExist(event); - } + realmSettingsPage.saveThemes(); }); - }); - it("Go to keys tab", () => { - sidebarPage.goToRealmSettings(); + describe("Events tab", () => { + const listingPage = new ListingPage(); - cy.findByTestId("rs-keys-tab").click(); - }); + it("Enable user events", () => { + cy.intercept("GET", `/auth/admin/realms/${realmName}/keys`).as("load"); + sidebarPage.goToRealmSettings(); + cy.findByTestId("rs-realm-events-tab").click(); + cy.wait(["@load"]); - it("add Providers", () => { - sidebarPage.goToRealmSettings(); + realmSettingsPage + .toggleSwitch(realmSettingsPage.enableEvents) + .save(realmSettingsPage.eventsUserSave); + masthead.checkNotificationMessage("Successfully saved configuration"); - cy.findByTestId("rs-keys-tab").click(); + realmSettingsPage.clearEvents("user"); - cy.findByTestId("rs-providers-tab").click(); + modalUtils + .checkModalMessage( + "If you clear all events of this realm, all records will be permanently cleared in the database" + ) + .confirmModal(); - realmSettingsPage.toggleAddProviderDropdown(); + masthead.checkNotificationMessage("The user events have been cleared"); - cy.findByTestId("option-aes-generated").click(); - realmSettingsPage.enterConsoleDisplayName("test_aes-generated"); - realmSettingsPage.addProvider(); + const events = ["Client info", "Client info error"]; - realmSettingsPage.toggleAddProviderDropdown(); + cy.intercept("GET", `/auth/admin/realms/${realmName}/events/config`).as( + "fetchConfig" + ); + realmSettingsPage.addUserEvents(events).clickAdd(); + masthead.checkNotificationMessage("Successfully saved configuration"); + cy.wait(["@fetchConfig"]); + sidebarPage.waitForPageLoad(); - cy.findByTestId("option-ecdsa-generated").click(); - realmSettingsPage.enterConsoleDisplayName("test_ecdsa-generated"); - realmSettingsPage.addProvider(); + for (const event of events) { + listingPage.searchItem(event, false).itemExist(event); + } + }); + }); - realmSettingsPage.toggleAddProviderDropdown(); + it("Go to keys tab", () => { + sidebarPage.goToRealmSettings(); - cy.findByTestId("option-hmac-generated").click(); - realmSettingsPage.enterConsoleDisplayName("test_hmac-generated"); - realmSettingsPage.addProvider(); + cy.findByTestId("rs-keys-tab").click(); + }); - realmSettingsPage.toggleAddProviderDropdown(); + it("add Providers", () => { + sidebarPage.goToRealmSettings(); - cy.findByTestId("option-rsa-generated").click(); - realmSettingsPage.enterConsoleDisplayName("test_rsa-generated"); - realmSettingsPage.addProvider(); - }); + cy.findByTestId("rs-keys-tab").click(); - it("go to details", () => { - sidebarPage.goToRealmSettings(); - goToDetails(); - }); + cy.findByTestId("rs-providers-tab").click(); - /*it("delete providers", () => { + realmSettingsPage.toggleAddProviderDropdown(); + + cy.findByTestId("option-aes-generated").click(); + realmSettingsPage.enterConsoleDisplayName("test_aes-generated"); + realmSettingsPage.addProvider(); + + realmSettingsPage.toggleAddProviderDropdown(); + + cy.findByTestId("option-ecdsa-generated").click(); + realmSettingsPage.enterConsoleDisplayName("test_ecdsa-generated"); + realmSettingsPage.addProvider(); + + realmSettingsPage.toggleAddProviderDropdown(); + + cy.findByTestId("option-hmac-generated").click(); + realmSettingsPage.enterConsoleDisplayName("test_hmac-generated"); + realmSettingsPage.addProvider(); + + realmSettingsPage.toggleAddProviderDropdown(); + + cy.findByTestId("option-rsa-generated").click(); + realmSettingsPage.enterConsoleDisplayName("test_rsa-generated"); + realmSettingsPage.addProvider(); + }); + + it("go to details", () => { + sidebarPage.goToRealmSettings(); + goToDetails(); + }); + + /*it("delete providers", () => { sidebarPage.goToRealmSettings(); const url = `/auth/admin/realms/${realmName}/keys`; cy.intercept(url).as("load"); @@ -261,168 +264,201 @@ describe("Realm settings", () => { deleteProvider("test_hmac-generated"); deleteProvider("test_rsa-generated"); });*/ - it("Test keys", () => { - sidebarPage.goToRealmSettings(); - goToKeys(); + it("Test keys", () => { + sidebarPage.goToRealmSettings(); + goToKeys(); - realmSettingsPage.testSelectFilter(); + realmSettingsPage.testSelectFilter(); + }); + + it("add locale", () => { + sidebarPage.goToRealmSettings(); + + cy.findByTestId("rs-localization-tab").click(); + + addBundle(); + + masthead.checkNotificationMessage( + "Success! The localization text has been created." + ); + }); + + it("Realm header settings", () => { + sidebarPage.goToRealmSettings(); + cy.get("#pf-tab-securityDefences-securityDefences").click(); + cy.findByTestId("headers-form-tab-save").should("be.disabled"); + cy.get("#xFrameOptions").clear().type("DENY"); + cy.findByTestId("headers-form-tab-save").should("be.enabled").click(); + + masthead.checkNotificationMessage("Realm successfully updated"); + }); + + it("Brute force detection", () => { + sidebarPage.goToRealmSettings(); + cy.get("#pf-tab-securityDefences-securityDefences").click(); + cy.get("#pf-tab-20-bruteForce").click(); + + cy.findByTestId("brute-force-tab-save").should("be.disabled"); + + cy.get("#bruteForceProtected").click({ force: true }); + cy.findByTestId("waitIncrementSeconds").type("1"); + cy.findByTestId("maxFailureWaitSeconds").type("1"); + cy.findByTestId("maxDeltaTimeSeconds").type("1"); + cy.findByTestId("minimumQuickLoginWaitSeconds").type("1"); + + cy.findByTestId("brute-force-tab-save").should("be.enabled").click(); + masthead.checkNotificationMessage("Realm successfully updated"); + }); + + it("add session data", () => { + sidebarPage.goToRealmSettings(); + + cy.findByTestId("rs-sessions-tab").click(); + + realmSettingsPage.populateSessionsPage(); + realmSettingsPage.save("sessions-tab-save"); + + masthead.checkNotificationMessage("Realm successfully updated"); + }); + + it("check that sessions data was saved", () => { + sidebarPage.goToAuthentication(); + sidebarPage.goToRealmSettings(); + + cy.findByTestId("rs-sessions-tab").click(); + + cy.findByTestId(realmSettingsPage.ssoSessionIdleInput).should( + "have.value", + 1 + ); + cy.findByTestId(realmSettingsPage.ssoSessionMaxInput).should( + "have.value", + 2 + ); + cy.findByTestId(realmSettingsPage.ssoSessionIdleRememberMeInput).should( + "have.value", + 3 + ); + cy.findByTestId(realmSettingsPage.ssoSessionMaxRememberMeInput).should( + "have.value", + 4 + ); + + cy.findByTestId(realmSettingsPage.clientSessionIdleInput).should( + "have.value", + 5 + ); + cy.findByTestId(realmSettingsPage.clientSessionMaxInput).should( + "have.value", + 6 + ); + + cy.findByTestId(realmSettingsPage.offlineSessionIdleInput).should( + "have.value", + 7 + ); + cy.findByTestId(realmSettingsPage.offlineSessionMaxSwitch).should( + "have.value", + "on" + ); + + cy.findByTestId(realmSettingsPage.loginTimeoutInput).should( + "have.value", + 9 + ); + cy.findByTestId(realmSettingsPage.loginActionTimeoutInput).should( + "have.value", + 10 + ); + }); + + it("add token data", () => { + sidebarPage.goToRealmSettings(); + + cy.findByTestId("rs-tokens-tab").click(); + + realmSettingsPage.populateTokensPage(); + realmSettingsPage.save("tokens-tab-save"); + + masthead.checkNotificationMessage("Realm successfully updated"); + }); + + it("check that token data was saved", () => { + sidebarPage.goToRealmSettings(); + + cy.findByTestId("rs-tokens-tab").click(); + + cy.findByTestId(realmSettingsPage.accessTokenLifespanInput).should( + "have.value", + 1 + ); + cy.findByTestId( + realmSettingsPage.accessTokenLifespanImplicitInput + ).should("have.value", 2); + cy.findByTestId(realmSettingsPage.clientLoginTimeoutInput).should( + "have.value", + 3 + ); + cy.findByTestId( + realmSettingsPage.userInitiatedActionLifespanInput + ).should("have.value", 4); + + cy.findByTestId(realmSettingsPage.defaultAdminInitatedInput).should( + "have.value", + 5 + ); + cy.findByTestId(realmSettingsPage.emailVerificationInput).should( + "have.value", + 6 + ); + + cy.findByTestId(realmSettingsPage.idpEmailVerificationInput).should( + "have.value", + 7 + ); + cy.findByTestId(realmSettingsPage.forgotPasswordInput).should( + "have.value", + 8 + ); + + cy.findByTestId(realmSettingsPage.executeActionsInput).should( + "have.value", + 9 + ); + }); }); - it("add locale", () => { - sidebarPage.goToRealmSettings(); + describe("Realm settings client profiles tab tests", () => { + beforeEach(() => { + keycloakBefore(); + loginPage.logIn(); + sidebarPage.goToRealmSettings(); + cy.findByTestId("rs-clientPolicies-tab").click(); + cy.findByTestId("rs-profiles-clientPolicies-tab").click(); + }); - cy.findByTestId("rs-localization-tab").click(); + it("Go to client policies profiles tab", function () { + realmSettingsPage.shouldDisplayProfilesTab(); + }); - addBundle(); + it("Check new client form is displaying", function () { + realmSettingsPage.shouldDisplayNewClientProfileForm(); + }); - masthead.checkNotificationMessage( - "Success! The localization text has been created." - ); - }); + it("Complete new client form and cancel", function () { + realmSettingsPage.shouldCompleteAndCancelCreateNewClientProfile(); + }); - it("Realm header settings", () => { - sidebarPage.goToRealmSettings(); - cy.get("#pf-tab-securityDefences-securityDefences").click(); - cy.findByTestId("headers-form-tab-save").should("be.disabled"); - cy.get("#xFrameOptions").clear().type("DENY"); - cy.findByTestId("headers-form-tab-save").should("be.enabled").click(); + it("Complete new client form and submit", function () { + realmSettingsPage.shouldCompleteAndCreateNewClientProfile(); + }); - masthead.checkNotificationMessage("Realm successfully updated"); - }); + it("Check cancelling the client profile deletion", function () { + realmSettingsPage.shouldDisplayDeleteClientProfileDialog(); + }); - it("Brute force detection", () => { - sidebarPage.goToRealmSettings(); - cy.get("#pf-tab-securityDefences-securityDefences").click(); - cy.get("#pf-tab-20-bruteForce").click(); - - cy.findByTestId("brute-force-tab-save").should("be.disabled"); - - cy.get("#bruteForceProtected").click({ force: true }); - cy.findByTestId("waitIncrementSeconds").type("1"); - cy.findByTestId("maxFailureWaitSeconds").type("1"); - cy.findByTestId("maxDeltaTimeSeconds").type("1"); - cy.findByTestId("minimumQuickLoginWaitSeconds").type("1"); - - cy.findByTestId("brute-force-tab-save").should("be.enabled").click(); - masthead.checkNotificationMessage("Realm successfully updated"); - }); - - it("add session data", () => { - sidebarPage.goToRealmSettings(); - - cy.findByTestId("rs-sessions-tab").click(); - - realmSettingsPage.populateSessionsPage(); - realmSettingsPage.save("sessions-tab-save"); - - masthead.checkNotificationMessage("Realm successfully updated"); - }); - - it("check that sessions data was saved", () => { - sidebarPage.goToAuthentication(); - sidebarPage.goToRealmSettings(); - - cy.findByTestId("rs-sessions-tab").click(); - - cy.findByTestId(realmSettingsPage.ssoSessionIdleInput).should( - "have.value", - 1 - ); - cy.findByTestId(realmSettingsPage.ssoSessionMaxInput).should( - "have.value", - 2 - ); - cy.findByTestId(realmSettingsPage.ssoSessionIdleRememberMeInput).should( - "have.value", - 3 - ); - cy.findByTestId(realmSettingsPage.ssoSessionMaxRememberMeInput).should( - "have.value", - 4 - ); - - cy.findByTestId(realmSettingsPage.clientSessionIdleInput).should( - "have.value", - 5 - ); - cy.findByTestId(realmSettingsPage.clientSessionMaxInput).should( - "have.value", - 6 - ); - - cy.findByTestId(realmSettingsPage.offlineSessionIdleInput).should( - "have.value", - 7 - ); - cy.findByTestId(realmSettingsPage.offlineSessionMaxSwitch).should( - "have.value", - "on" - ); - - cy.findByTestId(realmSettingsPage.loginTimeoutInput).should( - "have.value", - 9 - ); - cy.findByTestId(realmSettingsPage.loginActionTimeoutInput).should( - "have.value", - 10 - ); - }); - - it("add token data", () => { - sidebarPage.goToRealmSettings(); - - cy.findByTestId("rs-tokens-tab").click(); - - realmSettingsPage.populateTokensPage(); - realmSettingsPage.save("tokens-tab-save"); - - masthead.checkNotificationMessage("Realm successfully updated"); - }); - - it("check that token data was saved", () => { - sidebarPage.goToRealmSettings(); - - cy.findByTestId("rs-tokens-tab").click(); - - cy.findByTestId(realmSettingsPage.accessTokenLifespanInput).should( - "have.value", - 1 - ); - cy.findByTestId(realmSettingsPage.accessTokenLifespanImplicitInput).should( - "have.value", - 2 - ); - cy.findByTestId(realmSettingsPage.clientLoginTimeoutInput).should( - "have.value", - 3 - ); - cy.findByTestId(realmSettingsPage.userInitiatedActionLifespanInput).should( - "have.value", - 4 - ); - - cy.findByTestId(realmSettingsPage.defaultAdminInitatedInput).should( - "have.value", - 5 - ); - cy.findByTestId(realmSettingsPage.emailVerificationInput).should( - "have.value", - 6 - ); - - cy.findByTestId(realmSettingsPage.idpEmailVerificationInput).should( - "have.value", - 7 - ); - cy.findByTestId(realmSettingsPage.forgotPasswordInput).should( - "have.value", - 8 - ); - - cy.findByTestId(realmSettingsPage.executeActionsInput).should( - "have.value", - 9 - ); + it("Check deleting the client profile", function () { + realmSettingsPage.shouldDeleteClientProfileDialog(); + }); }); }); diff --git a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts index 3be98e7326..af552a5716 100644 --- a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts +++ b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts @@ -143,6 +143,20 @@ export default class RealmSettingsPage { executeActionsSelectMenu = "#kc-execute-actions-select-menu"; executeActionsSelectMenuList = "#kc-execute-actions-select-menu > div > ul"; + private createProfileBtn = "createProfile"; + private formViewSelect = "formView-radioBtn"; + private jsonEditorSelect = "formView-radioBtn"; + private newClientProfileNameInput = "client-profile-name"; + private newClientProfileDescriptionInput = "client-profile-description"; + private saveNewClientProfileBtn = "saveCreateProfile"; + private cancelNewClientProfile = "cancelCreateProfile"; + private alertMessage = ".pf-c-alert__title"; + private moreDrpDwn = ".pf-c-dropdown__toggle.pf-m-plain"; + private moreDrpDwnItems = ".pf-c-dropdown__menu-item"; + private deleteDialogTitle = ".pf-c-modal-box__title-text"; + private deleteDialogBodyText = ".pf-c-modal-box__body"; + private deleteDialogCancelBtn = ".pf-c-button.pf-m-link"; + selectLoginThemeType(themeType: string) { cy.get(this.selectLoginTheme).click(); cy.get(this.loginThemeList).contains(themeType).click(); @@ -450,4 +464,62 @@ export default class RealmSettingsPage { cy.findByTestId("addEventTypeConfirm").click(); return this; } + + shouldDisplayProfilesTab() { + cy.findByTestId(this.createProfileBtn).should("exist"); + cy.findByTestId(this.formViewSelect).should("exist"); + cy.findByTestId(this.jsonEditorSelect).should("exist"); + cy.get("table").should("be.visible").contains("td", "Global"); + } + + shouldDisplayNewClientProfileForm() { + cy.findByTestId(this.createProfileBtn).click(); + cy.findByTestId(this.newClientProfileNameInput).should("exist"); + cy.findByTestId(this.newClientProfileDescriptionInput).should("exist"); + cy.findByTestId(this.saveNewClientProfileBtn).should("exist"); + cy.findByTestId(this.cancelNewClientProfile).should("exist"); + } + + shouldCompleteAndCancelCreateNewClientProfile() { + cy.findByTestId(this.createProfileBtn).click(); + cy.findByTestId(this.newClientProfileNameInput).type("Test"); + cy.findByTestId(this.newClientProfileDescriptionInput).type( + "Test Description" + ); + cy.findByTestId(this.cancelNewClientProfile).click(); + cy.get("table").should("not.have.text", "Test"); + } + + shouldCompleteAndCreateNewClientProfile() { + cy.findByTestId(this.createProfileBtn).click(); + cy.findByTestId(this.newClientProfileNameInput).type("Test"); + cy.findByTestId(this.newClientProfileDescriptionInput).type( + "Test Description" + ); + cy.findByTestId(this.saveNewClientProfileBtn).click(); + cy.get(this.alertMessage).should( + "be.visible", + "New client profile created" + ); + } + + shouldDisplayDeleteClientProfileDialog() { + cy.get(this.moreDrpDwn).last().click(); + cy.get(this.moreDrpDwnItems).click(); + cy.get(this.deleteDialogTitle).contains("Delete profile?"); + cy.get(this.deleteDialogBodyText).contains( + "This action will permanently delete the profile custom-profile. This cannot be undone." + ); + cy.findByTestId("modalConfirm").contains("Delete"); + cy.get(this.deleteDialogCancelBtn).contains("Cancel").click(); + cy.get("table").should("not.have.text", "Test"); + } + + shouldDeleteClientProfileDialog() { + cy.get(this.moreDrpDwn).last().click(); + cy.get(this.moreDrpDwnItems).click(); + cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.get("table").should("not.have.text", "Test"); + cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); + } } diff --git a/src/realm-settings/NewClientProfileForm.tsx b/src/realm-settings/NewClientProfileForm.tsx index b944f46fa8..5d2b7e63aa 100644 --- a/src/realm-settings/NewClientProfileForm.tsx +++ b/src/realm-settings/NewClientProfileForm.tsx @@ -1,11 +1,15 @@ -import React from "react"; +import React, { useState } from "react"; import { ActionGroup, + AlertVariant, Button, + Divider, FormGroup, PageSection, + Text, TextArea, TextInput, + TextVariants, ValidatedOptions, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; @@ -14,15 +18,69 @@ import { FormAccess } from "../components/form-access/FormAccess"; import { ViewHeader } from "../components/view-header/ViewHeader"; import { Link } from "react-router-dom"; import { useRealm } from "../context/realm-context/RealmContext"; +import { useAlerts } from "../components/alert/Alerts"; +import { useAdminClient, useFetch } from "../context/auth/AdminClient"; +import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation"; +import { HelpItem } from "../components/help-enabler/HelpItem"; +import { PlusCircleIcon } from "@patternfly/react-icons"; +import "./RealmSettingsSection.css"; + +type NewClientProfileForm = Required; + +const defaultValues: NewClientProfileForm = { + name: "", + executors: [], + description: "", +}; export const NewClientProfileForm = () => { const { t } = useTranslation("realm-settings"); - const { register, errors } = useForm(); + const { getValues, register, errors } = useForm({ + defaultValues, + }); const { realm } = useRealm(); + const { addAlert, addError } = useAlerts(); + const adminClient = useAdminClient(); + const [globalProfiles, setGlobalProfiles] = useState< + ClientProfileRepresentation[] + >([]); + const [profiles, setProfiles] = useState([]); + const [showAddExecutorsForm, setShowAddExecutorsForm] = useState(false); - function save() { - //TODO - } + useFetch( + () => + adminClient.clientPolicies.listProfiles({ includeGlobalProfiles: true }), + (profiles) => { + setGlobalProfiles(profiles.globalProfiles ?? []); + setProfiles(profiles.profiles ?? []); + }, + [] + ); + + const save = async () => { + const form = getValues(); + + const createdProfile = { + ...form, + executors: [], + }; + + const allProfiles = profiles.concat(createdProfile); + + try { + await adminClient.clientPolicies.createProfiles({ + profiles: allProfiles, + globalProfiles: globalProfiles, + }); + addAlert( + t("realm-settings:createClientProfileSuccess"), + AlertVariant.success + ); + setShowAddExecutorsForm(true); + } catch (error) { + addError("realm-settings:createClientProfileError", error); + } + }; return ( <> @@ -32,39 +90,36 @@ export const NewClientProfileForm = () => { - +