From 0dd9cacdd3c39e00beda74a8191efb39b55668b2 Mon Sep 17 00:00:00 2001 From: mfrances17 <39063664+mfrances17@users.noreply.github.com> Date: Thu, 14 Apr 2022 07:07:28 -0400 Subject: [PATCH] Adds tests for LDAP provider advanced and cache settings (#2338) * adds ldap advanced and cache tests * fixes issues from merges * dont force close notification * error msg differs --- .../integration/user_fed_ldap_test.spec.ts | 127 +++++++++++++++--- .../manage/providers/ProviderPage.ts | 5 + .../ldap/LdapSettingsAdvanced.tsx | 3 + 3 files changed, 117 insertions(+), 18 deletions(-) diff --git a/cypress/integration/user_fed_ldap_test.spec.ts b/cypress/integration/user_fed_ldap_test.spec.ts index 854f59db34..7d46da6308 100644 --- a/cypress/integration/user_fed_ldap_test.spec.ts +++ b/cypress/integration/user_fed_ldap_test.spec.ts @@ -69,13 +69,17 @@ const secondUserLdapFilter = "(second-filter)"; const secondReadTimeout = "5000"; const defaultPolicy = "DEFAULT"; -const newPolicy = "EVICT_WEEKLY"; +const weeklyPolicy = "EVICT_WEEKLY"; +const dailyPolicy = "EVICT_DAILY"; +const lifespanPolicy = "MAX_LIFESPAN"; +const noCachePolicy = "NO_CACHE"; const defaultLdapDay = "Sunday"; const defaultLdapHour = "00"; const defaultLdapMinute = "00"; const newLdapDay = "Wednesday"; const newLdapHour = "15"; const newLdapMinute = "55"; +const maxLifespan = 5; const addProviderMenu = "Add new provider"; const createdSuccessMessage = "User federation provider successfully created"; @@ -83,12 +87,13 @@ const savedSuccessMessage = "User federation provider successfully saved"; const deletedSuccessMessage = "The user federation provider has been deleted."; const deleteModalTitle = "Delete user federation provider?"; const disableModalTitle = "Disable user federation provider?"; +const nonWritableFailMessage = "User federation provider could not be saved:"; const ldapTestSuccessMsg = "Successfully connected to LDAP"; const ldapTestFailMsg = "Error when trying to connect to LDAP. See server.log for details. LDAP test error"; -describe("User Fed LDAP tests", () => { +describe("User Federation LDAP tests", () => { beforeEach(() => { keycloakBefore(); loginPage.logIn(); @@ -96,7 +101,7 @@ describe("User Fed LDAP tests", () => { cy.intercept("GET", "/admin/realms/master").as("getProvider"); }); - it("Create Ldap provider from empty state", () => { + it("Should create LDAP provider from empty state", () => { // if tests don't start at empty state, e.g. user has providers configured locally, // create a new card from the card view instead cy.get("body").then(($body) => { @@ -131,21 +136,79 @@ describe("User Fed LDAP tests", () => { sidebarPage.goToUserFederation(); }); - it("Update an existing LDAP provider and save", () => { + it("Should fail updating advanced settings", () => { providersPage.clickExistingCard(firstLdapName); - providersPage.selectCacheType(newPolicy); - - providersPage.changeCacheTime("day", newLdapDay); - providersPage.changeCacheTime("hour", newLdapHour); - providersPage.changeCacheTime("minute", newLdapMinute); + providersPage.toggleSwitch(providersPage.ldapv3PwSwitch); + providersPage.toggleSwitch(providersPage.validatePwPolicySwitch); + providersPage.toggleSwitch(providersPage.trustEmailSwitch); + providersPage.save(provider); + masthead.checkNotificationMessage(nonWritableFailMessage); + sidebarPage.goToUserFederation(); + }); + it("Should update advanced settings", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.toggleSwitch(providersPage.ldapv3PwSwitch); + providersPage.toggleSwitch(providersPage.validatePwPolicySwitch); + providersPage.toggleSwitch(providersPage.trustEmailSwitch); + providersPage.fillLdapSearchingData( + editModeWritable, + secondUsersDn, + secondUserLdapAtt, + secondRdnLdapAtt, + secondUuidLdapAtt, + secondUserObjClasses + ); providersPage.save(provider); masthead.checkNotificationMessage(savedSuccessMessage); + sidebarPage.goToUserFederation(); + providersPage.clickExistingCard(firstLdapName); + providersPage.verifyToggle(providersPage.ldapv3PwSwitch, "on"); + providersPage.verifyToggle(providersPage.validatePwPolicySwitch, "on"); + providersPage.verifyToggle(providersPage.trustEmailSwitch, "on"); + }); + it("Should set cache policy to evict_daily", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.selectCacheType(dailyPolicy); + providersPage.changeCacheTime("hour", newLdapHour); + providersPage.changeCacheTime("minute", newLdapMinute); + providersPage.save(provider); + + masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); providersPage.clickExistingCard(firstLdapName); - expect(cy.contains(newPolicy).should("exist")); + expect(cy.contains(dailyPolicy).should("exist")); + expect(cy.contains(defaultPolicy).should("not.exist")); + }); + + it("Should set cache policy to default", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.selectCacheType(defaultPolicy); + providersPage.save(provider); + + masthead.checkNotificationMessage(savedSuccessMessage); + sidebarPage.goToUserFederation(); + providersPage.clickExistingCard(firstLdapName); + + expect(cy.contains(defaultPolicy).should("exist")); + expect(cy.contains(dailyPolicy).should("not.exist")); + }); + + it("Should set cache policy to evict_weekly", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.selectCacheType(weeklyPolicy); + providersPage.changeCacheTime("day", newLdapDay); + providersPage.changeCacheTime("hour", newLdapHour); + providersPage.changeCacheTime("minute", newLdapMinute); + providersPage.save(provider); + + masthead.checkNotificationMessage(savedSuccessMessage); + sidebarPage.goToUserFederation(); + providersPage.clickExistingCard(firstLdapName); + + expect(cy.contains(weeklyPolicy).should("exist")); expect(cy.contains(defaultPolicy).should("not.exist")); }); @@ -365,6 +428,7 @@ describe("User Fed LDAP tests", () => { providersPage.fillSelect(providersPage.ldapEditModeInput, editModeUnsynced); providersPage.toggleSwitch(providersPage.importUsers); + providersPage.toggleSwitch(providersPage.validatePwPolicySwitch); providersPage.save(provider); masthead.checkNotificationMessage(savedSuccessMessage); @@ -392,9 +456,9 @@ describe("User Fed LDAP tests", () => { sidebarPage.goToUserFederation(); }); - it("Change existing LDAP provider and click button to cancel", () => { - providersPage.clickExistingCard(updatedLdapName); - providersPage.selectCacheType(newPolicy); + it("Should update existing LDAP provider and cancel", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.selectCacheType(weeklyPolicy); providersPage.changeCacheTime("day", defaultLdapDay); providersPage.changeCacheTime("hour", defaultLdapHour); @@ -403,13 +467,40 @@ describe("User Fed LDAP tests", () => { providersPage.cancel(provider); providersPage.clickExistingCard(updatedLdapName); - providersPage.selectCacheType(newPolicy); + providersPage.selectCacheType(weeklyPolicy); providersPage.verifyChangedHourInput(newLdapHour, defaultLdapHour); sidebarPage.goToUserFederation(); }); + it("Should set cache policy to max_lifespan", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.selectCacheType(lifespanPolicy); + providersPage.fillMaxLifespanData(maxLifespan); + providersPage.save(provider); + + masthead.checkNotificationMessage(savedSuccessMessage); + sidebarPage.goToUserFederation(); + providersPage.clickExistingCard(firstLdapName); + + expect(cy.contains(lifespanPolicy).should("exist")); + expect(cy.contains(weeklyPolicy).should("not.exist")); + }); + + it("Should set cache policy to no_cache", () => { + providersPage.clickExistingCard(firstLdapName); + providersPage.selectCacheType(noCachePolicy); + providersPage.save(provider); + + masthead.checkNotificationMessage(savedSuccessMessage); + sidebarPage.goToUserFederation(); + providersPage.clickExistingCard(firstLdapName); + + expect(cy.contains(noCachePolicy).should("exist")); + expect(cy.contains(lifespanPolicy).should("not.exist")); + }); + it("Should disable an existing LDAP provider", () => { providersPage.clickExistingCard(firstLdapName); cy.wait("@getProvider"); @@ -429,7 +520,7 @@ describe("User Fed LDAP tests", () => { expect(cy.contains("Enabled").should("exist")); }); - it("Create new LDAP provider using the New Provider dropdown", () => { + it("Should create new LDAP provider using New Provider dropdown", () => { providersPage.clickMenuCommand(addProviderMenu, allCapProvider); providersPage.fillLdapGeneralData(secondLdapName, secondLdapVendor); providersPage.fillLdapConnectionData( @@ -453,14 +544,14 @@ describe("User Fed LDAP tests", () => { sidebarPage.goToUserFederation(); }); - it("Delete an LDAP provider from card view using the card's menu", () => { + it("Should delete LDAP provider from card view using card menu", () => { providersPage.deleteCardFromCard(secondLdapName); modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); masthead.checkNotificationMessage(deletedSuccessMessage); }); - it("Delete an LDAP provider using the Settings view's Action menu", () => { - providersPage.deleteCardFromMenu(updatedLdapName); + it("Should delete LDAP provider using Settings view Action menu", () => { + providersPage.deleteCardFromMenu(firstLdapName); modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); masthead.checkNotificationMessage(deletedSuccessMessage); }); diff --git a/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts index 3ddf1e3b57..f6fbdc6959 100644 --- a/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts +++ b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts @@ -111,6 +111,11 @@ export default class ProviderPage { enableStartTls = "enable-start-tls"; connectionPooling = "connection-pooling"; + // LDAP advanced settings switch input values + ldapv3PwSwitch = "ldapv3-password"; + validatePwPolicySwitch = "password-policy"; + trustEmailSwitch = "trust-email"; + changeCacheTime(unit: string, time: string) { switch (unit) { case "day": diff --git a/src/user-federation/ldap/LdapSettingsAdvanced.tsx b/src/user-federation/ldap/LdapSettingsAdvanced.tsx index 91205af355..40066b82d7 100644 --- a/src/user-federation/ldap/LdapSettingsAdvanced.tsx +++ b/src/user-federation/ldap/LdapSettingsAdvanced.tsx @@ -49,6 +49,7 @@ export const LdapSettingsAdvanced = ({ render={({ onChange, value }) => ( onChange([`${value}`])} isChecked={value[0] === "true"} @@ -77,6 +78,7 @@ export const LdapSettingsAdvanced = ({ render={({ onChange, value }) => ( onChange([`${value}`])} isChecked={value[0] === "true"} @@ -105,6 +107,7 @@ export const LdapSettingsAdvanced = ({ render={({ onChange, value }) => ( onChange([`${value}`])} isChecked={value[0] === "true"}