From 4fb2f73b2c7acf48d8d4044f09f958bc9fec1cb3 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 22 Mar 2024 14:07:25 +0100 Subject: [PATCH] migrated to use ui-shared (#27849) * migrated to use ui-shared Signed-off-by: Erik Jan de Wit * fixed tests Signed-off-by: Erik Jan de Wit * fixed tests Signed-off-by: Erik Jan de Wit --------- Signed-off-by: Erik Jan de Wit --- .../e2e/realm_settings_events_test.spec.ts | 6 +- .../e2e/realm_settings_tabs_test.spec.ts | 39 ++++-- .../security-defences/BruteForceDetection.tsx | 123 ++++-------------- .../security-defences/HelpLinkTextInput.tsx | 28 ++-- .../realm-settings/security-defences/Time.tsx | 42 ++---- js/libs/ui-shared/src/controls/FormLabel.tsx | 4 +- .../ui-shared/src/controls/TextControl.tsx | 3 +- 7 files changed, 77 insertions(+), 168 deletions(-) diff --git a/js/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts b/js/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts index d81bea5ec9..0fbad917c8 100644 --- a/js/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts +++ b/js/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts @@ -237,8 +237,8 @@ describe("Realm settings events tab tests", () => { it("Realm header settings", () => { sidebarPage.goToRealmSettings(); cy.findByTestId("rs-security-defenses-tab").click(); - cy.findByTestId("headers-form-tab-save").should("be.disabled"); - cy.get("#xFrameOptions").clear().type("DENY"); + cy.findByTestId("browserSecurityHeaders.xFrameOptions").clear(); + cy.findByTestId("browserSecurityHeaders.xFrameOptions").type("DENY"); cy.findByTestId("headers-form-tab-save").should("be.enabled").click(); masthead.checkNotificationMessage("Realm successfully updated"); @@ -249,8 +249,6 @@ describe("Realm settings events tab tests", () => { cy.findAllByTestId("rs-security-defenses-tab").click(); cy.get("#pf-tab-20-bruteForce").click(); - cy.findByTestId("brute-force-tab-save").should("be.disabled"); - cy.get("#kc-brute-force-mode").click(); cy.findByTestId("select-brute-force-mode") .contains("Lockout temporarily") diff --git a/js/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts b/js/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts index 2b7a289303..98709532b2 100644 --- a/js/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts +++ b/js/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts @@ -136,7 +136,8 @@ describe("Realm settings tabs tests", () => { it("Realm header settings- update single input", () => { sidebarPage.goToRealmSettings(); realmSettingsPage.goToSecurityDefensesTab(); - cy.get("#xFrameOptions").clear().type("DENY"); + cy.findByTestId("browserSecurityHeaders.xFrameOptions").clear(); + cy.findByTestId("browserSecurityHeaders.xFrameOptions").type("DENY"); realmSettingsPage.saveSecurityDefensesHeaders(); masthead.checkNotificationMessage("Realm successfully updated"); }); @@ -144,14 +145,34 @@ describe("Realm settings tabs tests", () => { it("Realm header settings- update all inputs", () => { sidebarPage.goToRealmSettings(); realmSettingsPage.goToSecurityDefensesTab(); - cy.get("#xFrameOptions").clear().type("SAMEORIGIN"); - cy.get("#contentSecurityPolicy").clear().type("default-src 'self'"); - cy.get("#strictTransportSecurity").clear().type("max-age=31536000"); - cy.get("#xContentTypeOptions").clear().type("nosniff"); - cy.get("#xRobotsTag").clear().type("none"); - cy.get("#xXSSProtection").clear().type("1; mode=block"); - cy.get("#strictTransportSecurity").clear().type("max-age=31537000"); - cy.get("#referrerPolicy").clear().type("referrer"); + cy.findByTestId("browserSecurityHeaders.xFrameOptions").clear(); + cy.findByTestId("browserSecurityHeaders.xFrameOptions").type( + "SAMEORIGIN", + ); + cy.findByTestId("browserSecurityHeaders.contentSecurityPolicy").clear(); + cy.findByTestId("browserSecurityHeaders.contentSecurityPolicy").type( + "default-src 'self'", + ); + cy.findByTestId("browserSecurityHeaders.strictTransportSecurity").clear(); + cy.findByTestId("browserSecurityHeaders.strictTransportSecurity").type( + "max-age=31536000", + ); + cy.findByTestId("browserSecurityHeaders.xContentTypeOptions").clear(); + cy.findByTestId("browserSecurityHeaders.xContentTypeOptions").type( + "nosniff", + ); + cy.findByTestId("browserSecurityHeaders.xRobotsTag").clear(); + cy.findByTestId("browserSecurityHeaders.xRobotsTag").type("none"); + cy.findByTestId("browserSecurityHeaders.xXSSProtection").clear(); + cy.findByTestId("browserSecurityHeaders.xXSSProtection").type( + "1; mode=block", + ); + cy.findByTestId("browserSecurityHeaders.strictTransportSecurity").clear(); + cy.findByTestId("browserSecurityHeaders.strictTransportSecurity").type( + "max-age=31537000", + ); + cy.findByTestId("browserSecurityHeaders.referrerPolicy").clear(); + cy.findByTestId("browserSecurityHeaders.referrerPolicy").type("referrer"); realmSettingsPage.saveSecurityDefensesHeaders(); masthead.checkNotificationMessage("Realm successfully updated"); }); diff --git a/js/apps/admin-ui/src/realm-settings/security-defences/BruteForceDetection.tsx b/js/apps/admin-ui/src/realm-settings/security-defences/BruteForceDetection.tsx index da76a1d0ac..b480d89649 100644 --- a/js/apps/admin-ui/src/realm-settings/security-defences/BruteForceDetection.tsx +++ b/js/apps/admin-ui/src/realm-settings/security-defences/BruteForceDetection.tsx @@ -3,17 +3,15 @@ import { ActionGroup, Button, FormGroup, - NumberInput, Select, SelectOption, SelectVariant, } from "@patternfly/react-core"; import { useEffect, useState } from "react"; -import { Controller, FormProvider, useForm } from "react-hook-form"; +import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; - +import { HelpItem, NumberControl } from "ui-shared"; import { FormAccess } from "../../components/form/FormAccess"; -import { HelpItem } from "ui-shared"; import { convertToFormValues } from "../../util"; import { Time } from "./Time"; @@ -31,7 +29,6 @@ export const BruteForceDetection = ({ const { setValue, handleSubmit, - control, formState: { isDirty }, } = form; @@ -131,74 +128,26 @@ export const BruteForceDetection = ({ {bruteForceMode !== BruteForceMode.Disabled && ( <> - - } - fieldId="failureFactor" - > - ( - field.onChange(field.value + 1)} - onMinus={() => field.onChange(field.value - 1)} - onChange={(event) => - field.onChange( - Number((event.target as HTMLInputElement).value), - ) - } - /> - )} - /> - - + labelIcon={t("failureFactorHelp")} + controller={{ + defaultValue: 0, + rules: { required: t("required") }, + }} + /> {bruteForceMode === BruteForceMode.PermanentAfterTemporaryLockout && ( - - } - fieldId="maxTemporaryLockouts" - hasNoPaddingTop - > - ( - field.onChange(field.value + 1)} - onMinus={() => field.onChange(field.value - 1)} - onChange={(event) => - field.onChange( - Number((event.target as HTMLInputElement).value), - ) - } - aria-label={t("maxTemporaryLockouts")} - /> - )} - /> - + labelIcon={t("maxTemporaryLockoutsHelp")} + controller={{ + defaultValue: 0, + }} + /> )} - {(bruteForceMode === BruteForceMode.TemporaryLockout || bruteForceMode === BruteForceMode.PermanentAfterTemporaryLockout) && ( @@ -208,38 +157,14 @@ export const BruteForceDetection = ({