don't test ldap when form isn't valid (#2294)

* don't test ldap when form isn't valid

fixes: #1776

* changed to PF way of showing errors

* Update src/user-federation/kerberos/KerberosSettingsRequired.tsx

Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>

* Update src/user-federation/kerberos/KerberosSettingsRequired.tsx

Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>

* Update src/user-federation/kerberos/KerberosSettingsRequired.tsx

Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>

Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>
This commit is contained in:
Erik Jan de Wit 2022-03-29 09:49:43 +02:00 committed by GitHub
parent e9707f0a87
commit 78bdf2d2ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 118 additions and 79 deletions

View file

@ -65,6 +65,8 @@ export const AttributeGeneralSettings = () => {
} }
fieldId="kc-attribute-name" fieldId="kc-attribute-name"
isRequired isRequired
validated={form.errors.name ? "error" : "default"}
helperTextInvalid={form.errors.name?.message}
> >
<TextInput <TextInput
isRequired isRequired
@ -79,10 +81,8 @@ export const AttributeGeneralSettings = () => {
}, },
})} })}
data-testid="attribute-name" data-testid="attribute-name"
validated={form.errors.name ? "error" : "default"}
/> />
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("attributeDisplayName")} label={t("attributeDisplayName")}

View file

@ -70,6 +70,8 @@ export const KerberosSettingsRequired = ({
} }
fieldId="kc-console-display-name" fieldId="kc-console-display-name"
isRequired isRequired
validated={form.errors.name ? "error" : "default"}
helperTextInvalid={form.errors.name?.message}
> >
{/* These hidden fields are required so data object written back matches data retrieved */} {/* These hidden fields are required so data object written back matches data retrieved */}
<TextInput <TextInput
@ -109,10 +111,8 @@ export const KerberosSettingsRequired = ({
}, },
})} })}
data-testid="kerberos-name" data-testid="kerberos-name"
validated={form.errors.name ? "error" : "default"}
/> />
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -125,6 +125,10 @@ export const KerberosSettingsRequired = ({
} }
fieldId="kc-kerberos-realm" fieldId="kc-kerberos-realm"
isRequired isRequired
validated={
form.errors.config?.kerberosRealm?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.kerberosRealm?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -138,12 +142,10 @@ export const KerberosSettingsRequired = ({
}, },
})} })}
data-testid="kerberos-realm" data-testid="kerberos-realm"
validated={
form.errors.config?.kerberosRealm?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.kerberosRealm?.[0] && (
<div className="error">
{form.errors.config.kerberosRealm[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -156,6 +158,10 @@ export const KerberosSettingsRequired = ({
} }
fieldId="kc-server-principal" fieldId="kc-server-principal"
isRequired isRequired
validated={
form.errors.config?.serverPrincipal?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.serverPrincipal?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -169,12 +175,10 @@ export const KerberosSettingsRequired = ({
}, },
})} })}
data-testid="kerberos-principal" data-testid="kerberos-principal"
validated={
form.errors.config?.serverPrincipal?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.serverPrincipal?.[0] && (
<div className="error">
{form.errors.config.serverPrincipal[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -187,6 +191,8 @@ export const KerberosSettingsRequired = ({
} }
fieldId="kc-key-tab" fieldId="kc-key-tab"
isRequired isRequired
validated={form.errors.config?.keyTab?.[0] ? "error" : "default"}
helperTextInvalid={form.errors.config?.keyTab?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -200,10 +206,8 @@ export const KerberosSettingsRequired = ({
}, },
})} })}
data-testid="kerberos-keytab" data-testid="kerberos-keytab"
validated={form.errors.config?.keyTab?.[0] ? "error" : "default"}
/> />
{form.errors.config?.keyTab?.[0] && (
<div className="error">{form.errors.config.keyTab[0].message}</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup

View file

@ -68,6 +68,7 @@ export const LdapSettingsConnection = ({
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
const testLdap = async (testType: TestTypes) => { const testLdap = async (testType: TestTypes) => {
if (!(await form.trigger())) return;
try { try {
const settings = convertFormToSettings(form); const settings = convertFormToSettings(form);
await adminClient.realms.testLDAPConnection( await adminClient.realms.testLDAPConnection(
@ -113,6 +114,10 @@ export const LdapSettingsConnection = ({
} }
fieldId="kc-console-connection-url" fieldId="kc-console-connection-url"
isRequired isRequired
validated={
form.errors.config?.connectionUrl?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.connectionUrl?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -126,12 +131,10 @@ export const LdapSettingsConnection = ({
message: `${t("validateConnectionUrl")}`, message: `${t("validateConnectionUrl")}`,
}, },
})} })}
validated={
form.errors.config?.connectionUrl?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.connectionUrl?.[0] && (
<div className="error">
{form.errors.config.connectionUrl[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("enableStartTls")} label={t("enableStartTls")}
@ -312,6 +315,11 @@ export const LdapSettingsConnection = ({
data-testid="ldap-bind-dn" data-testid="ldap-bind-dn"
name="config.bindDn[0]" name="config.bindDn[0]"
ref={form.register({ required: true })} ref={form.register({ required: true })}
validated={
form.errors.config?.bindDn
? ValidatedOptions.error
: ValidatedOptions.default
}
/> />
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -340,6 +348,11 @@ export const LdapSettingsConnection = ({
ref={form.register({ ref={form.register({
required: true, required: true,
})} })}
validated={
form.errors.config?.bindCredential
? ValidatedOptions.error
: ValidatedOptions.default
}
/> />
</FormGroup> </FormGroup>
</> </>

View file

@ -113,6 +113,8 @@ export const LdapSettingsGeneral = ({
} }
fieldId="kc-console-display-name" fieldId="kc-console-display-name"
isRequired isRequired
validated={form.errors.name ? "error" : "default"}
helperTextInvalid={form.errors.name?.message}
> >
{/* These hidden fields are required so data object written back matches data retrieved */} {/* These hidden fields are required so data object written back matches data retrieved */}
<TextInput hidden type="text" id="kc-console-id" name="id" /> <TextInput hidden type="text" id="kc-console-id" name="id" />
@ -153,10 +155,8 @@ export const LdapSettingsGeneral = ({
}, },
})} })}
data-testid="ldap-name" data-testid="ldap-name"
validated={form.errors.name ? "error" : "default"}
/> />
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("vendor")} label={t("vendor")}

View file

@ -77,6 +77,10 @@ export const LdapSettingsKerberosIntegration = ({
} }
fieldId="kc-kerberos-realm" fieldId="kc-kerberos-realm"
isRequired isRequired
validated={
form.errors.config?.kerberosRealm?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.kerberosRealm?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -90,12 +94,10 @@ export const LdapSettingsKerberosIntegration = ({
}, },
})} })}
data-testid="kerberos-realm" data-testid="kerberos-realm"
validated={
form.errors.config?.kerberosRealm?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.kerberosRealm?.[0] && (
<div className="error">
{form.errors.config.kerberosRealm[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -108,6 +110,12 @@ export const LdapSettingsKerberosIntegration = ({
} }
fieldId="kc-server-principal" fieldId="kc-server-principal"
isRequired isRequired
validated={
form.errors.config?.serverPrincipal?.[0] ? "error" : "default"
}
helperTextInvalid={
form.errors.config?.serverPrincipal?.[0].message
}
> >
<TextInput <TextInput
isRequired isRequired
@ -121,12 +129,10 @@ export const LdapSettingsKerberosIntegration = ({
}, },
})} })}
data-testid="kerberos-principal" data-testid="kerberos-principal"
validated={
form.errors.config?.serverPrincipal?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.serverPrincipal?.[0] && (
<div className="error">
{form.errors.config.serverPrincipal[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
@ -139,6 +145,8 @@ export const LdapSettingsKerberosIntegration = ({
} }
fieldId="kc-key-tab" fieldId="kc-key-tab"
isRequired isRequired
validated={form.errors.config?.keyTab?.[0] ? "error" : "default"}
helperTextInvalid={form.errors.config?.keyTab?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -152,12 +160,10 @@ export const LdapSettingsKerberosIntegration = ({
}, },
})} })}
data-testid="kerberos-keytab" data-testid="kerberos-keytab"
validated={
form.errors.config?.keyTab?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.keyTab?.[0] && (
<div className="error">
{form.errors.config.keyTab[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup

View file

@ -52,6 +52,8 @@ export const LdapSettingsSearching = ({
} }
fieldId="kc-edit-mode" fieldId="kc-edit-mode"
isRequired isRequired
validated={form.errors.config?.editMode?.[0] ? "error" : "default"}
helperTextInvalid={form.errors.config?.editMode?.[0].message}
> >
<Controller <Controller
name="config.editMode[0]" name="config.editMode[0]"
@ -74,6 +76,9 @@ export const LdapSettingsSearching = ({
}} }}
selections={value} selections={value}
variant={SelectVariant.single} variant={SelectVariant.single}
validated={
form.errors.config?.editMode?.[0] ? "error" : "default"
}
> >
<SelectOption value="" isPlaceholder /> <SelectOption value="" isPlaceholder />
<SelectOption value="READ_ONLY" /> <SelectOption value="READ_ONLY" />
@ -82,11 +87,6 @@ export const LdapSettingsSearching = ({
</Select> </Select>
)} )}
/> />
{form.errors.config?.editMode?.[0] && (
<div className="error">
{form.errors.config.editMode[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("usersDN")} label={t("usersDN")}
@ -98,6 +98,8 @@ export const LdapSettingsSearching = ({
} }
fieldId="kc-console-users-dn" fieldId="kc-console-users-dn"
isRequired isRequired
validated={form.errors.config?.usersDn?.[0] ? "error" : "default"}
helperTextInvalid={form.errors.config?.usersDn?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -112,10 +114,8 @@ export const LdapSettingsSearching = ({
message: `${t("validateUsersDn")}`, message: `${t("validateUsersDn")}`,
}, },
})} })}
validated={form.errors.config?.usersDn?.[0] ? "error" : "default"}
/> />
{form.errors.config?.usersDn?.[0] && (
<div className="error">{form.errors.config.usersDn[0].message}</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("usernameLdapAttribute")} label={t("usernameLdapAttribute")}
@ -127,6 +127,12 @@ export const LdapSettingsSearching = ({
} }
fieldId="kc-username-ldap-attribute" fieldId="kc-username-ldap-attribute"
isRequired isRequired
validated={
form.errors.config?.usernameLDAPAttribute?.[0] ? "error" : "default"
}
helperTextInvalid={
form.errors.config?.usernameLDAPAttribute?.[0].message
}
> >
<TextInput <TextInput
isRequired isRequired
@ -141,12 +147,12 @@ export const LdapSettingsSearching = ({
message: `${t("validateUsernameLDAPAttribute")}`, message: `${t("validateUsernameLDAPAttribute")}`,
}, },
})} })}
validated={
form.errors.config?.usernameLDAPAttribute?.[0]
? "error"
: "default"
}
/> />
{form.errors.config?.usernameLDAPAttribute?.[0] && (
<div className="error">
{form.errors.config.usernameLDAPAttribute[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("rdnLdapAttribute")} label={t("rdnLdapAttribute")}
@ -158,6 +164,10 @@ export const LdapSettingsSearching = ({
} }
fieldId="kc-rdn-ldap-attribute" fieldId="kc-rdn-ldap-attribute"
isRequired isRequired
validated={
form.errors.config?.rdnLDAPAttribute?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.rdnLDAPAttribute?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -172,12 +182,10 @@ export const LdapSettingsSearching = ({
message: `${t("validateRdnLdapAttribute")}`, message: `${t("validateRdnLdapAttribute")}`,
}, },
})} })}
validated={
form.errors.config?.rdnLDAPAttribute?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.rdnLDAPAttribute?.[0] && (
<div className="error">
{form.errors.config.rdnLDAPAttribute[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("uuidLdapAttribute")} label={t("uuidLdapAttribute")}
@ -189,6 +197,10 @@ export const LdapSettingsSearching = ({
} }
fieldId="kc-uuid-ldap-attribute" fieldId="kc-uuid-ldap-attribute"
isRequired isRequired
validated={
form.errors.config?.uuidLDAPAttribute?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.uuidLDAPAttribute?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -203,12 +215,10 @@ export const LdapSettingsSearching = ({
message: `${t("validateUuidLDAPAttribute")}`, message: `${t("validateUuidLDAPAttribute")}`,
}, },
})} })}
validated={
form.errors.config?.uuidLDAPAttribute?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.uuidLDAPAttribute?.[0] && (
<div className="error">
{form.errors.config.uuidLDAPAttribute[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("userObjectClasses")} label={t("userObjectClasses")}
@ -220,6 +230,10 @@ export const LdapSettingsSearching = ({
} }
fieldId="kc-user-object-classes" fieldId="kc-user-object-classes"
isRequired isRequired
validated={
form.errors.config?.userObjectClasses?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.userObjectClasses?.[0].message}
> >
<TextInput <TextInput
isRequired isRequired
@ -234,12 +248,10 @@ export const LdapSettingsSearching = ({
message: `${t("validateUserObjectClasses")}`, message: `${t("validateUserObjectClasses")}`,
}, },
})} })}
validated={
form.errors.config?.userObjectClasses?.[0] ? "error" : "default"
}
/> />
{form.errors.config?.userObjectClasses?.[0] && (
<div className="error">
{form.errors.config.userObjectClasses[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("userLdapFilter")} label={t("userLdapFilter")}
@ -250,6 +262,14 @@ export const LdapSettingsSearching = ({
/> />
} }
fieldId="kc-user-ldap-filter" fieldId="kc-user-ldap-filter"
validated={
form.errors.config?.customUserSearchFilter?.[0]
? "error"
: "default"
}
helperTextInvalid={
form.errors.config?.customUserSearchFilter?.[0].message
}
> >
<TextInput <TextInput
type="text" type="text"
@ -261,12 +281,12 @@ export const LdapSettingsSearching = ({
message: `${t("validateCustomUserSearchFilter")}`, message: `${t("validateCustomUserSearchFilter")}`,
}, },
})} })}
validated={
form.errors.config?.customUserSearchFilter?.[0]
? "error"
: "default"
}
/> />
{form.errors.config?.customUserSearchFilter?.[0] && (
<div className="error">
{form.errors.config.customUserSearchFilter[0].message}
</div>
)}
</FormGroup> </FormGroup>
<FormGroup <FormGroup

View file

@ -6,10 +6,6 @@
display: contents; display: contents;
} }
.error {
color: red;
}
.keycloak__user-federation__assign-role { .keycloak__user-federation__assign-role {
display: flex; display: flex;
flex-direction: row; flex-direction: row;