Merge pull request #400 from mfrances17/add-ldap

User fed: Add LDAP provider and tests
This commit is contained in:
mfrances17 2021-03-02 16:07:32 -05:00 committed by GitHub
commit 511f558834
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 575 additions and 121 deletions

View file

@ -41,7 +41,7 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get("[data-cy=kerberos-card]").click();
cy.get("[data-testid=kerberos-card]").click();
providersPage.fillKerberosRequiredData(
firstKerberosName,
@ -60,7 +60,7 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
@ -81,7 +81,7 @@ describe("User Fed Kerberos tests", () => {
sidebarPage.goToUserFederation();
cy.wait(1000);
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
@ -95,7 +95,7 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
@ -113,7 +113,7 @@ describe("User Fed Kerberos tests", () => {
providersPage.cancel();
cy.wait(1000);
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
@ -133,7 +133,7 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
@ -158,7 +158,7 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
@ -196,8 +196,8 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="my-kerberos-2-dropdown"]').click();
cy.get('[data-cy="card-delete"]').click();
cy.get('[data-testid="my-kerberos-2-dropdown"]').click();
cy.get('[data-testid="card-delete"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
@ -209,13 +209,13 @@ describe("User Fed Kerberos tests", () => {
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
cy.get('[data-testid="action-dropdown"]').click();
cy.get('[data-cy="delete-provider-cmd"]').click();
cy.get('[data-testid="delete-kerberos-cmd"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();

View file

@ -0,0 +1,188 @@
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import CreateLdapProviderPage from "../support/pages/admin_console/manage/providers/CreateLdapProviderPage";
import Masthead from "../support/pages/admin_console/Masthead";
import ModalUtils from "../support/util/ModalUtils";
const loginPage = new LoginPage();
const masthead = new Masthead();
const sidebarPage = new SidebarPage();
const providersPage = new CreateLdapProviderPage();
const modalUtils = new ModalUtils();
const firstLdapName = "my-ldap";
const firstLdapVendor = "Active Directory";
const connectionUrl = "ldap://";
const firstBindType = "simple";
const firstBindDn = "user-1";
const firstBindCreds = "password1";
const firstUsersDn = "user-dn-1";
const firstUserLdapAtt = "uid";
const firstRdnLdapAtt = "uid";
const firstUuidLdapAtt = "entryUUID";
const firstUserObjClasses = "inetOrgPerson, organizationalPerson";
const secondLdapName = `${firstLdapName}-2`;
const secondLdapVendor = "Other";
const secondBindType = "none";
const secondBindDn = "user-2";
const secondBindCreds = "password2";
const secondUsersDn = "user-dn-2";
const secondUserLdapAtt = "cn";
const secondRdnLdapAtt = "cn";
const secondUuidLdapAtt = "objectGUID";
const secondUserObjClasses = "person, organizationalPerson, user";
const defaultPolicy = "DEFAULT";
const newPolicy = "EVICT_WEEKLY";
const defaultLdapDay = "Sunday";
const defaultLdapHour = "00";
const defaultLdapMinute = "00";
const newLdapDay = "Wednesday";
const newLdapHour = "15";
const newLdapMinute = "55";
const createdSuccessMessage = "User federation provider successfully created";
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?";
describe("User Fed LDAP tests", () => {
beforeEach(() => {
cy.visit("");
cy.wait(1000);
loginPage.logIn();
cy.wait(1000);
sidebarPage.goToUserFederation();
cy.wait(1000);
});
it("Create Ldap provider from empty state", () => {
providersPage.clickNewCard("ldap");
providersPage.fillLdapRequiredGeneralData(firstLdapName, firstLdapVendor);
providersPage.fillLdapRequiredConnectionData(
connectionUrl,
firstBindType,
firstBindDn,
firstBindCreds
);
providersPage.fillLdapRequiredSearchingData(
firstUsersDn,
firstUserLdapAtt,
firstRdnLdapAtt,
firstUuidLdapAtt,
firstUserObjClasses
);
providersPage.save();
masthead.checkNotificationMessage(createdSuccessMessage);
sidebarPage.goToUserFederation();
});
it("Update an existing LDAP provider and save", () => {
providersPage.clickExistingCard(firstLdapName);
providersPage.selectCacheType(newPolicy);
providersPage.changeTime(defaultLdapDay, newLdapDay);
providersPage.changeTime(defaultLdapHour, newLdapHour);
providersPage.changeTime(defaultLdapMinute, newLdapMinute);
providersPage.save();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
providersPage.clickExistingCard(firstLdapName);
expect(cy.contains(newPolicy).should("exist"));
expect(cy.contains(defaultPolicy).should("not.exist"));
});
it("Change existing LDAP provider and click button to cancel", () => {
providersPage.clickExistingCard(firstLdapName);
providersPage.selectCacheType(newPolicy);
providersPage.changeTime(newLdapDay, defaultLdapDay);
providersPage.changeTime(newLdapHour, defaultLdapHour);
providersPage.changeTime(newLdapMinute, defaultLdapMinute);
providersPage.cancel();
cy.wait(1000);
providersPage.clickExistingCard(firstLdapName);
providersPage.selectCacheType(newPolicy);
expect(cy.contains(newLdapDay).should("exist"));
expect(cy.contains(newLdapHour).should("exist"));
expect(cy.contains(newLdapMinute).should("exist"));
expect(cy.contains(defaultLdapMinute).should("not.exist"));
sidebarPage.goToUserFederation();
});
it("Disable an existing LDAP provider", () => {
providersPage.clickExistingCard(firstLdapName);
providersPage.disableEnabledSwitch();
modalUtils.checkModalTitle(disableModalTitle).confirmModal();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Disabled").should("exist"));
});
it("Enable an existing previously-disabled LDAP provider", () => {
providersPage.clickExistingCard(firstLdapName);
providersPage.enableEnabledSwitch();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Enabled").should("exist"));
});
it("Create new LDAP provider using the New Provider dropdown", () => {
providersPage.clickMenuCommand("Add new provider", "LDAP");
providersPage.fillLdapRequiredGeneralData(secondLdapName, secondLdapVendor);
providersPage.fillLdapRequiredConnectionData(
connectionUrl,
secondBindType,
secondBindDn,
secondBindCreds
);
providersPage.fillLdapRequiredSearchingData(
secondUsersDn,
secondUserLdapAtt,
secondRdnLdapAtt,
secondUuidLdapAtt,
secondUserObjClasses
);
providersPage.save();
masthead.checkNotificationMessage(createdSuccessMessage);
sidebarPage.goToUserFederation();
});
it("Delete an LDAP provider from card view using the card's 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(firstLdapName);
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
});

View file

@ -19,10 +19,10 @@ export default class CreateKerberosProviderPage {
cancelBtn: string;
constructor() {
this.kerberosNameInput = "data-cy=kerberos-name";
this.kerberosRealmInput = "data-cy=kerberos-realm";
this.kerberosPrincipalInput = "data-cy=kerberos-principal";
this.kerberosKeytabInput = "data-cy=kerberos-keytab";
this.kerberosNameInput = "data-testid=kerberos-name";
this.kerberosRealmInput = "data-testid=kerberos-realm";
this.kerberosPrincipalInput = "data-testid=kerberos-principal";
this.kerberosKeytabInput = "data-testid=kerberos-keytab";
this.kerberosEnabledInput = "#Kerberos-switch";
@ -35,8 +35,8 @@ export default class CreateKerberosProviderPage {
this.kerberosCachePolicyInput = "#kc-cache-policy";
this.kerberosCachePolicyList = "#kc-cache-policy + ul";
this.saveBtn = "data-cy=kerberos-save";
this.cancelBtn = "data-cy=kerberos-cancel";
this.saveBtn = "data-testid=kerberos-save";
this.cancelBtn = "data-testid=kerberos-cancel";
}
//#region Required Settings

View file

@ -0,0 +1,191 @@
export default class CreateLdapProviderPage {
ldapNameInput: string;
ldapVendorInput: string;
ldapVendorList: string;
ldapConnectionUrlInput: string;
ldapBindTypeInput: string;
ldapBindTypeList: string;
ldapBindDnInput: string;
ldapBindCredsInput: string;
ldapUsersDnInput: string;
ldapUserLdapAttInput: string;
ldapRdnLdapAttInput: string;
ldapUuidLdapAttInput: string;
ldapUserObjClassesInput: string;
ldapEnabledInput: string;
ldapCacheDayInput: string;
ldapCacheDayList: string;
ldapCacheHourInput: string;
ldapCacheHourList: string;
ldapCacheMinuteInput: string;
ldapCacheMinuteList: string;
ldapCachePolicyInput: string;
ldapCachePolicyList: string;
saveBtn: string;
cancelBtn: string;
constructor() {
// LdapSettingsGeneral required input values
this.ldapNameInput = "data-testid=ldap-name";
this.ldapVendorInput = "#kc-vendor";
this.ldapVendorList = "#kc-vendor + ul";
// LdapSettingsConnection required input values
this.ldapConnectionUrlInput = "data-testid=ldap-connection-url";
this.ldapBindTypeInput = "#kc-bind-type";
this.ldapBindTypeList = "#kc-bind-type + ul";
this.ldapBindDnInput = "data-testid=ldap-bind-dn";
this.ldapBindCredsInput = "data-testid=ldap-bind-credentials";
// LdapSettingsSearching required input values
this.ldapUsersDnInput = "data-testid=ldap-users-dn";
this.ldapUserLdapAttInput = "data-testid=ldap-username-attribute";
this.ldapRdnLdapAttInput = "data-testid=ldap-rdn-attribute";
this.ldapUuidLdapAttInput = "data-testid=ldap-uuid-attribute";
this.ldapUserObjClassesInput = "data-testid=ldap-user-object-classes";
// SettingsCache input values
this.ldapCacheDayInput = "#kc-eviction-day";
this.ldapCacheDayList = "#kc-eviction-day + ul";
this.ldapCacheHourInput = "#kc-eviction-hour";
this.ldapCacheHourList = "#kc-eviction-hour + ul";
this.ldapCacheMinuteInput = "#kc-eviction-minute";
this.ldapCacheMinuteList = "#kc-eviction-minute + ul";
this.ldapCachePolicyInput = "#kc-cache-policy";
this.ldapCachePolicyList = "#kc-cache-policy + ul";
// LDAP settings enabled switch
this.ldapEnabledInput = "#LDAP-switch";
// LDAP action buttons
this.saveBtn = "data-testid=ldap-save";
this.cancelBtn = "data-testid=ldap-cancel";
}
changeTime(oldTime: string, newTime: string) {
cy.contains(oldTime).click();
cy.contains(newTime).click();
return this;
}
deleteCardFromCard(card: string) {
cy.get(`[data-testid=${card}-dropdown]`).click();
cy.get('[data-testid="card-delete"]').click();
return this;
}
deleteCardFromMenu(card: string) {
this.clickExistingCard(card);
cy.get('[data-testid="action-dropdown"]').click();
cy.get('[data-testid="delete-ldap-cmd"]').click();
return this;
}
// Required fields - these always must be filled out when testing a save
fillLdapRequiredGeneralData(name: string, vendor: string) {
if (name) {
cy.get(`[${this.ldapNameInput}]`).type(name);
}
if (vendor) {
cy.get(this.ldapVendorInput).click();
cy.get(this.ldapVendorList).contains(vendor).click();
}
return this;
}
fillLdapRequiredConnectionData(
connectionUrl: string,
bindType: string,
bindDn: string,
bindCreds: string
) {
if (connectionUrl) {
cy.get(`[${this.ldapConnectionUrlInput}]`).type(connectionUrl);
}
if (bindType) {
cy.get(this.ldapBindTypeInput).click();
cy.get(this.ldapBindTypeList).contains(bindType).click();
}
if (bindDn) {
cy.get(`[${this.ldapBindDnInput}]`).type(bindDn);
}
if (bindCreds) {
cy.get(`[${this.ldapBindCredsInput}]`).type(bindCreds);
}
return this;
}
fillLdapRequiredSearchingData(
usersDn: string,
userLdapAtt: string,
rdnLdapAtt: string,
uuidLdapAtt: string,
userObjClasses: string
) {
if (usersDn) {
cy.get(`[${this.ldapUsersDnInput}]`).type(usersDn);
}
if (userLdapAtt) {
cy.get(`[${this.ldapUserLdapAttInput}]`).type(userLdapAtt);
}
if (rdnLdapAtt) {
cy.get(`[${this.ldapRdnLdapAttInput}]`).type(rdnLdapAtt);
}
if (uuidLdapAtt) {
cy.get(`[${this.ldapUuidLdapAttInput}]`).type(uuidLdapAtt);
}
if (userObjClasses) {
cy.get(`[${this.ldapUserObjClassesInput}]`).type(userObjClasses);
}
return this;
}
selectCacheType(cacheType: string) {
cy.get(this.ldapCachePolicyInput).click();
cy.get(this.ldapCachePolicyList).contains(cacheType).click();
return this;
}
clickExistingCard(cardName: string) {
cy.get('[data-testid="keycloak-card-title"]').contains(cardName).click();
cy.wait(1000);
return this;
}
clickMenuCommand(menu: string, command: string) {
cy.contains("button", menu).click();
cy.contains("li", command).click();
return this;
}
clickNewCard(providerType: string) {
cy.get(`[data-testid=${providerType}-card]`).click();
cy.wait(1000);
return this;
}
disableEnabledSwitch() {
cy.get(this.ldapEnabledInput).uncheck({ force: true });
return this;
}
enableEnabledSwitch() {
cy.get(this.ldapEnabledInput).check({ force: true });
return this;
}
save() {
cy.get(`[${this.saveBtn}]`).click();
return this;
}
cancel() {
cy.get(`[${this.cancelBtn}]`).click();
return this;
}
}

View file

@ -58,7 +58,7 @@ export const KeycloakCard = ({
<CardActions>
{dropdownItems && (
<Dropdown
data-cy={`${title}-dropdown`}
data-testid={`${title}-dropdown`}
isPlain
position={"right"}
toggle={<KebabToggle onToggle={onDropdownToggle} />}
@ -68,7 +68,7 @@ export const KeycloakCard = ({
/>
)}
</CardActions>
<CardTitle data-cy="keycloak-card-title">{title}</CardTitle>
<CardTitle data-testid="keycloak-card-title">{title}</CardTitle>
</CardHeader>
<CardBody />
<CardFooter>

View file

@ -60,7 +60,7 @@ const KerberosSettingsHeader = ({
<DropdownItem
key="delete"
onClick={() => toggleDeleteDialog()}
data-cy="delete-provider-cmd"
data-testid="delete-kerberos-cmd"
>
{t("deleteProvider")}
</DropdownItem>,
@ -93,9 +93,11 @@ export const UserFederationKerberosSettings = () => {
useEffect(() => {
(async () => {
const fetchedComponent = await adminClient.components.findOne({ id });
if (fetchedComponent) {
setupForm(fetchedComponent);
if (id !== "new") {
const fetchedComponent = await adminClient.components.findOne({ id });
if (fetchedComponent) {
setupForm(fetchedComponent);
}
}
})();
}, []);
@ -174,13 +176,13 @@ export const UserFederationKerberosSettings = () => {
<SettingsCache form={form} showSectionHeading />
<Form onSubmit={form.handleSubmit(save)}>
<ActionGroup>
<Button variant="primary" type="submit" data-cy="kerberos-save">
<Button variant="primary" type="submit" data-testid="kerberos-save">
{t("common:save")}
</Button>
<Button
variant="link"
onClick={() => history.push(`/${realm}/user-federation`)}
data-cy="kerberos-cancel"
data-testid="kerberos-cancel"
>
{t("common:cancel")}
</Button>

View file

@ -47,6 +47,7 @@ const LdapSettingsHeader = ({
toggleRemoveUsersDialog,
}: LdapSettingsHeaderProps) => {
const { t } = useTranslation("user-federation");
const { id } = useParams<{ id: string }>();
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
titleKey: "user-federation:userFedDisableConfirmTitle",
messageKey: "user-federation:userFedDisableConfirm",
@ -59,46 +60,57 @@ const LdapSettingsHeader = ({
return (
<>
<DisableConfirm />
<ViewHeader
titleKey="LDAP"
subKey=""
dropdownItems={[
<DropdownItem
key="sync"
onClick={() => console.log("Sync users TBD")}
>
{t("syncChangedUsers")}
</DropdownItem>,
<DropdownItem
key="syncall"
onClick={() => console.log("Sync all users TBD")}
>
{t("syncAllUsers")}
</DropdownItem>,
<DropdownItem
key="unlink"
onClick={() => console.log("Unlink users TBD")}
>
{t("unlinkUsers")}
</DropdownItem>,
<DropdownItem key="remove" onClick={() => toggleRemoveUsersDialog()}>
{t("removeImported")}
</DropdownItem>,
<DropdownSeparator key="separator" />,
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
{t("deleteProvider")}
</DropdownItem>,
]}
isEnabled={value === "true"}
onToggle={(value) => {
if (!value) {
toggleDisableDialog();
} else {
onChange("" + value);
save();
}
}}
/>
{id === "new" ? (
<ViewHeader titleKey="LDAP" subKey="" />
) : (
<ViewHeader
titleKey="LDAP"
subKey=""
dropdownItems={[
<DropdownItem
key="sync"
onClick={() => console.log("Sync users TBD")}
>
{t("syncChangedUsers")}
</DropdownItem>,
<DropdownItem
key="syncall"
onClick={() => console.log("Sync all users TBD")}
>
{t("syncAllUsers")}
</DropdownItem>,
<DropdownItem
key="unlink"
onClick={() => console.log("Unlink users TBD")}
>
{t("unlinkUsers")}
</DropdownItem>,
<DropdownItem
key="remove"
onClick={() => toggleRemoveUsersDialog()}
>
{t("removeImported")}
</DropdownItem>,
<DropdownSeparator key="separator" />,
<DropdownItem
key="delete"
onClick={() => toggleDeleteDialog()}
data-testid="delete-ldap-cmd"
>
{t("deleteProvider")}
</DropdownItem>,
]}
isEnabled={value === "true"}
onToggle={(value) => {
if (!value) {
toggleDisableDialog();
} else {
onChange("" + value);
save();
}
}}
/>
)}
</>
);
};
@ -115,9 +127,11 @@ export const UserFederationLdapSettings = () => {
useEffect(() => {
(async () => {
const fetchedComponent = await adminClient.components.findOne({ id });
if (fetchedComponent) {
setupForm(fetchedComponent);
if (id !== "new") {
const fetchedComponent = await adminClient.components.findOne({ id });
if (fetchedComponent) {
setupForm(fetchedComponent);
}
}
})();
}, []);
@ -134,11 +148,23 @@ export const UserFederationLdapSettings = () => {
const save = async (component: ComponentRepresentation) => {
try {
await adminClient.components.update({ id }, component);
if (id) {
if (id === "new") {
await adminClient.components.create(component);
} else {
await adminClient.components.update({ id }, component);
}
}
setupForm(component as ComponentRepresentation);
addAlert(t("saveSuccess"), AlertVariant.success);
addAlert(
t(id === "new" ? "createSuccess" : "saveSuccess"),
AlertVariant.success
);
} catch (error) {
addAlert(`${t("saveError")} '${error}'`, AlertVariant.danger);
addAlert(
`${t(id === "new" ? "createError" : "saveError")} '${error}'`,
AlertVariant.danger
);
}
};
@ -179,7 +205,7 @@ export const UserFederationLdapSettings = () => {
<RemoveUsersConfirm />
<Controller
name="config.enabled[0]"
defaultValue={["true"]}
defaultValue={["true"][0]}
control={form.control}
render={({ onChange, value }) => (
<LdapSettingsHeader
@ -213,12 +239,13 @@ export const UserFederationLdapSettings = () => {
</ScrollForm>
<Form onSubmit={form.handleSubmit(save)}>
<ActionGroup>
<Button variant="primary" type="submit">
<Button variant="primary" type="submit" data-testid="ldap-save">
{t("common:save")}
</Button>
<Button
variant="link"
onClick={() => history.push(`/${realm}/user-federation`)}
data-testid="ldap-cancel"
>
{t("common:cancel")}
</Button>

View file

@ -113,7 +113,7 @@ export const UserFederationSection = () => {
onClick={() => {
toggleDeleteForCard(userFederation.id!);
}}
data-cy="card-delete"
data-testid="card-delete"
>
{t("common:delete")}
</DropdownItem>,
@ -179,7 +179,7 @@ export const UserFederationSection = () => {
<Card
isHoverable
onClick={() => history.push(`${url}/kerberos/new`)}
data-cy="kerberos-card"
data-testid="kerberos-card"
>
<CardTitle>
<Split hasGutter>
@ -190,7 +190,11 @@ export const UserFederationSection = () => {
</Split>
</CardTitle>
</Card>
<Card isHoverable>
<Card
isHoverable
onClick={() => history.push(`${url}/ldap/new`)}
data-testid="ldap-card"
>
<CardTitle>
<Split hasGutter>
<SplitItem>

View file

@ -107,7 +107,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateName")}`,
},
})}
data-cy="kerberos-name"
data-testid="kerberos-name"
/>
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
@ -137,7 +137,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateRealm")}`,
},
})}
data-cy="kerberos-realm"
data-testid="kerberos-realm"
/>
{form.errors.config &&
form.errors.config.kerberosRealm &&
@ -171,7 +171,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateServerPrincipal")}`,
},
})}
data-cy="kerberos-principal"
data-testid="kerberos-principal"
/>
{form.errors.config &&
form.errors.config.serverPrincipal &&
@ -205,7 +205,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateKeyTab")}`,
},
})}
data-cy="kerberos-keytab"
data-testid="kerberos-keytab"
/>
{form.errors.config &&
form.errors.config.keyTab &&

View file

@ -74,7 +74,7 @@ export const LdapSettingsAdvanced = ({
>
<Controller
name="config.validatePasswordPolicy"
defaultValue={"false"}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch
@ -103,7 +103,7 @@ export const LdapSettingsAdvanced = ({
>
<Controller
name="config.trustEmail"
defaultValue={"false"}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch

View file

@ -66,6 +66,7 @@ export const LdapSettingsConnection = ({
isRequired
type="text"
id="kc-console-connection-url"
data-testid="ldap-connection-url"
name="config.connectionUrl[0]"
ref={form.register({
required: {
@ -167,7 +168,7 @@ export const LdapSettingsConnection = ({
>
<Controller
name="config.connectionPooling"
defaultValue={false}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch
@ -193,7 +194,8 @@ export const LdapSettingsConnection = ({
fieldId="kc-console-connection-timeout"
>
<TextInput
type="text"
type="number"
min={0}
id="kc-console-connection-timeout"
name="config.connectionTimeout[0]"
ref={form.register}
@ -229,6 +231,7 @@ export const LdapSettingsConnection = ({
}}
selections={value}
variant={SelectVariant.single}
data-testid="ldap-bind-type"
>
<SelectOption key={3} value="simple" />
<SelectOption key={4} value="none" />
@ -246,13 +249,27 @@ export const LdapSettingsConnection = ({
/>
}
fieldId="kc-console-bind-dn"
isRequired
>
<TextInput
type="text"
id="kc-console-bind-dn"
data-testid="ldap-bind-dn"
name="config.bindDn[0]"
ref={form.register}
ref={form.register({
required: {
value: true,
message: `${t("validateBindDn")}`,
},
})}
/>
{form.errors.config &&
form.errors.config.bindDn &&
form.errors.config.bindDn[0] && (
<div className="error">
{form.errors.config.bindDn[0].message}
</div>
)}
</FormGroup>
<FormGroup
label={t("bindCredentials")}
@ -271,6 +288,7 @@ export const LdapSettingsConnection = ({
isRequired
type={isPasswordVisible ? "text" : "password"}
id="kc-console-bind-credentials"
data-testid="ldap-bind-credentials"
name="config.bindCredential[0]"
ref={form.register({
required: {

View file

@ -10,6 +10,8 @@ import React, { useState } from "react";
import { HelpItem } from "../../components/help-enabler/HelpItem";
import { UseFormMethods, Controller } from "react-hook-form";
import { FormAccess } from "../../components/form-access/FormAccess";
import { useRealm } from "../../context/realm-context/RealmContext";
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
export type LdapSettingsGeneralProps = {
@ -25,6 +27,7 @@ export const LdapSettingsGeneral = ({
}: LdapSettingsGeneralProps) => {
const { t } = useTranslation("user-federation");
const helpText = useTranslation("user-federation-help").t;
const { realm } = useRealm();
const [isVendorDropdownOpen, setIsVendorDropdownOpen] = useState(false);
@ -54,8 +57,25 @@ export const LdapSettingsGeneral = ({
<TextInput
hidden
type="text"
id="kc-console-id"
name="id"
id="kc-console-provider-id"
name="providerId"
defaultValue="ldap"
ref={form.register}
/>
<TextInput
hidden
type="text"
id="kc-console-provider-type"
name="providerType"
defaultValue="org.keycloak.storage.UserStorageProvider"
ref={form.register}
/>
<TextInput
hidden
type="text"
id="kc-console-parentId"
name="parentId"
defaultValue={realm}
ref={form.register}
/>
<TextInput
@ -69,27 +89,7 @@ export const LdapSettingsGeneral = ({
message: `${t("validateName")}`,
},
})}
/>
<TextInput
hidden
type="text"
id="kc-console-provider-id"
name="providerId"
ref={form.register}
/>
<TextInput
hidden
type="text"
id="kc-console-provider-type"
name="providerType"
ref={form.register}
/>
<TextInput
hidden
type="text"
id="kc-console-parentId"
name="parentId"
ref={form.register}
data-testid="ldap-name"
/>
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
@ -123,6 +123,7 @@ export const LdapSettingsGeneral = ({
}}
selections={value}
variant={SelectVariant.single}
// data-testid="ldap-vendor"
>
<SelectOption key={0} value="ad" isPlaceholder>
Active Directory

View file

@ -45,7 +45,7 @@ export const LdapSettingsKerberosIntegration = ({
>
<Controller
name="config.allowKerberosAuthentication"
defaultValue={false}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch
@ -73,7 +73,7 @@ export const LdapSettingsKerberosIntegration = ({
>
<Controller
name="config.useKerberosForPasswordAuthentication"
defaultValue={false}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch

View file

@ -97,6 +97,7 @@ export const LdapSettingsSearching = ({
isRequired
type="text"
id="kc-console-users-dn"
data-testid="ldap-users-dn"
name="config.usersDn[0]"
ref={form.register({
required: {
@ -129,6 +130,7 @@ export const LdapSettingsSearching = ({
isRequired
type="text"
id="kc-username-ldap-attribute"
data-testid="ldap-username-attribute"
name="config.usernameLDAPAttribute[0]"
ref={form.register({
required: {
@ -161,6 +163,7 @@ export const LdapSettingsSearching = ({
isRequired
type="text"
id="kc-rdn-ldap-attribute"
data-testid="ldap-rdn-attribute"
name="config.rdnLDAPAttribute[0]"
ref={form.register({
required: {
@ -193,6 +196,7 @@ export const LdapSettingsSearching = ({
isRequired
type="text"
id="kc-uuid-ldap-attribute"
data-testid="ldap-uuid-attribute"
name="config.uuidLDAPAttribute[0]"
ref={form.register({
required: {
@ -225,6 +229,7 @@ export const LdapSettingsSearching = ({
isRequired
type="text"
id="kc-user-object-classes"
data-testid="ldap-user-object-classes"
name="config.userObjectClasses[0]"
ref={form.register({
required: {
@ -256,8 +261,20 @@ export const LdapSettingsSearching = ({
type="text"
id="kc-user-ldap-filter"
name="config.customUserSearchFilter[0]"
ref={form.register}
ref={form.register({
pattern: {
value: /(\(.*\))$/,
message: `${t("validateCustomUserSearchFilter")}`,
},
})}
/>
{form.errors.config &&
form.errors.config.customUserSearchFilter &&
form.errors.config.customUserSearchFilter[0] && (
<div className="error">
{form.errors.config.customUserSearchFilter[0].message}
</div>
)}
</FormGroup>
<FormGroup
@ -312,7 +329,8 @@ export const LdapSettingsSearching = ({
fieldId="kc-read-timeout"
>
<TextInput
type="text"
type="number"
min={0}
id="kc-read-timeout"
name="config.readTimeout[0]"
ref={form.register}
@ -332,7 +350,7 @@ export const LdapSettingsSearching = ({
>
<Controller
name="config.pagination"
defaultValue={false}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch

View file

@ -44,7 +44,7 @@ export const LdapSettingsSynchronization = ({
>
<Controller
name="config.importEnabled"
defaultValue={false}
defaultValue={["false"]}
control={form.control}
render={({ onChange, value }) => (
<Switch
@ -71,7 +71,8 @@ export const LdapSettingsSynchronization = ({
fieldId="kc-batch-size"
>
<TextInput
type="text"
type="number"
min={0}
id="kc-batch-size"
name="config.batchSizeForSync[0]"
ref={form.register}
@ -92,7 +93,8 @@ export const LdapSettingsSynchronization = ({
fieldId="kc-full-sync-period"
>
<TextInput
type="text"
type="number"
min={-1}
id="kc-full-sync-period"
name="config.fullSyncPeriod[0]"
ref={form.register}
@ -113,7 +115,8 @@ export const LdapSettingsSynchronization = ({
hasNoPaddingTop
>
<TextInput
type="text"
type="number"
min={-1}
id="kc-changed-users-sync-period"
name="config.changedSyncPeriod[0]"
ref={form.register}

View file

@ -104,12 +104,14 @@
"validateServerPrincipal":"You must enter a server principal",
"validateKeyTab": "You must enter a key tab",
"validateConnectionUrl": "You must enter a connection URL",
"validateBindCredentials": "You must enter bind credentials",
"validateBindDn": "You must enter the DN of the LDAP admin",
"validateBindCredentials": "You must enter the password of the LDAP admin",
"validateUuidLDAPAttribute": "You must enter a UUID LDAP attribute",
"validateUserObjectClasses": "You must enter one or more user object classes",
"validateUsersDn": "You must enter users DN",
"validateUsernameLDAPAttribute": "You must enter a username LDAP attribute",
"validateRdnLdapAttribute": "You must enter an RDN LDAP attribute",
"validateCustomUserSearchFilter": "Filter must be enclosed in parentheses, for example: (filter)",
"id": "ID",
"mapperType": "Mapper type",

View file

@ -126,7 +126,7 @@ export const SettingsCache = ({
}}
selections={value}
variant={SelectVariant.single}
data-cy="kerberos-cache-policy"
data-testid="kerberos-cache-policy"
>
<SelectOption key={0} value={["DEFAULT"]} isPlaceholder />
<SelectOption key={1} value={["EVICT_DAILY"]} />
@ -156,7 +156,7 @@ export const SettingsCache = ({
control={form.control}
render={({ onChange, value }) => (
<Select
data-cy="cache-day"
data-testid="cache-day"
toggleId="kc-eviction-day"
required
onToggle={() =>
@ -294,7 +294,7 @@ export const SettingsCache = ({
id="kc-max-lifespan"
name="config.maxLifespan[0]"
ref={form.register}
data-cy="kerberos-cache-lifespan"
data-testid="kerberos-cache-lifespan"
/>
</FormGroup>
) : (