Cypress tests for initial 8 LDAP mappers (#550)

* create delete all mapper types working

* all tests working
This commit is contained in:
mfrances17 2021-04-28 01:50:41 -04:00 committed by GitHub
parent 9e4d1d34ee
commit aa7d2049d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 438 additions and 15 deletions

View file

@ -0,0 +1,276 @@
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import ListingPage from "../support/pages/admin_console/ListingPage";
import GroupModal from "../support/pages/admin_console/manage/groups/GroupModal";
import ProviderPage from "../support/pages/admin_console/manage/providers/ProviderPage";
import Masthead from "../support/pages/admin_console/Masthead";
import ModalUtils from "../support/util/ModalUtils";
import { keycloakBefore } from "../support/util/keycloak_before";
const loginPage = new LoginPage();
const masthead = new Masthead();
const sidebarPage = new SidebarPage();
const listingPage = new ListingPage();
const groupModal = new GroupModal();
const providersPage = new ProviderPage();
const modalUtils = new ModalUtils();
const provider = "ldap";
const allCapProvider = provider.toUpperCase();
const ldapName = "ldap-mappers-testing";
const ldapVendor = "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 addProviderMenu = "Add new provider";
const providerCreatedSuccess = "User federation provider successfully created";
const mapperCreatedSuccess = "Mapping successfully created";
const mapperUpdatedSuccess = "Mapping successfully updated";
const providerDeleteSuccess = "The user federation provider has been deleted.";
const providerDeleteTitle = "Delete user federation provider?";
const mapperDeletedSuccess = "Mapping successfully deleted";
const mapperDeleteTitle = "Delete mapping?";
const groupName = "my-mappers-group";
// mapperType variables
const msadUserAcctMapper = "msad-user-account-control-mapper";
const msadLdsUserAcctMapper = "msad-lds-user-account-control-mapper";
const userAttLdapMapper = "user-attribute-ldap-mapper";
const hcAttMapper = "hardcoded-attribute-mapper";
const certLdapMapper = "certificate-ldap-mapper";
const fullNameLdapMapper = "full-name-ldap-mapper";
const hcLdapGroupMapper = "hardcoded-ldap-group-mapper";
const hcLdapAttMapper = "hardcoded-ldap-attribute-mapper";
// const groupLdapMapper = "group-ldap-mapper";
// const roleMapper = "role-ldap-mapper";
// const hcLdapRoleMapper = "hardcoded-ldap-role-mapper";
const creationDateMapper = "creation date";
const emailMapper = "email";
const lastNameMapper = "last name";
const modifyDateMapper = "modify date";
const usernameMapper = "username";
const firstNameMapper = "first name";
const MsadAccountControlsMapper = "MSAD account controls";
describe("User Fed LDAP mapper tests", () => {
beforeEach(() => {
keycloakBefore();
loginPage.logIn();
sidebarPage.goToUserFederation();
});
it("Create LDAP provider from empty state", () => {
// if tests don't start at empty state, e.g. user has providers configured locally,
// create a new card from the card view instead
cy.get("body").then(($body) => {
if ($body.find(`[data-testid=ldap-card]`).length > 0) {
providersPage.clickNewCard(provider);
} else {
providersPage.clickMenuCommand(addProviderMenu, allCapProvider);
}
});
providersPage.fillLdapRequiredGeneralData(ldapName, ldapVendor);
providersPage.fillLdapRequiredConnectionData(
connectionUrl,
firstBindType,
firstBindDn,
firstBindCreds
);
providersPage.fillLdapRequiredSearchingData(
firstUsersDn,
firstUserLdapAtt,
firstRdnLdapAtt,
firstUuidLdapAtt,
firstUserObjClasses
);
providersPage.save(provider);
masthead.checkNotificationMessage(providerCreatedSuccess);
sidebarPage.goToUserFederation();
});
// create a new group
it("Create group", () => {
sidebarPage.goToGroups();
groupModal
.open("empty-primary-action")
.fillGroupForm(groupName)
.clickCreate();
masthead.checkNotificationMessage("Group created");
});
// delete default mappers
it("Delete default mappers", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
listingPage.itemExist(creationDateMapper).deleteItem(creationDateMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
listingPage.itemExist(creationDateMapper, false);
listingPage.itemExist(emailMapper).deleteItem(emailMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
listingPage.itemExist(emailMapper, false);
listingPage.itemExist(lastNameMapper).deleteItem(lastNameMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
listingPage.itemExist(lastNameMapper, false);
listingPage.itemExist(modifyDateMapper).deleteItem(modifyDateMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
listingPage.itemExist(modifyDateMapper, false);
listingPage.itemExist(usernameMapper).deleteItem(usernameMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
listingPage.itemExist(usernameMapper, false);
listingPage.itemExist(firstNameMapper).deleteItem(firstNameMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
listingPage.itemExist(firstNameMapper, false);
listingPage
.itemExist(MsadAccountControlsMapper)
.deleteItem(MsadAccountControlsMapper);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
});
// create mapper
it("Create certificate ldap mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(certLdapMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(certLdapMapper, true);
});
// update mapper
it("Update certificate ldap mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
listingPage.goToItemDetails(`${certLdapMapper}-test`);
providersPage.updateMapper(certLdapMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperUpdatedSuccess);
});
// delete mapper
it("Delete certificate ldap mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
listingPage.deleteItem(`${certLdapMapper}-test`);
modalUtils.checkModalTitle(mapperDeleteTitle).confirmModal();
masthead.checkNotificationMessage(mapperDeletedSuccess);
});
// create one of every kind of non-group/role mapper (8)
it("Create user account control mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(msadUserAcctMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(msadUserAcctMapper, true);
});
it("Create msad lds user account control mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(msadLdsUserAcctMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(msadLdsUserAcctMapper, true);
});
it("Create certificate ldap mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(certLdapMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(certLdapMapper, true);
});
it("Create user attribute ldap mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(userAttLdapMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(userAttLdapMapper, true);
});
it("Create hardcoded attribute mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(hcAttMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(hcAttMapper, true);
});
it("Create full name ldap mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(fullNameLdapMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(fullNameLdapMapper, true);
});
it("Create hardcoded ldap group mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(hcLdapGroupMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(hcLdapGroupMapper, true);
});
it("Create hardcoded ldap attribute mapper", () => {
providersPage.clickExistingCard(ldapName);
providersPage.goToMappers();
providersPage.createNewMapper(hcLdapAttMapper);
providersPage.save("ldap-mapper");
masthead.checkNotificationMessage(mapperCreatedSuccess);
listingPage.itemExist(hcLdapAttMapper, true);
});
// *** test cleanup ***
it("Cleanup - delete group", () => {
sidebarPage.goToGroups();
listingPage.deleteItem(groupName);
masthead.checkNotificationMessage("Group deleted");
});
it("Cleanup - delete LDAP provider", () => {
providersPage.deleteCardFromMenu(provider, ldapName);
modalUtils.checkModalTitle(providerDeleteTitle).confirmModal();
masthead.checkNotificationMessage(providerDeleteSuccess);
});
});

