2023-06-20 12:21:49 +00:00
|
|
|
import { v4 as uuid } from "uuid";
|
2021-01-27 12:56:28 +00:00
|
|
|
import LoginPage from "../support/pages/LoginPage";
|
2022-12-07 15:28:28 +00:00
|
|
|
import Masthead from "../support/pages/admin-ui/Masthead";
|
2021-01-27 12:56:28 +00:00
|
|
|
import ModalUtils from "../support/util/ModalUtils";
|
2022-12-07 15:28:28 +00:00
|
|
|
import ListingPage from "../support/pages/admin-ui/ListingPage";
|
|
|
|
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
|
|
|
|
import createRealmRolePage from "../support/pages/admin-ui/manage/realm_roles/CreateRealmRolePage";
|
|
|
|
import AssociatedRolesPage from "../support/pages/admin-ui/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";
|
2022-12-07 15:28:28 +00:00
|
|
|
import ClientRolesTab from "../support/pages/admin-ui/manage/clients/ClientRolesTab";
|
|
|
|
import KeyValueInput from "../support/pages/admin-ui/manage/KeyValueInput";
|
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();
|
2021-03-03 14:55:19 +00:00
|
|
|
const associatedRolesPage = new AssociatedRolesPage();
|
2022-03-29 10:39:32 +00:00
|
|
|
const rolesTab = new ClientRolesTab();
|
2021-01-27 12:47:57 +00:00
|
|
|
|
2021-10-04 06:03:19 +00:00
|
|
|
describe("Realm roles test", () => {
|
2022-10-06 14:18:33 +00:00
|
|
|
beforeEach(() => {
|
2022-02-23 11:05:38 +00:00
|
|
|
loginPage.logIn();
|
2023-02-10 10:10:35 +00:00
|
|
|
keycloakBefore();
|
2022-02-23 11:05:38 +00:00
|
|
|
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",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-02-23 11:05:38 +00:00
|
|
|
);
|
|
|
|
});
|
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", () => {
|
2023-06-20 12:21:49 +00:00
|
|
|
itemId += "_" + uuid();
|
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);
|
2022-03-29 10:39:32 +00:00
|
|
|
|
|
|
|
itemId = "realm_role_crud";
|
2022-02-23 11:05:38 +00:00
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
it("should delete role from details action", () => {
|
2023-06-20 12:21:49 +00:00
|
|
|
itemId += "_" + uuid();
|
2022-02-23 11:05:38 +00:00
|
|
|
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);
|
2022-03-29 10:39:32 +00:00
|
|
|
itemId = "realm_role_crud";
|
2022-02-23 11:05:38 +00:00
|
|
|
});
|
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.",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-02-23 11:05:38 +00:00
|
|
|
);
|
|
|
|
});
|
2021-02-04 20:50:13 +00:00
|
|
|
|
2022-03-29 10:39:32 +00:00
|
|
|
it("Add associated roles test", () => {
|
2023-06-20 12:21:49 +00:00
|
|
|
itemId += "_" + uuid();
|
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-03-29 10:39:32 +00:00
|
|
|
// Add associated realm role from action dropdown
|
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-03-29 10:39:32 +00:00
|
|
|
// Add associated realm role from search bar
|
|
|
|
associatedRolesPage.addAssociatedRoleFromSearchBar("offline_access");
|
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
|
|
|
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
|
|
|
|
// Add associated client role from search bar
|
|
|
|
associatedRolesPage.addAssociatedRoleFromSearchBar("manage-account", true);
|
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
|
|
|
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
|
2022-02-23 11:05:38 +00:00
|
|
|
// Add associated client role
|
2022-03-29 10:39:32 +00:00
|
|
|
associatedRolesPage.addAssociatedRoleFromSearchBar("manage-consent", true);
|
2022-02-23 11:05:38 +00:00
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
2022-03-29 10:39:32 +00:00
|
|
|
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
|
|
|
|
// Add associated client role
|
2022-08-20 08:10:36 +00:00
|
|
|
associatedRolesPage.addAssociatedRoleFromSearchBar(
|
|
|
|
"manage-account-links",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-08-20 08:10:36 +00:00
|
|
|
);
|
2022-03-29 10:39:32 +00:00
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
|
|
|
});
|
|
|
|
|
2023-12-07 14:34:31 +00:00
|
|
|
it("should search existing associated role by name and go to it", () => {
|
|
|
|
listingPage
|
|
|
|
.searchItem("create-realm", false)
|
|
|
|
.itemExist("create-realm")
|
|
|
|
.goToItemDetails("create-realm");
|
|
|
|
|
|
|
|
cy.findByTestId("view-header").should("contain.text", "create-realm");
|
|
|
|
cy.findByTestId("cancel").click();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should go to default-roles-master link role name and check assign roles table is not empty", () => {
|
|
|
|
listingPage.goToItemDetails("default-roles-master");
|
|
|
|
|
|
|
|
rolesTab.goToDefaultGroupsTab();
|
|
|
|
cy.findByTestId("assigned-roles").find("tr").should("have.length.gt", 0);
|
|
|
|
cy.findByTestId("empty-state").contains("No default groups");
|
|
|
|
|
|
|
|
rolesTab.goToDefaultRolesTab();
|
|
|
|
cy.findByTestId("assigned-roles").find("tr").should("have.length.gt", 0);
|
2022-03-29 10:39:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should search non-existent associated role by name", () => {
|
|
|
|
const itemName = "non-existent-associated-role";
|
|
|
|
listingPage.searchItem(itemName, false);
|
|
|
|
cy.findByTestId(listingPage.emptyState).should("exist");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should hide inherited roles test", () => {
|
|
|
|
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
rolesTab.hideInheritedRoles();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should fail to remove role when all unchecked from search bar", () => {
|
|
|
|
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
associatedRolesPage.isRemoveAssociatedRolesBtnDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should delete single non-inherited role item", () => {
|
|
|
|
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
listingPage.removeItem("create-realm");
|
|
|
|
sidebarPage.waitForPageLoad();
|
2022-12-02 09:41:30 +00:00
|
|
|
modalUtils.checkModalTitle("Remove role?").confirmModal();
|
2022-03-29 10:39:32 +00:00
|
|
|
sidebarPage.waitForPageLoad();
|
|
|
|
|
|
|
|
masthead.checkNotificationMessage(
|
2022-09-16 08:58:43 +00:00
|
|
|
"Scope mapping successfully removed",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-03-29 10:39:32 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should delete all roles from search bar", () => {
|
|
|
|
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
|
|
|
|
sidebarPage.waitForPageLoad();
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
|
|
|
|
cy.get('input[name="check-all"]').check();
|
|
|
|
|
|
|
|
associatedRolesPage.removeAssociatedRoles();
|
|
|
|
|
|
|
|
sidebarPage.waitForPageLoad();
|
2022-12-02 09:41:30 +00:00
|
|
|
modalUtils.checkModalTitle("Remove role?").confirmModal();
|
2022-03-29 10:39:32 +00:00
|
|
|
sidebarPage.waitForPageLoad();
|
|
|
|
|
|
|
|
masthead.checkNotificationMessage(
|
2022-09-16 08:58:43 +00:00
|
|
|
"Scope mapping successfully removed",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-03-29 10:39:32 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should delete associated roles from list test", () => {
|
|
|
|
itemId = "realm_role_crud";
|
2023-06-20 12:21:49 +00:00
|
|
|
itemId += "_" + uuid();
|
2022-03-29 10:39:32 +00:00
|
|
|
|
|
|
|
// Create
|
|
|
|
listingPage.itemExist(itemId, false).goToCreateItem();
|
|
|
|
createRealmRolePage.fillRealmRoleData(itemId).save();
|
|
|
|
masthead.checkNotificationMessage("Role created", true);
|
|
|
|
|
|
|
|
// Add associated realm role from action dropdown
|
|
|
|
associatedRolesPage.addAssociatedRealmRole("create-realm");
|
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
|
|
|
|
|
|
|
// Add associated realm role from search bar
|
|
|
|
associatedRolesPage.addAssociatedRoleFromSearchBar("offline_access");
|
|
|
|
masthead.checkNotificationMessage("Associated roles have been added", true);
|
|
|
|
|
|
|
|
rolesTab.goToAssociatedRolesTab();
|
|
|
|
|
|
|
|
// delete associated roles from list
|
|
|
|
listingPage.removeItem("create-realm");
|
|
|
|
sidebarPage.waitForPageLoad();
|
2022-12-02 09:41:30 +00:00
|
|
|
modalUtils.checkModalTitle("Remove role?").confirmModal();
|
2022-03-29 10:39:32 +00:00
|
|
|
sidebarPage.waitForPageLoad();
|
|
|
|
|
|
|
|
masthead.checkNotificationMessage(
|
2022-09-16 08:58:43 +00:00
|
|
|
"Scope mapping successfully removed",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-03-29 10:39:32 +00:00
|
|
|
);
|
|
|
|
listingPage.removeItem("offline_access");
|
|
|
|
sidebarPage.waitForPageLoad();
|
2022-12-02 09:41:30 +00:00
|
|
|
modalUtils.checkModalTitle("Remove role?").confirmModal();
|
2022-03-29 10:39:32 +00:00
|
|
|
sidebarPage.waitForPageLoad();
|
|
|
|
|
|
|
|
masthead.checkNotificationMessage(
|
2022-09-16 08:58:43 +00:00
|
|
|
"Scope mapping successfully removed",
|
2023-07-11 14:03:21 +00:00
|
|
|
true,
|
2022-03-29 10:39:32 +00:00
|
|
|
);
|
2022-02-23 11:05:38 +00:00
|
|
|
});
|
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-04-20 09:29:35 +00:00
|
|
|
const updateDescription = "updated description";
|
|
|
|
|
2022-03-03 07:45:44 +00:00
|
|
|
before(() =>
|
2022-02-23 11:05:38 +00:00
|
|
|
adminClient.createRealmRole({
|
|
|
|
name: editRoleName,
|
|
|
|
description,
|
2023-07-11 14:03:21 +00:00
|
|
|
}),
|
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);
|
|
|
|
createRealmRolePage.updateDescription(updateDescription).save();
|
|
|
|
masthead.checkNotificationMessage("The role has been saved", true);
|
|
|
|
createRealmRolePage.checkDescription(updateDescription);
|
2022-04-20 09:29:35 +00:00
|
|
|
});
|
|
|
|
|
2022-04-20 17:11:46 +00:00
|
|
|
const keyValue = new KeyValueInput("attributes");
|
2024-02-19 01:09:22 +00:00
|
|
|
|
2022-10-06 14:18:33 +00:00
|
|
|
it("should add attribute", () => {
|
2022-04-20 09:29:35 +00:00
|
|
|
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
|
|
|
|
|
|
|
|
createRealmRolePage.goToAttributesTab();
|
2023-04-04 08:09:31 +00:00
|
|
|
keyValue.fillKeyValue({ key: "one", value: "1" }).validateRows(1);
|
2022-04-20 09:29:35 +00:00
|
|
|
keyValue.save();
|
|
|
|
masthead.checkNotificationMessage("The role has been saved", true);
|
2023-04-04 08:09:31 +00:00
|
|
|
keyValue.validateRows(1);
|
2022-04-20 09:29:35 +00:00
|
|
|
});
|
|
|
|
|
2022-10-06 14:18:33 +00:00
|
|
|
it("should add attribute multiple", () => {
|
2022-04-20 09:29:35 +00:00
|
|
|
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
|
|
|
|
|
|
|
|
createRealmRolePage.goToAttributesTab();
|
|
|
|
keyValue
|
2023-04-04 08:09:31 +00:00
|
|
|
.fillKeyValue({ key: "two", value: "2" })
|
|
|
|
.fillKeyValue({ key: "three", value: "3" })
|
2022-04-20 09:29:35 +00:00
|
|
|
.save()
|
2023-04-04 08:09:31 +00:00
|
|
|
.validateRows(3);
|
2022-04-20 09:29:35 +00:00
|
|
|
});
|
|
|
|
|
2022-10-06 14:18:33 +00:00
|
|
|
it("should delete attribute", () => {
|
2022-04-20 09:29:35 +00:00
|
|
|
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
|
|
|
|
createRealmRolePage.goToAttributesTab();
|
|
|
|
|
2023-04-04 08:09:31 +00:00
|
|
|
keyValue.deleteRow(1).save().validateRows(2);
|
2022-04-20 09:29:35 +00:00
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
});
|
2023-03-22 16:14:53 +00:00
|
|
|
|
|
|
|
describe("Accessibility tests for realm roles", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
loginPage.logIn();
|
|
|
|
keycloakBefore();
|
|
|
|
sidebarPage.goToRealmRoles();
|
|
|
|
cy.injectAxe();
|
|
|
|
});
|
|
|
|
|
|
|
|
const role = "a11y-role";
|
2023-12-07 14:34:31 +00:00
|
|
|
const defaultRolesMaster = "default-roles-master";
|
2023-03-22 16:14:53 +00:00
|
|
|
|
|
|
|
it("Check a11y violations on load/ realm roles", () => {
|
|
|
|
cy.checkA11y();
|
|
|
|
});
|
|
|
|
|
2023-12-07 14:34:31 +00:00
|
|
|
it("Check a11y violations on default-roles-master default tab and default roles tabs", () => {
|
|
|
|
listingPage.goToItemDetails(defaultRolesMaster);
|
|
|
|
cy.checkA11y();
|
|
|
|
|
|
|
|
rolesTab.goToDefaultGroupsTab();
|
|
|
|
cy.checkA11y();
|
|
|
|
});
|
|
|
|
|
2023-03-22 16:14:53 +00:00
|
|
|
it("Check a11y violations on empty create role form", () => {
|
|
|
|
rolesTab.goToCreateRoleFromToolbar();
|
|
|
|
cy.checkA11y();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check a11y violations on role details", () => {
|
|
|
|
const permissionSwitch = "permissionSwitch";
|
|
|
|
rolesTab.goToCreateRoleFromToolbar();
|
|
|
|
createRealmRolePage.fillRealmRoleData(role).save();
|
|
|
|
cy.checkA11y();
|
|
|
|
|
|
|
|
rolesTab.goToAttributesTab();
|
|
|
|
cy.checkA11y();
|
|
|
|
|
|
|
|
rolesTab.goToUsersInRoleTab();
|
|
|
|
cy.checkA11y();
|
|
|
|
|
|
|
|
rolesTab.goToPermissionsTab();
|
|
|
|
cy.findByTestId(permissionSwitch).parent().click();
|
|
|
|
cy.checkA11y();
|
|
|
|
|
|
|
|
sidebarPage.goToRealmRoles();
|
|
|
|
listingPage.deleteItem(role);
|
|
|
|
cy.checkA11y();
|
|
|
|
cy.findByTestId("confirm").click();
|
|
|
|
});
|
|
|
|
});
|
2021-01-21 12:09:50 +00:00
|
|
|
});
|