Port client login settings to new form controls (#27414)

Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Jon Koops 2024-03-05 18:02:07 +01:00 committed by GitHub
parent 4ef38a783a
commit 96841f8d5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 50 additions and 129 deletions

View file

@ -167,18 +167,18 @@ describe("Clients SAML tests", () => {
const homeUrlError = const homeUrlError =
"Client could not be updated: Base URL is not a valid URL"; "Client could not be updated: Base URL is not a valid URL";
cy.get("#kc-root-url").type("Invalid URL"); cy.findByTestId("rootUrl").type("Invalid URL");
settingsTab.clickSaveBtn(); settingsTab.clickSaveBtn();
masthead.checkNotificationMessage(rootUrlError); masthead.checkNotificationMessage(rootUrlError);
cy.get("#kc-root-url").clear(); cy.findByTestId("rootUrl").clear();
cy.get("#kc-home-url").type("Invalid URL"); cy.findByTestId("baseUrl").type("Invalid URL");
settingsTab.clickSaveBtn(); settingsTab.clickSaveBtn();
masthead.checkNotificationMessage(homeUrlError); masthead.checkNotificationMessage(homeUrlError);
cy.get("#kc-home-url").clear(); cy.findByTestId("baseUrl").clear();
cy.get("#kc-root-url").type(validUrl); cy.findByTestId("rootUrl").type(validUrl);
cy.get("#kc-home-url").type(validUrl); cy.findByTestId("baseUrl").type(validUrl);
settingsTab.clickSaveBtn(); settingsTab.clickSaveBtn();
masthead.checkNotificationMessage("Client successfully updated"); masthead.checkNotificationMessage("Client successfully updated");

View file

@ -25,11 +25,11 @@ export default class CreateClientPage extends CommonPage {
#deviceAuthGrantChkBx = "#kc-oauth-device-authorization-grant"; #deviceAuthGrantChkBx = "#kc-oauth-device-authorization-grant";
#serviceAccountRolesChkBx = "#kc-flow-service-account"; #serviceAccountRolesChkBx = "#kc-flow-service-account";
#rootUrlInput = "#kc-root-url"; #rootUrlInput = "rootUrl";
#homeUrlInput = "#kc-home-url"; #homeUrlInput = "baseUrl";
#firstValidRedirectUrlInput = "redirectUris0"; #firstValidRedirectUrlInput = "redirectUris0";
#firstWebOriginsInput = "webOrigins0"; #firstWebOriginsInput = "webOrigins0";
#adminUrlInput = "#kc-admin-url"; #adminUrlInput = "adminUrl";
#loginThemeDrpDwn = "#loginTheme"; #loginThemeDrpDwn = "#loginTheme";
#loginThemeList = 'ul[aria-label="Login theme"]'; #loginThemeList = 'ul[aria-label="Login theme"]';
@ -227,12 +227,12 @@ export default class CreateClientPage extends CommonPage {
} }
checkAccessSettingsElements() { checkAccessSettingsElements() {
cy.get(this.#adminUrlInput).scrollIntoView(); cy.findByTestId(this.#adminUrlInput).scrollIntoView();
cy.get(this.#rootUrlInput).should("not.be.disabled"); cy.findByTestId(this.#rootUrlInput).should("not.be.disabled");
cy.get(this.#homeUrlInput).should("not.be.disabled"); cy.findByTestId(this.#homeUrlInput).should("not.be.disabled");
cy.findByTestId(this.#firstValidRedirectUrlInput).should("not.be.disabled"); cy.findByTestId(this.#firstValidRedirectUrlInput).should("not.be.disabled");
cy.findByTestId(this.#firstWebOriginsInput).should("not.be.disabled"); cy.findByTestId(this.#firstWebOriginsInput).should("not.be.disabled");
cy.get(this.#adminUrlInput).should("not.be.disabled"); cy.findByTestId(this.#adminUrlInput).should("not.be.disabled");
return this; return this;
} }

View file

@ -35,9 +35,9 @@ export default class SettingsTab extends PageObject {
#redirectUris = "redirectUris"; #redirectUris = "redirectUris";
#idpInitiatedSsoUrlName = "idpInitiatedSsoUrlName"; #idpInitiatedSsoUrlName = "attributes.saml_idp_initiated_sso_url_name";
#idpInitiatedSsoRelayState = "idpInitiatedSsoRelayState"; #idpInitiatedSsoRelayState = "attributes.saml_idp_initiated_sso_relay_state";
#masterSamlProcessingUrl = "masterSamlProcessingUrl"; #masterSamlProcessingUrl = "adminUrl";
public clickSaveBtn() { public clickSaveBtn() {
cy.findByTestId(this.#saveBtn).click(); cy.findByTestId(this.#saveBtn).click();

View file

@ -1,11 +1,9 @@
import { FormGroup } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form"; import { useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { TextControl } from "ui-shared";
import { HelpItem } from "ui-shared";
import { FixedButtonsGroup } from "../../components/form/FixedButtonGroup"; import { FixedButtonsGroup } from "../../components/form/FixedButtonGroup";
import { FormAccess } from "../../components/form/FormAccess"; import { FormAccess } from "../../components/form/FormAccess";
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
import { useAccess } from "../../context/access/Access"; import { useAccess } from "../../context/access/Access";
import { FormFields } from "../ClientDetails"; import { FormFields } from "../ClientDetails";
import type { ClientSettingsProps } from "../ClientSettings"; import type { ClientSettingsProps } from "../ClientSettings";
@ -17,7 +15,7 @@ export const AccessSettings = ({
reset, reset,
}: ClientSettingsProps) => { }: ClientSettingsProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { register, watch } = useFormContext<FormFields>(); const { watch } = useFormContext<FormFields>();
const { hasAccess } = useAccess(); const { hasAccess } = useAccess();
const isManager = hasAccess("manage-clients") || client.access?.configure; const isManager = hasAccess("manage-clients") || client.access?.configure;
@ -32,19 +30,12 @@ export const AccessSettings = ({
> >
{!client.bearerOnly && <LoginSettings protocol={protocol} />} {!client.bearerOnly && <LoginSettings protocol={protocol} />}
{protocol !== "saml" && ( {protocol !== "saml" && (
<FormGroup <TextControl
label={t("adminURL")}
fieldId="kc-admin-url"
labelIcon={
<HelpItem helpText={t("adminURLHelp")} fieldLabelId="adminURL" />
}
>
<KeycloakTextInput
id="kc-admin-url"
type="url" type="url"
{...register("adminUrl")} name="adminUrl"
label={t("adminURL")}
labelIcon={t("adminURLHelp")}
/> />
</FormGroup>
)} )}
{client.bearerOnly && ( {client.bearerOnly && (
<FixedButtonsGroup <FixedButtonsGroup

View file

@ -1,63 +1,38 @@
import { FormGroup } from "@patternfly/react-core"; import { FormGroup } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form"; import { useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { HelpItem, TextControl } from "ui-shared";
import { HelpItem } from "ui-shared";
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
import { MultiLineInput } from "../../components/multi-line-input/MultiLineInput"; import { MultiLineInput } from "../../components/multi-line-input/MultiLineInput";
import { useRealm } from "../../context/realm-context/RealmContext";
import environment from "../../environment";
import { convertAttributeNameToForm } from "../../util"; import { convertAttributeNameToForm } from "../../util";
import { FormFields } from "../ClientDetails"; import { FormFields } from "../ClientDetails";
type LoginSettingsProps = { type LoginSettingsProps = {
protocol?: string; protocol?: string;
isDisabled?: boolean;
}; };
export const LoginSettings = ({ export const LoginSettings = ({
protocol = "openid-connect", protocol = "openid-connect",
...rest
}: LoginSettingsProps) => { }: LoginSettingsProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { register, watch } = useFormContext<FormFields>(); const { watch } = useFormContext<FormFields>();
const { realm } = useRealm();
const idpInitiatedSsoUrlName: string = watch(
"attributes.saml_idp_initiated_sso_url_name",
);
const standardFlowEnabled = watch("standardFlowEnabled"); const standardFlowEnabled = watch("standardFlowEnabled");
return ( return (
<> <>
<FormGroup <TextControl
type="url"
name="rootUrl"
label={t("rootUrl")} label={t("rootUrl")}
fieldId="kc-root-url" labelIcon={t("rootURLHelp")}
labelIcon={
<HelpItem helpText={t("rootURLHelp")} fieldLabelId="rootUrl" />
}
>
<KeycloakTextInput
id="kc-root-url"
type="url"
{...register("rootUrl")}
{...rest}
/> />
</FormGroup> <TextControl
<FormGroup type="url"
name="baseUrl"
label={t("homeURL")} label={t("homeURL")}
fieldId="kc-home-url" labelIcon={t("homeURLHelp")}
labelIcon={
<HelpItem helpText={t("homeURLHelp")} fieldLabelId="homeURL" />
}
>
<KeycloakTextInput
id="kc-home-url"
type="url"
{...register("baseUrl")}
{...rest}
/> />
</FormGroup>
{standardFlowEnabled && ( {standardFlowEnabled && (
<> <>
<FormGroup <FormGroup
@ -75,7 +50,6 @@ export const LoginSettings = ({
name="redirectUris" name="redirectUris"
aria-label={t("validRedirectUri")} aria-label={t("validRedirectUri")}
addButtonLabel="addRedirectUri" addButtonLabel="addRedirectUri"
{...rest}
/> />
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -96,71 +70,28 @@ export const LoginSettings = ({
aria-label={t("validPostLogoutRedirectUri")} aria-label={t("validPostLogoutRedirectUri")}
addButtonLabel="addPostLogoutRedirectUri" addButtonLabel="addPostLogoutRedirectUri"
stringify stringify
{...rest}
/> />
</FormGroup>{" "} </FormGroup>
</> </>
)} )}
{protocol === "saml" && ( {protocol === "saml" && (
<> <>
<FormGroup <TextControl
name="attributes.saml_idp_initiated_sso_url_name"
label={t("idpInitiatedSsoUrlName")} label={t("idpInitiatedSsoUrlName")}
fieldId="idpInitiatedSsoUrlName" labelIcon={t("idpInitiatedSsoUrlNameHelp")}
labelIcon={
<HelpItem
helpText={t("idpInitiatedSsoUrlNameHelp")}
fieldLabelId="idpInitiatedSsoUrlName"
/> />
} <TextControl
helperText={ name="attributes.saml_idp_initiated_sso_relay_state"
idpInitiatedSsoUrlName !== "" &&
t("idpInitiatedSsoUrlNameHelp", {
url: `${environment.authServerUrl}/realms/${realm}/protocol/saml/clients/${idpInitiatedSsoUrlName}`,
})
}
>
<KeycloakTextInput
id="idpInitiatedSsoUrlName"
data-testid="idpInitiatedSsoUrlName"
{...register("attributes.saml_idp_initiated_sso_url_name")}
{...rest}
/>
</FormGroup>
<FormGroup
label={t("idpInitiatedSsoRelayState")} label={t("idpInitiatedSsoRelayState")}
fieldId="idpInitiatedSsoRelayState" labelIcon={t("idpInitiatedSsoRelayStateHelp")}
labelIcon={
<HelpItem
helpText={t("idpInitiatedSsoRelayStateHelp")}
fieldLabelId="idpInitiatedSsoRelayState"
/> />
} <TextControl
>
<KeycloakTextInput
id="idpInitiatedSsoRelayState"
data-testid="idpInitiatedSsoRelayState"
{...register("attributes.saml_idp_initiated_sso_relay_state")}
{...rest}
/>
</FormGroup>
<FormGroup
label={t("masterSamlProcessingUrl")}
fieldId="masterSamlProcessingUrl"
labelIcon={
<HelpItem
helpText={t("masterSamlProcessingUrlHelp")}
fieldLabelId="masterSamlProcessingUrl"
/>
}
>
<KeycloakTextInput
id="masterSamlProcessingUrl"
type="url" type="url"
data-testid="masterSamlProcessingUrl" name="adminUrl"
{...register("adminUrl")} label={t("masterSamlProcessingUrl")}
{...rest} labelIcon={t("masterSamlProcessingUrlHelp")}
/> />
</FormGroup>
</> </>
)} )}
{protocol !== "saml" && standardFlowEnabled && ( {protocol !== "saml" && standardFlowEnabled && (
@ -179,7 +110,6 @@ export const LoginSettings = ({
name="webOrigins" name="webOrigins"
aria-label={t("webOrigins")} aria-label={t("webOrigins")}
addButtonLabel="addWebOrigins" addButtonLabel="addWebOrigins"
{...rest}
/> />
</FormGroup> </FormGroup>
)} )}