View file

@ -29,6 +29,29 @@ export default class ProviderPage {
cachePolicyInput: string; cachePolicyInput: string;
cachePolicyList: string; cachePolicyList: string;
userModelAttInput: string;
ldapAttInput: string;
userModelAttNameInput: string;
attValueInput: string;
ldapFullNameAttInput: string;
ldapAttNameInput: string;
ldapAttValueInput: string;
groupInput: string;
msadUserAcctMapper: string;
msadLdsUserAcctMapper: string;
userAttLdapMapper: string;
hcAttMapper: string;
certLdapMapper: string;
fullNameLdapMapper: string;
hcLdapAttMapper: string;
hcLdapGroupMapper: string;
// roleMapper: string;
// groupLdapMapper: string;
// hcLdapRoleMapper string;
groupName: string;
constructor() { constructor() {
// KerberosSettingsRequired required input values // KerberosSettingsRequired required input values
this.kerberosNameInput = "data-testid=kerberos-name"; this.kerberosNameInput = "data-testid=kerberos-name";
@ -64,6 +87,32 @@ export default class ProviderPage {
this.cacheMinuteList = "#kc-eviction-minute + ul"; this.cacheMinuteList = "#kc-eviction-minute + ul";
this.cachePolicyInput = "#kc-cache-policy"; this.cachePolicyInput = "#kc-cache-policy";
this.cachePolicyList = "#kc-cache-policy + ul"; this.cachePolicyList = "#kc-cache-policy + ul";
// Mapper required input values
this.userModelAttInput = "data-testid=mapper-userModelAttribute-fld";
this.ldapAttInput = "data-testid=mapper-ldapAttribute-fld";
this.userModelAttNameInput =
"data-testid=mapper-userModelAttributeName-fld";
this.attValueInput = "data-testid=mapper-attributeValue-fld";
this.ldapFullNameAttInput = "data-testid=mapper-fullNameAttribute-fld";
this.ldapAttNameInput = "data-testid=mapper-ldapAttributeName-fld";
this.ldapAttValueInput = "data-testid=mapper-ldapAttributeValue-fld";
this.groupInput = "data-testid=mapper-group-fld";
// mapper types
this.msadUserAcctMapper = "msad-user-account-control-mapper";
this.msadLdsUserAcctMapper = "msad-lds-user-account-control-mapper";
this.userAttLdapMapper = "user-attribute-ldap-mapper";
this.hcAttMapper = "hardcoded-attribute-mapper";
this.certLdapMapper = "certificate-ldap-mapper";
this.fullNameLdapMapper = "full-name-ldap-mapper";
this.hcLdapAttMapper = "hardcoded-ldap-attribute-mapper";
this.hcLdapGroupMapper = "hardcoded-ldap-group-mapper";
// this.groupLdapMapper = "group-ldap-mapper";
// this.roleMapper = "role-ldap-mapper";
// this.hcLdapRoleMapper = "hardcoded-ldap-role-mapper";
this.groupName = "my-mappers-group";
} }
changeCacheTime(unit: string, time: string) { changeCacheTime(unit: string, time: string) {
@ -99,7 +148,7 @@ export default class ProviderPage {
cy.get(`[data-testid="delete-${providerType}-cmd"]`).click(); cy.get(`[data-testid="delete-${providerType}-cmd"]`).click();
return this; return this;
} }
fillKerberosRequiredData( fillKerberosRequiredData(
name: string, name: string,
realm: string, realm: string,
@ -185,6 +234,102 @@ export default class ProviderPage {
return this; return this;
} }
goToMappers() {
cy.get(`[data-testid="ldap-mappers-tab"]`).click();
}
createNewMapper(mapperType: string) {
const userModelAttValue = "firstName";
const ldapAttValue = "cn";
cy.get(`[data-testid="add-mapper-btn"]`).click();
cy.wait(1000);
cy.get("#kc-providerId").click();
cy.get("#kc-providerId + ul").contains(mapperType).click();
cy.get(`[data-testid="ldap-mapper-name"]`).type(`${mapperType}-test`);
switch (mapperType) {
case this.msadUserAcctMapper:
case this.msadLdsUserAcctMapper:
break;
case this.userAttLdapMapper:
case this.certLdapMapper:
cy.get(`[${this.userModelAttInput}]`).type(userModelAttValue);
cy.get(`[${this.ldapAttInput}]`).type(ldapAttValue);
break;
case this.hcAttMapper:
cy.get(`[${this.userModelAttNameInput}]`).type(userModelAttValue);
cy.get(`[${this.attValueInput}]`).type(ldapAttValue);
break;
case this.fullNameLdapMapper:
cy.get(`[${this.ldapFullNameAttInput}]`).type(ldapAttValue);
break;
case this.hcLdapAttMapper:
cy.get(`[${this.ldapAttNameInput}]`).type(userModelAttValue);
cy.get(`[${this.ldapAttValueInput}]`).type(ldapAttValue);
break;
case this.hcLdapGroupMapper:
cy.get(`[${this.groupInput}]`).type(this.groupName);
break;
// case this.groupLdapMapper:
// break;
// case this.roleMapper:
// break;
// case this.hcLdapRoleMapper:
// break;
default:
console.log("Invalid mapper type.");
break;
}
}
updateMapper(mapperType: string) {
const userModelAttValue = "lastName";
const ldapAttValue = "sn";
switch (mapperType) {
case this.msadUserAcctMapper:
case this.msadLdsUserAcctMapper:
break;
case this.userAttLdapMapper:
case this.certLdapMapper:
cy.get(`[${this.userModelAttInput}]`).clear();
cy.get(`[${this.userModelAttInput}]`).type(userModelAttValue);
cy.get(`[${this.ldapAttInput}]`).clear();
cy.get(`[${this.ldapAttInput}]`).type(ldapAttValue);
break;
case this.hcAttMapper:
cy.get(`[${this.userModelAttNameInput}]`).clear();
cy.get(`[${this.userModelAttNameInput}]`).type(userModelAttValue);
cy.get(`[${this.attValueInput}]`).clear();
cy.get(`[${this.attValueInput}]`).type(ldapAttValue);
break;
case this.fullNameLdapMapper:
cy.get(`[${this.ldapFullNameAttInput}]`).clear();
cy.get(`[${this.ldapFullNameAttInput}]`).type(ldapAttValue);
break;
case this.hcLdapAttMapper:
cy.get(`[${this.ldapAttNameInput}]`).clear();
cy.get(`[${this.ldapAttNameInput}]`).type(userModelAttValue);
cy.get(`[${this.ldapAttValueInput}]`).clear;
cy.get(`[${this.ldapAttValueInput}]`).type(ldapAttValue);
break;
// case this.hcLdapGroupMapper:
// break;
// case this.groupLdapMapper:
// break;
// case this.roleMapper:
// break;
// case this.hcLdapRoleMapper:
// break;
default:
console.log("Invalid mapper name.");
break;
}
}
clickExistingCard(cardName: string) { clickExistingCard(cardName: string) {
cy.get('[data-testid="keycloak-card-title"]').contains(cardName).click(); cy.get('[data-testid="keycloak-card-title"]').contains(cardName).click();
cy.wait(1000); cy.wait(1000);

View file

@ -325,6 +325,7 @@ export const UserFederationLdapSettings = () => {
id="mappers" id="mappers"
eventKey="mappers" eventKey="mappers"
title={<TabTitleText>{t("common:mappers")}</TabTitleText>} title={<TabTitleText>{t("common:mappers")}</TabTitleText>}
data-testid="ldap-mappers-tab"
> >
<LdapMapperList /> <LdapMapperList />
</Tab> </Tab>

View file

@ -165,7 +165,7 @@ export const LdapMapperDetails = () => {
defaultValue={isNew ? id : mapping ? mapping.parentId : ""} defaultValue={isNew ? id : mapping ? mapping.parentId : ""}
type="text" type="text"
id="kc-ldap-parentId" id="kc-ldap-parentId"
data-testid="ldap-parentId" data-testid="ldap-mapper-parentId"
name="parentId" name="parentId"
ref={form.register} ref={form.register}
/> />
@ -174,7 +174,7 @@ export const LdapMapperDetails = () => {
defaultValue="org.keycloak.storage.ldap.mappers.LDAPStorageMapper" defaultValue="org.keycloak.storage.ldap.mappers.LDAPStorageMapper"
type="text" type="text"
id="kc-ldap-provider-type" id="kc-ldap-provider-type"
data-testid="ldap-provider-type" data-testid="ldap-mapper-provider-type"
name="providerType" name="providerType"
ref={form.register} ref={form.register}
/> />
@ -197,7 +197,7 @@ export const LdapMapperDetails = () => {
isRequired isRequired
type="text" type="text"
id="kc-ldap-mapper-type" id="kc-ldap-mapper-type"
data-testid="ldap-mapper-type" data-testid="ldap-mapper-type-fld"
name="providerId" name="providerId"
ref={form.register} ref={form.register}
/> />
@ -219,6 +219,7 @@ export const LdapMapperDetails = () => {
name="providerId" name="providerId"
defaultValue=" " defaultValue=" "
control={form.control} control={form.control}
data-testid="ldap-mapper-type-select"
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<Select <Select
toggleId="kc-providerId" toggleId="kc-providerId"
@ -366,7 +367,7 @@ export const LdapMapperDetails = () => {
isDisabled={!form.formState.isDirty} isDisabled={!form.formState.isDirty}
variant="primary" variant="primary"
type="submit" type="submit"
data-testid="ldap-save" data-testid="ldap-mapper-save"
> >
{t("common:save")} {t("common:save")}
</Button> </Button>
@ -381,7 +382,7 @@ export const LdapMapperDetails = () => {
}/mappers` }/mappers`
) )
} }
data-testid="ldap-cancel" data-testid="ldap-mapper-cancel"
> >
{t("common:cancel")} {t("common:cancel")}
</Button> </Button>

View file

@ -32,7 +32,7 @@ export const LdapMapperFullNameAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-full-name-attribute" id="kc-full-name-attribute"
data-testid="full-name-attribute" data-testid="mapper-fullNameAttribute-fld"
name="config.ldap-full-name-attribute[0]" name="config.ldap-full-name-attribute[0]"
ref={form.register} ref={form.register}
/> />

View file

@ -32,7 +32,7 @@ export const LdapMapperHardcodedAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-user-model-attribute" id="kc-user-model-attribute"
data-testid="user-model-attribute" data-testid="mapper-userModelAttributeName-fld"
name="config.user-model-attribute[0]" name="config.user-model-attribute[0]"
ref={form.register} ref={form.register}
/> />
@ -53,7 +53,7 @@ export const LdapMapperHardcodedAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-attribute-value" id="kc-attribute-value"
data-testid="attribute-value" data-testid="mapper-attributeValue-fld"
name="config.attribute-value[0]" name="config.attribute-value[0]"
ref={form.register} ref={form.register}
/> />

View file

@ -32,7 +32,7 @@ export const LdapMapperHardcodedLdapAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-ldap-attribute-name" id="kc-ldap-attribute-name"
data-testid="ldap-attribute-name" data-testid="mapper-ldapAttributeName-fld"
name="config.ldap-attribute-name[0]" name="config.ldap-attribute-name[0]"
ref={form.register} ref={form.register}
/> />
@ -53,7 +53,7 @@ export const LdapMapperHardcodedLdapAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-ldap-attribute-value" id="kc-ldap-attribute-value"
data-testid="ldap-attribute-value" data-testid="mapper-ldapAttributeValue-fld"
name="config.ldap-attribute-value[0]" name="config.ldap-attribute-value[0]"
ref={form.register} ref={form.register}
/> />

View file

@ -32,7 +32,7 @@ export const LdapMapperHardcodedLdapGroup = ({
isRequired isRequired
type="text" type="text"
id="kc-group" id="kc-group"
data-testid="group" data-testid="mapper-group-fld"
name="config.group[0]" name="config.group[0]"
ref={form.register} ref={form.register}
/> />

View file

@ -96,7 +96,7 @@ export const LdapMapperList = () => {
toolbarItem={ toolbarItem={
<ToolbarItem> <ToolbarItem>
<Button <Button
data-testid="createMapperBtn" data-testid="add-mapper-btn"
variant="primary" variant="primary"
onClick={() => history.push(`${url}/new`)} onClick={() => history.push(`${url}/new`)}
> >

View file

@ -34,7 +34,7 @@ export const LdapMapperUserAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-user-model-attribute" id="kc-user-model-attribute"
data-testid="user-model-attribute" data-testid="mapper-userModelAttribute-fld"
name="config.user-model-attribute[0]" name="config.user-model-attribute[0]"
ref={form.register} ref={form.register}
/> />
@ -55,7 +55,7 @@ export const LdapMapperUserAttribute = ({
isRequired isRequired
type="text" type="text"
id="kc-ldap-attribute" id="kc-ldap-attribute"
data-testid="ldap-attribute" data-testid="mapper-ldapAttribute-fld"
name="config.ldap-attribute[0]" name="config.ldap-attribute[0]"
ref={form.register} ref={form.register}
/> />