keycloak-scim/apps/admin-ui/cypress/e2e/identity_providers_test.spec.ts
2022-09-05 10:46:39 +02:00

282 lines
11 KiB
TypeScript

import Masthead from "../support/pages/admin_console/Masthead";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import ListingPage from "../support/pages/admin_console/ListingPage";
import CreateProviderPage from "../support/pages/admin_console/manage/identity_providers/CreateProviderPage";
import ModalUtils from "../support/util/ModalUtils";
import OrderDialog from "../support/pages/admin_console/manage/identity_providers/OrderDialog";
import AddMapperPage from "../support/pages/admin_console/manage/identity_providers/AddMapperPage";
import ProviderFacebookGeneralSettings from "../support/pages/admin_console/manage/identity_providers/social/ProviderFacebookGeneralSettings";
import ProviderBaseGeneralSettingsPage from "../support/pages/admin_console/manage/identity_providers/ProviderBaseGeneralSettingsPage";
import ProviderGithubGeneralSettings from "../support/pages/admin_console/manage/identity_providers/social/ProviderGithubGeneralSettings";
import ProviderGoogleGeneralSettings from "../support/pages/admin_console/manage/identity_providers/social/ProviderGoogleGeneralSettings";
import ProviderOpenshiftGeneralSettings from "../support/pages/admin_console/manage/identity_providers/social/ProviderOpenshiftGeneralSettings";
import ProviderPaypalGeneralSettings from "../support/pages/admin_console/manage/identity_providers/social/ProviderPaypalGeneralSettings";
import ProviderStackoverflowGeneralSettings from "../support/pages/admin_console/manage/identity_providers/social/ProviderStackoverflowGeneralSettings";
import adminClient from "../support/util/AdminClient";
import GroupPage from "../support/pages/admin_console/manage/groups/GroupPage";
import CommonPage from "../support/pages/CommonPage";
describe("Identity provider test", () => {
const loginPage = new LoginPage();
const sidebarPage = new SidebarPage();
const masthead = new Masthead();
const listingPage = new ListingPage();
const createProviderPage = new CreateProviderPage();
const addMapperPage = new AddMapperPage();
const groupPage = new GroupPage();
const commonPage = new CommonPage();
const createSuccessMsg = "Identity provider successfully created";
const createFailMsg =
"Could not create the identity provider: Identity Provider github already exists";
const createMapperSuccessMsg = "Mapper created successfully.";
const changeSuccessMsg =
"Successfully changed display order of identity providers";
const deletePrompt = "Delete provider?";
const deleteSuccessMsg = "Provider successfully deleted.";
beforeEach(() => {
keycloakBefore();
loginPage.logIn();
sidebarPage.goToIdentityProviders();
});
const socialLoginIdentityProvidersWithCustomFiels = {
Facebook: new ProviderFacebookGeneralSettings(),
Github: new ProviderGithubGeneralSettings(),
Google: new ProviderGoogleGeneralSettings(),
"Openshift-v3": new ProviderOpenshiftGeneralSettings(),
"Openshift-v4": new ProviderOpenshiftGeneralSettings(),
Paypal: new ProviderPaypalGeneralSettings(),
Stackoverflow: new ProviderStackoverflowGeneralSettings(),
};
function getSocialIdpClassInstance(idpTestName: string) {
let instance = new ProviderBaseGeneralSettingsPage();
Object.entries(socialLoginIdentityProvidersWithCustomFiels).find(
([key, value]) => {
if (key === idpTestName) {
instance = value;
return true;
}
return false;
}
);
return instance;
}
describe("Identity provider creation", () => {
const identityProviderName = "github";
describe("Custom fields tests", () => {
const socialLoginIdentityProviders = [
{ testName: "Bitbucket", displayName: "BitBucket", alias: "bitbucket" },
{ testName: "Facebook", displayName: "Facebook", alias: "facebook" },
{ testName: "Github", displayName: "GitHub", alias: "github" },
{ testName: "Gitlab", displayName: "Gitlab", alias: "gitlab" },
{ testName: "Google", displayName: "Google", alias: "google" },
{ testName: "Instagram", displayName: "Instagram", alias: "instagram" },
{ testName: "Linkedin", displayName: "LinkedIn", alias: "linkedin" },
{ testName: "Microsoft", displayName: "Microsoft", alias: "microsoft" },
{
testName: "Openshift-v3",
displayName: "Openshift v3",
alias: "openshift-v3",
},
{
testName: "Openshift-v4",
displayName: "Openshift v4",
alias: "openshift-v4",
},
{ testName: "Paypal", displayName: "PayPal", alias: "paypal" },
{
testName: "Stackoverflow",
displayName: "StackOverflow",
alias: "stackoverflow",
},
{ testName: "Twitter", displayName: "Twitter", alias: "twitter" },
];
after(async () => {
await Promise.all(
socialLoginIdentityProviders.map((idp) =>
adminClient.deleteIdentityProvider(idp.alias)
)
);
});
socialLoginIdentityProviders.forEach(($idp, linkedIdpsCount) => {
it(`should create social login provider ${$idp.testName} with custom fields`, () => {
if (linkedIdpsCount == 0) {
createProviderPage.clickCard($idp.alias);
} else {
createProviderPage.clickCreateDropdown().clickItem($idp.alias);
}
const instance = getSocialIdpClassInstance($idp.testName);
instance
.typeDisplayOrder("0")
.clickAdd()
.assertRequiredFieldsErrorsExist()
.fillData($idp.testName)
.clickAdd()
.assertNotificationIdpCreated()
.assertFilledDataEqual($idp.testName);
});
});
});
it("should create github provider", () => {
createProviderPage.checkGitHubCardVisible().clickGitHubCard();
createProviderPage.checkAddButtonDisabled();
createProviderPage
.fill(identityProviderName)
.clickAdd()
.checkClientIdRequiredMessage(true);
createProviderPage.fill(identityProviderName, "123").clickAdd();
masthead.checkNotificationMessage(createSuccessMsg, true);
sidebarPage.goToIdentityProviders();
listingPage.itemExist(identityProviderName);
});
it("fail to make duplicate github provider", () => {
createProviderPage
.clickCreateDropdown()
.clickItem("github")
.fill("github2", "123")
.clickAdd();
masthead.checkNotificationMessage(createFailMsg, true);
});
it("should create facebook provider", () => {
createProviderPage
.clickCreateDropdown()
.clickItem("facebook")
.fill("facebook", "123")
.clickAdd();
masthead.checkNotificationMessage(createSuccessMsg, true);
});
it("search for existing provider by name", () => {
sidebarPage.goToIdentityProviders();
listingPage.searchItem(identityProviderName, false);
listingPage.itemExist(identityProviderName, true);
});
it("search for non-existing provider by name", () => {
sidebarPage.goToIdentityProviders();
listingPage.searchItem("not-existing-provider", false);
groupPage.assertNoSearchResultsMessageExist(true);
});
it("create and delete provider by item details", () => {
createProviderPage
.clickCreateDropdown()
.clickItem("linkedin")
.fill("linkedin", "123")
.clickAdd();
masthead.checkNotificationMessage(createSuccessMsg, true);
commonPage
.actionToolbarUtils()
.clickActionToggleButton()
.clickDropdownItem("Delete");
const modalUtils = new ModalUtils();
modalUtils.checkModalTitle(deletePrompt).confirmModal();
masthead.checkNotificationMessage(deleteSuccessMsg, true);
});
it.skip("should change order of providers", () => {
const orderDialog = new OrderDialog();
const providers = [identityProviderName, "facebook", "bitbucket"];
sidebarPage.goToIdentityProviders();
listingPage.itemExist("facebook");
sidebarPage.goToIdentityProviders();
listingPage.itemExist(identityProviderName);
createProviderPage
.clickCreateDropdown()
.clickItem("bitbucket")
.fill("bitbucket", "123")
.clickAdd();
masthead.checkNotificationMessage(createSuccessMsg, true);
cy.wait(2000);
sidebarPage.goToIdentityProviders();
listingPage.itemExist(identityProviderName);
orderDialog.openDialog().checkOrder(providers);
orderDialog.moveRowTo("facebook", identityProviderName);
orderDialog.checkOrder(["bitbucket", identityProviderName, "facebook"]);
orderDialog.clickSave();
masthead.checkNotificationMessage(changeSuccessMsg);
});
it("should delete provider", () => {
const modalUtils = new ModalUtils();
listingPage.deleteItem(identityProviderName);
modalUtils.checkModalTitle(deletePrompt).confirmModal();
masthead.checkNotificationMessage(deleteSuccessMsg, true);
});
it("should add facebook social mapper", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("facebook");
addMapperPage.goToMappersTab();
addMapperPage.emptyStateAddMapper();
addMapperPage.fillSocialMapper("facebook mapper");
// addMapperPage.saveNewMapper();
masthead.checkNotificationMessage(createMapperSuccessMsg, true);
});
it("should add Social mapper of type Attribute Importer", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("facebook");
addMapperPage.goToMappersTab();
addMapperPage.addMapper();
addMapperPage.fillSocialMapper("facebook attribute importer");
masthead.checkNotificationMessage(createMapperSuccessMsg, true);
});
it("should edit facebook mapper", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("facebook");
addMapperPage.goToMappersTab();
listingPage.goToItemDetails("facebook attribute importer");
addMapperPage.editSocialMapper();
});
it("should delete facebook mapper", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("facebook");
addMapperPage.goToMappersTab();
listingPage.deleteItem("facebook attribute importer");
cy.findByTestId("confirm").click();
});
it("clean up providers", () => {
const modalUtils = new ModalUtils();
// TODO: Re-enable this code when the 'should change order of providers' is no longer skipped.
// sidebarPage.goToIdentityProviders();
// listingPage.itemExist("bitbucket").deleteItem("bitbucket");
// modalUtils.checkModalTitle(deletePrompt).confirmModal();
// masthead.checkNotificationMessage(deleteSuccessMsg, true);
sidebarPage.goToIdentityProviders();
listingPage.itemExist("facebook").deleteItem("facebook");
modalUtils.checkModalTitle(deletePrompt).confirmModal();
masthead.checkNotificationMessage(deleteSuccessMsg, true);
});
});
});