Added validation on realm name (#4259)
This commit is contained in:
parent
60d10d88bd
commit
31b203665a
4 changed files with 32 additions and 10 deletions
|
@ -15,11 +15,12 @@ const realmSettings = new RealmSettings();
|
||||||
const modalUtils = new ModalUtils();
|
const modalUtils = new ModalUtils();
|
||||||
|
|
||||||
const testRealmName =
|
const testRealmName =
|
||||||
"Test realm " + (Math.random() + 1).toString(36).substring(7);
|
"Test-realm-" + (Math.random() + 1).toString(36).substring(7);
|
||||||
const newRealmName =
|
const newRealmName =
|
||||||
"New Test realm " + (Math.random() + 1).toString(36).substring(7);
|
"New-Test-realm-" + (Math.random() + 1).toString(36).substring(7);
|
||||||
const editedRealmName =
|
const editedRealmName =
|
||||||
"Edited Test realm " + (Math.random() + 1).toString(36).substring(7);
|
"Edited-Test-realm-" + (Math.random() + 1).toString(36).substring(7);
|
||||||
|
const testDisabledName = "Test-Disabled";
|
||||||
|
|
||||||
describe("Realm tests", () => {
|
describe("Realm tests", () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
|
@ -67,21 +68,22 @@ describe("Realm tests", () => {
|
||||||
it("should create Test Disabled realm", () => {
|
it("should create Test Disabled realm", () => {
|
||||||
sidebarPage.goToCreateRealm();
|
sidebarPage.goToCreateRealm();
|
||||||
sidebarPage.waitForPageLoad();
|
sidebarPage.waitForPageLoad();
|
||||||
createRealmPage.fillRealmName("Test Disabled").createRealm();
|
|
||||||
|
createRealmPage.fillRealmName(testDisabledName).createRealm();
|
||||||
createRealmPage.disableRealm();
|
createRealmPage.disableRealm();
|
||||||
|
|
||||||
masthead.checkNotificationMessage("Realm created successfully");
|
masthead.checkNotificationMessage("Realm created successfully");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should cancel deleting Test Disabled realm", () => {
|
it("Should cancel deleting Test Disabled realm", () => {
|
||||||
sidebarPage.goToRealm("Test Disabled").goToRealmSettings();
|
sidebarPage.goToRealm(testDisabledName).goToRealmSettings();
|
||||||
realmSettings.clickActionMenu();
|
realmSettings.clickActionMenu();
|
||||||
cy.findByText("Delete").click();
|
cy.findByText("Delete").click();
|
||||||
modalUtils.cancelModal();
|
modalUtils.cancelModal();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should delete Test Disabled realm", () => {
|
it("Should delete Test Disabled realm", () => {
|
||||||
sidebarPage.goToRealm("Test Disabled").goToRealmSettings();
|
sidebarPage.goToRealm(testDisabledName).goToRealmSettings();
|
||||||
realmSettings.clickActionMenu();
|
realmSettings.clickActionMenu();
|
||||||
cy.findByText("Delete").click();
|
cy.findByText("Delete").click();
|
||||||
modalUtils.confirmModal();
|
modalUtils.confirmModal();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"uploadFile": "Upload JSON file",
|
"uploadFile": "Upload JSON file",
|
||||||
"realmName": "Realm name",
|
"realmName": "Realm name",
|
||||||
|
"invalidRealmName": "Realm name can't contain special characters",
|
||||||
"enabled": "Enabled",
|
"enabled": "Enabled",
|
||||||
"createRealm": "Create realm",
|
"createRealm": "Create realm",
|
||||||
"realmExplain": "A realm manages a set of users, credentials, roles, and groups. A user belongs to and logs into a realm. Realms are isolated from one another and can only manage and authenticate the users that they control.",
|
"realmExplain": "A realm manages a set of users, credentials, roles, and groups. A user belongs to and logs into a realm. Realms are isolated from one another and can only manage and authenticate the users that they control.",
|
||||||
|
|
|
@ -48,7 +48,7 @@ export const RealmSettingsGeneralTab = ({
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
setValue,
|
setValue,
|
||||||
formState: { isDirty },
|
formState: { isDirty, errors },
|
||||||
} = form;
|
} = form;
|
||||||
const isFeatureEnabled = useIsFeatureEnabled();
|
const isFeatureEnabled = useIsFeatureEnabled();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
@ -79,10 +79,23 @@ export const RealmSettingsGeneralTab = ({
|
||||||
className="pf-u-mt-lg"
|
className="pf-u-mt-lg"
|
||||||
onSubmit={handleSubmit(save)}
|
onSubmit={handleSubmit(save)}
|
||||||
>
|
>
|
||||||
<FormGroup label={t("realmId")} fieldId="kc-realm-id" isRequired>
|
<FormGroup
|
||||||
|
label={t("realmId")}
|
||||||
|
fieldId="kc-realm-id"
|
||||||
|
isRequired
|
||||||
|
validated={errors.realm ? "error" : "default"}
|
||||||
|
helperTextInvalid={errors.realm?.message}
|
||||||
|
>
|
||||||
<Controller
|
<Controller
|
||||||
name="realm"
|
name="realm"
|
||||||
control={control}
|
control={control}
|
||||||
|
rules={{
|
||||||
|
required: { value: true, message: t("common:required") },
|
||||||
|
pattern: {
|
||||||
|
value: /^[a-zA-Z0-9-_]+$/,
|
||||||
|
message: t("realm:invalidRealmName"),
|
||||||
|
},
|
||||||
|
}}
|
||||||
defaultValue=""
|
defaultValue=""
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<ClipboardCopy data-testid="realmName" onChange={field.onChange}>
|
<ClipboardCopy data-testid="realmName" onChange={field.onChange}>
|
||||||
|
|
|
@ -81,13 +81,19 @@ export default function NewRealmForm() {
|
||||||
isRequired
|
isRequired
|
||||||
fieldId="kc-realm-name"
|
fieldId="kc-realm-name"
|
||||||
validated={errors.realm ? "error" : "default"}
|
validated={errors.realm ? "error" : "default"}
|
||||||
helperTextInvalid={t("common:required")}
|
helperTextInvalid={errors.realm?.message}
|
||||||
>
|
>
|
||||||
<KeycloakTextInput
|
<KeycloakTextInput
|
||||||
isRequired
|
isRequired
|
||||||
id="kc-realm-name"
|
id="kc-realm-name"
|
||||||
validated={errors.realm ? "error" : "default"}
|
validated={errors.realm ? "error" : "default"}
|
||||||
{...register("realm", { required: true })}
|
{...register("realm", {
|
||||||
|
required: { value: true, message: t("common:required") },
|
||||||
|
pattern: {
|
||||||
|
value: /^[a-zA-Z0-9-_]+$/,
|
||||||
|
message: t("invalidRealmName"),
|
||||||
|
},
|
||||||
|
})}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup label={t("enabled")} fieldId="kc-realm-enabled-switch">
|
<FormGroup label={t("enabled")} fieldId="kc-realm-enabled-switch">
|
||||||
|
|
Loading…
Reference in a new issue