2021-01-27 12:56:28 +00:00
|
|
|
import LoginPage from "../support/pages/LoginPage";
|
|
|
|
import Masthead from "../support/pages/admin_console/Masthead";
|
|
|
|
import ModalUtils from "../support/util/ModalUtils";
|
|
|
|
import ListingPage from "../support/pages/admin_console/ListingPage";
|
|
|
|
import SidebarPage from "../support/pages/admin_console/SidebarPage";
|
|
|
|
import CreateRealmRolePage from "../support/pages/admin_console/manage/realm_roles/CreateRealmRolePage";
|
2021-03-03 14:55:19 +00:00
|
|
|
import AssociatedRolesPage from "../support/pages/admin_console/manage/realm_roles/AssociatedRolesPage";
|
2022-03-09 16:42:51 +00:00
|
|
|
import { keycloakBefore } from "../support/util/keycloak_hooks";
|
2022-02-24 10:31:46 +00:00
|
|
|
import adminClient from "../support/util/AdminClient";
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2021-01-27 12:47:57 +00:00
|
|
|
let itemId = "realm_role_crud";
|
|
|
|
const loginPage = new LoginPage();
|
|
|
|
const masthead = new Masthead();
|
|
|
|
const modalUtils = new ModalUtils();
|
|
|
|
const sidebarPage = new SidebarPage();
|
|
|
|
const listingPage = new ListingPage();
|
|
|
|
const createRealmRolePage = new CreateRealmRolePage();
|
2021-03-03 14:55:19 +00:00
|
|
|
const associatedRolesPage = new AssociatedRolesPage();
|
2021-01-27 12:47:57 +00:00
|
|
|
|
2021-10-04 06:03:19 +00:00
|
|
|
describe("Realm roles test", () => {
|
2022-02-23 11:05:38 +00:00
|
|
|
before(() => {
|
|
|
|
keycloakBefore();
|
|
|
|
loginPage.logIn();
|
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
sidebarPage.goToRealmRoles();
|
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("should fail creating realm role", () => {
|
|
|
|
listingPage.goToCreateItem();
|
|
|
|
createRealmRolePage.save().checkRealmRoleNameRequiredMessage();
|
|
|
|
createRealmRolePage.fillRealmRoleData("admin").save();
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
// 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",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("shouldn't create a realm role based with only whitespace name", () => {
|
|
|
|
listingPage.goToCreateItem();
|
|
|
|
createRealmRolePage
|
|
|
|
.fillRealmRoleData(" ")
|
|
|
|
.checkRealmRoleNameRequiredMessage();
|
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("Realm role CRUD test", () => {
|
|
|
|
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
// Create
|
|
|
|
listingPage.itemExist(itemId, false).goToCreateItem();
|
|
|
|
createRealmRolePage.fillRealmRoleData(itemId).save();
|
|
|
|
masthead.checkNotificationMessage("Role created", true);
|
|
|
|
sidebarPage.goToRealmRoles();
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-03-06 15:25:37 +00:00
|
|
|
const fetchUrl = "/admin/realms/master/roles?first=0&max=11";
|
2022-02-23 11:05:38 +00:00
|
|
|
cy.intercept(fetchUrl).as("fetch");
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
listingPage.deleteItem(itemId);
|
2021-01-27 12:56:28 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
cy.wait(["@fetch"]);
|
|
|
|
modalUtils.checkModalTitle("Delete role?").confirmModal();
|
|
|
|
masthead.checkNotificationMessage("The role has been deleted", true);
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
listingPage.itemExist(itemId, false);
|
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("should delete role from details action", () => {
|
|
|
|
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
|
|
|
listingPage.goToCreateItem();
|
|
|
|
createRealmRolePage.fillRealmRoleData(itemId).save();
|
|
|
|
masthead.checkNotificationMessage("Role created", true);
|
|
|
|
createRealmRolePage.clickActionMenu("Delete this role");
|
|
|
|
modalUtils.confirmModal();
|
|
|
|
masthead.checkNotificationMessage("The role has been deleted", true);
|
|
|
|
});
|
2021-02-04 20:50:13 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("should not be able to delete default role", () => {
|
|
|
|
const defaultRole = "default-roles-master";
|
|
|
|
listingPage.itemExist(defaultRole).deleteItem(defaultRole);
|
|
|
|
masthead.checkNotificationMessage(
|
|
|
|
"You cannot delete a default role.",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
});
|
2021-02-04 20:50:13 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("Associated roles test", () => {
|
|
|
|
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
2021-02-04 20:50:13 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
// Create
|
|
|
|
listingPage.itemExist(itemId, false).goToCreateItem();
|
|
|
|
createRealmRolePage.fillRealmRoleData(itemId).save();
|
|
|
|
masthead.checkNotificationMessage("Role created", true);
|
2021-02-04 20:50:13 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
// Add associated realm role
|
2022-03-09 16:41:45 +00:00
|
|
|
associatedRolesPage.addAssociatedRealmRole("create-realm");
|
2022-02-23 11:05:38 +00:00
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
2021-02-04 20:50:13 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
// Add associated client role
|
2022-03-09 16:41:45 +00:00
|
|
|
associatedRolesPage.addAssociatedClientRole("manage-account");
|
2022-02-23 11:05:38 +00:00
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
|
|
|
});
|
2021-02-23 13:36:37 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
describe("edit role details", () => {
|
|
|
|
const editRoleName = "going to edit";
|
|
|
|
const description = "some description";
|
2022-03-03 07:45:44 +00:00
|
|
|
before(() =>
|
2022-02-23 11:05:38 +00:00
|
|
|
adminClient.createRealmRole({
|
|
|
|
name: editRoleName,
|
|
|
|
description,
|
2022-03-03 07:45:44 +00:00
|
|
|
})
|
|
|
|
);
|
2021-02-25 09:10:28 +00:00
|
|
|
|
2022-03-03 07:45:44 +00:00
|
|
|
after(() => adminClient.deleteRealmRole(editRoleName));
|
2021-02-23 13:36:37 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("should edit realm role details", () => {
|
|
|
|
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
|
|
|
|
createRealmRolePage.checkNameDisabled().checkDescription(description);
|
|
|
|
const updateDescription = "updated description";
|
|
|
|
createRealmRolePage.updateDescription(updateDescription).save();
|
|
|
|
masthead.checkNotificationMessage("The role has been saved", true);
|
|
|
|
createRealmRolePage.checkDescription(updateDescription);
|
2021-02-04 20:50:13 +00:00
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
});
|
|
|
|
});
|