complete suite of kerberos cypress tests

This commit is contained in:
mfrances 2021-02-16 14:42:30 -05:00
parent cf8451fe9d
commit 8c4d6d4eb4
7 changed files with 213 additions and 112 deletions

View file

@ -64,6 +64,7 @@ export const KeycloakCard = ({
onClick={(e) => handleCardMenuClick(e)}
isOpen={isDropdownOpen}
dropdownItems={dropdownItems}
data-cy={`${title}-dropdown`}
/>
)}
</CardActions>

View file

@ -112,6 +112,7 @@ export const ViewHeader = ({
}
isOpen={isDropdownOpen}
dropdownItems={dropdownItems}
data-cy="action-dropdown"
/>
</ToolbarItem>
)}

View file

@ -57,7 +57,11 @@ const KerberosSettingsHeader = ({
titleKey="Kerberos"
subKey=""
dropdownItems={[
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
<DropdownItem
key="delete"
onClick={() => toggleDeleteDialog()}
data-cy="delete-provider-cmd"
>
{t("deleteProvider")}
</DropdownItem>,
]}

View file

@ -110,6 +110,7 @@ export const UserFederationSection = () => {
onClick={() => {
toggleDeleteForCard(userFederation.id!);
}}
data-cy="card-delete"
>
{t("common:delete")}
</DropdownItem>,

View file

@ -156,6 +156,7 @@ export const SettingsCache = ({
control={form.control}
render={({ onChange, value }) => (
<Select
data-cy="cache-day"
toggleId="kc-eviction-day"
required
onToggle={() =>

View file

@ -1,85 +1,224 @@
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
// import ListingPage from "../support/pages/admin_console/ListingPage";
import CreateKerberosProviderPage from "../support/pages/admin_console/manage/providers/CreateKerberosProviderPage";
// import Masthead from "../support/pages/admin_console/Masthead";
// import { wait } from "@testing-library/react";
import Masthead from "../support/pages/admin_console/Masthead";
import ModalUtils from "../support/util/ModalUtils";
const loginPage = new LoginPage();
// const masthead = new Masthead();
const masthead = new Masthead();
const sidebarPage = new SidebarPage();
// const listingPage = new ListingPage();
const providersPage = new CreateKerberosProviderPage();
const modalUtils = new ModalUtils();
// config info
const kerberosName = "my-kerberos";
const kerberosRealm = "my-realm";
const kerberosPrincipal = "my-principal";
const kerberosKeytab = "my-keytab";
// const kerberosSecondName = "my-kerberos-2";
const firstKerberosName = "my-kerberos";
const firstKerberosRealm = "my-realm";
const firstKerberosPrincipal = "my-principal";
const firstKerberosKeytab = "my-keytab";
const policy = "EVICT_WEEKLY"
const kerberosDay = "Tuesday";
const kerberosHour = "11";
const kerberosMinute = "45";
// const kerberosLifespan = "24";
const secondKerberosName = `${firstKerberosName}-2`;
const secondKerberosRealm = `${firstKerberosRealm}-2`;
const secondKerberosPrincipal = `${firstKerberosPrincipal}-2`;
const secondKerberosKeytab = `${firstKerberosKeytab}-2`;
describe('User Fed Kerberos test', () => {
it('Kerberos provider creation from empty state', () => {
const defaultPolicy = "DEFAULT";
const newPolicy = "EVICT_WEEKLY";
const defaultKerberosDay = "Sunday";
const defaultKerberosHour = "00";
const defaultKerberosMinute = "00";
const newKerberosDay = "Wednesday";
const newKerberosHour = "15";
const newKerberosMinute = "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 Kerberos tests", () => {
it("Create Kerberos provider from empty state", () => {
cy.visit("");
loginPage.logIn();
// CREATE FROM EMPTY STATE CARD PAGE
sidebarPage.goToUserFederation();
cy.get('[data-cy=kerberos-card]').click();
// cy.get('[data-cy=kerberos-name]').type("my-kerberos-provider");
providersPage.fillKerberosRequiredData(kerberosName, kerberosRealm, kerberosPrincipal, kerberosKeytab);
cy.get("[data-cy=kerberos-card]").click();
providersPage.fillKerberosRequiredData(
firstKerberosName,
firstKerberosRealm,
firstKerberosPrincipal,
firstKerberosKeytab
);
providersPage.save();
// TODO verify save message
// UPDATE
masthead.checkNotificationMessage(createdSuccessMessage);
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]').contains("my-kerberos").click();
});
it("Update an existing Kerberos provider and save", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
providersPage.selectCacheType(policy);
// cy.get('[data-cy="kerberos-cache-policy"]').select(policy);
providersPage.fillCachedData( kerberosHour, kerberosMinute)
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
cy.contains(defaultKerberosDay).click();
cy.contains(newKerberosDay).click();
cy.contains(defaultKerberosHour).click();
cy.contains(newKerberosHour).click();
cy.contains(defaultKerberosMinute).click();
cy.contains(newKerberosMinute).click();
// TODO verify update message
providersPage.save();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
// CREATE FROM USER FED CARD PAGE
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
expect(cy.contains(newPolicy).should("exist"));
expect(cy.contains(defaultPolicy).should("not.exist"));
});
it("Change existing Kerberos provider and click button to cancel", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
cy.contains(newKerberosDay).click();
cy.contains(defaultKerberosDay).click();
})
cy.contains(newKerberosHour).click();
cy.contains(defaultKerberosHour).click();
// Messages:
// User federation provider successfully created
// The user federation provider has been deleted.
cy.contains(newKerberosMinute).click();
cy.contains(defaultKerberosMinute).click();
providersPage.cancel();
cy.wait(1000);
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
expect(cy.contains(newKerberosDay).should("exist"));
expect(cy.contains(newKerberosHour).should("exist"));
expect(cy.contains(newKerberosMinute).should("exist"));
// it("should open kerberos empty settings page by clicking card", function () {
expect(cy.contains(defaultKerberosMinute).should("not.exist"));
// // // listingPage.goToCreateItem();
// // cy.get('[data-cy=kerberos-card]').click();
// // cy.get('[data-cy=kerberos-name]').type("my-kerberos-provider");
// // // providersPage.fillKerberosRequiredData(kerberosName, kerberosRealm, kerberosPrincipal, kerberosKeytab);
sidebarPage.goToUserFederation();
});
// // // providersPage.save();
it("Disable an existing Kerberos provider", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
// // // The error should inform about duplicated name/id (THIS MESSAGE DOES NOT HAVE QUOTES AS THE OTHERS)
// // // masthead.checkNotificationMessage(
// // // "Could not create role: Role with name admin already exists"
// // // );
// });
})
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.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 Kerberos provider", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.enableEnabledSwitch();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Enabled").should("exist"));
});
it("Create new Kerberos provider using the New Provider dropdown", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.contains("Add new provider").click();
cy.contains("Kerberos").click();
providersPage.fillKerberosRequiredData(
secondKerberosName,
secondKerberosRealm,
secondKerberosPrincipal,
secondKerberosKeytab
);
providersPage.save();
masthead.checkNotificationMessage(createdSuccessMessage);
sidebarPage.goToUserFederation();
});
it("Delete a Kerberos provider from card view using the card's menu", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="my-kerberos-2-dropdown"]').click();
cy.get('[data-cy="card-delete"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
it("Delete a Kerberos provider using the Settings view's Action menu", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
cy.get('[data-cy="action-dropdown"]').click();
cy.get('[data-cy="delete-provider-cmd"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
});

View file

@ -4,41 +4,27 @@ export default class CreateKerberosProviderPage {
kerberosPrincipalInput: string;
kerberosKeytabInput: string;
// clientScopeTypeDrpDwn: string;
// this.clientScopeTypeDrpDwn = "#kc-protocol";
// selectClientScopeType(clientScopeType: string) {
// cy.get(this.clientScopeTypeDrpDwn).click();
// cy.get(this.clientScopeTypeList).contains(clientScopeType).click();
kerberosEnabledInput: string;
// return this;
// }
// kerberosCachePolicyInput: string;
kerberosCacheDayInput: string;
kerberosCacheDayList: string;
kerberosCacheHourInput: string;
kerberosCacheHourList: string;
kerberosCacheMinuteInput: string;
kerberosCacheMinuteList: string;
// kerberosCacheLifespanInput: string;
kerberosCachePolicyInput: string;
kerberosCachePolicyList: string;
realmRoleNameError: string;
realmRoleDescriptionInput: string;
saveBtn: string;
cancelBtn: string;
constructor() {
// cypress IDs
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.kerberosCachePolicyInput = "#kc-cache-policy";
this.kerberosCachePolicyList = "#kc-cache-policy + ul";
this.kerberosEnabledInput = "#Kerberos-switch";
this.kerberosCacheDayInput = "#kc-eviction-day";
this.kerberosCacheDayList = "#kc-eviction-day + ul";
@ -46,15 +32,11 @@ export default class CreateKerberosProviderPage {
this.kerberosCacheHourList = "#kc-eviction-hour + ul";
this.kerberosCacheMinuteInput = "#kc-eviction-minute";
this.kerberosCacheMinuteList = "#kc-eviction-minute + ul";
// this.kerberosCacheLifespanInput = "data-cy=kerberos-cache-lifespan";
this.realmRoleNameError = "#kc-name-helper";
this.realmRoleDescriptionInput = "#kc-role-description";
this.kerberosCachePolicyInput = "#kc-cache-policy";
this.kerberosCachePolicyList = "#kc-cache-policy + ul";
this.saveBtn = "data-cy=kerberos-save";
this.cancelBtn = "data-cy=kerberos-cancel";
// this.cardTitle = "keycloak-card-title";
}
//#region Required Settings
@ -64,7 +46,6 @@ export default class CreateKerberosProviderPage {
principal: string,
keytab: string
) {
// cy.get(this.realmRoleNameInput).clear();
if (name) {
cy.get(`[${this.kerberosNameInput}]`).type(name);
}
@ -77,57 +58,30 @@ export default class CreateKerberosProviderPage {
if (keytab) {
cy.get(`[${this.kerberosKeytabInput}]`).type(keytab);
}
return this;
}
selectCacheType(cacheType: string) {
cy.get(this.kerberosCachePolicyInput).click();
cy.get(this.kerberosCachePolicyList).contains(cacheType).click();
return this;
}
// fillCachedData(day: string, hour: string, minute: string) {
fillCachedData(hour: string, minute: string) {
// cy.get(this.realmRoleNameInput).clear();
// if (policy) {
// cy.get(`[${this.kerberosNameInput}]`).type(policy);
// }
// if (day) {
// cy.get(this.kerberosCacheDayInput).click();
// // cy.get(this.kerberosCacheDayInput).contains(day).click();
// cy.get(this.kerberosCacheDayInput).contains().click();
// }
if (hour) {
cy.get(this.kerberosCacheHourInput).click();
cy.get(this.kerberosCacheHourInput).contains(hour).click();
}
if (minute) {
cy.get(this.kerberosCacheMinuteInput).click();
cy.get(this.kerberosCacheMinuteInput).contains(minute).click();
}
return this;
disableEnabledSwitch() {
cy.get(this.kerberosEnabledInput).uncheck({ force: true });
}
// checkRealmRoleNameRequiredMessage(exist = true) {
// cy.get(this.realmRoleNameError).should((!exist ? "not." : "") + "exist");
// return this;
// }
//#endregion
enableEnabledSwitch() {
cy.get(this.kerberosEnabledInput).check({ force: true });
}
save() {
cy.get(`[${this.saveBtn}]`).click();
return this;
}
cancel() {
cy.get(this.cancelBtn).click();
cy.get(`[${this.cancelBtn}]`).click();
return this;
}
}