cypress tests working

This commit is contained in:
mfrances 2021-02-23 15:49:57 -05:00
parent 84d8df2b05
commit 0ee4f7ea8e
9 changed files with 469 additions and 16 deletions

View file

@ -215,7 +215,7 @@ describe("User Fed Kerberos tests", () => {
cy.wait(1000);
cy.get('[data-testid="action-dropdown"]').click();
cy.get('[data-testid="delete-provider-cmd"]').click();
cy.get('[data-testid="delete-kerberos-cmd"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();

View file

@ -0,0 +1,275 @@
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", () => {
it("Create Ldap provider from empty state", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get("[data-testid=ldap-card]").click();
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", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
cy.contains(defaultLdapDay).click();
cy.contains(newLdapDay).click();
cy.contains(defaultLdapHour).click();
cy.contains(newLdapHour).click();
cy.contains(defaultLdapMinute).click();
cy.contains(newLdapMinute).click();
providersPage.save();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
expect(cy.contains(newPolicy).should("exist"));
expect(cy.contains(defaultPolicy).should("not.exist"));
});
it("Change existing LDAP provider and click button to cancel", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.wait(1000);
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
cy.contains(newLdapDay).click();
cy.contains(defaultLdapDay).click();
cy.contains(newLdapHour).click();
cy.contains(defaultLdapHour).click();
cy.contains(newLdapMinute).click();
cy.contains(defaultLdapMinute).click();
providersPage.cancel();
cy.wait(1000);
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
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", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
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", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.wait(1000);
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
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", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
// cy get contains
cy.contains("button", "Add new provider", ).click();
cy.contains("li", "LDAP").click();
// cy.contains("Add new provider").click();
// cy.contains("LDAP").click();
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", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="my-ldap-2-dropdown"]').click();
cy.get('[data-testid="card-delete"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
it("Delete an LDAP provider using the Settings view's Action menu", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstLdapName)
.click();
cy.wait(1000);
cy.get('[data-testid="action-dropdown"]').click();
cy.get('[data-testid="delete-ldap-cmd"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
});

View file

@ -0,0 +1,155 @@
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";
}
// Required fields - these always must be filled out when testing a save, everything else can feasibly be left blank (TEST THIS)
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;
}
disableEnabledSwitch() {
cy.get(this.ldapEnabledInput).uncheck({ force: true });
}
enableEnabledSwitch() {
cy.get(this.ldapEnabledInput).check({ force: true });
}
save() {
cy.get(`[${this.saveBtn}]`).click();
return this;
}
cancel() {
cy.get(`[${this.cancelBtn}]`).click();
return this;
}
}

View file

@ -60,7 +60,7 @@ const KerberosSettingsHeader = ({
<DropdownItem
key="delete"
onClick={() => toggleDeleteDialog()}
data-testid="delete-provider-cmd"
data-testid="delete-kerberos-cmd"
>
{t("deleteProvider")}
</DropdownItem>,

View file

@ -92,7 +92,11 @@ const LdapSettingsHeader = ({
{t("removeImported")}
</DropdownItem>,
<DropdownSeparator key="separator" />,
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
<DropdownItem
key="delete"
onClick={() => toggleDeleteDialog()}
data-testid="delete-ldap-cmd"
>
{t("deleteProvider")}
</DropdownItem>,
]}
@ -235,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

@ -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: {
@ -229,6 +230,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 +248,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 +287,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

@ -54,13 +54,6 @@ export const LdapSettingsGeneral = ({
isRequired
>
{/* These hidden fields are required so data object written back matches data retrieved */}
{/* <TextInput
hidden
type="text"
id="kc-console-id"
name="id"
ref={form.register}
/> */}
<TextInput
hidden
type="text"
@ -96,6 +89,7 @@ export const LdapSettingsGeneral = ({
message: `${t("validateName")}`,
},
})}
data-testid="ldap-name"
/>
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
@ -129,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

@ -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,11 +261,11 @@ 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")}`
}
message: `${t("validateCustomUserSearchFilter")}`,
},
})}
/>
{form.errors.config &&

View file

@ -104,7 +104,8 @@
"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",