1
import { v4 as uuid } from "uuid";
2
import LoginPage from "../support/pages/LoginPage";
3
import Masthead from "../support/pages/admin-ui/Masthead";
4
import ModalUtils from "../support/util/ModalUtils";
5
import ListingPage from "../support/pages/admin-ui/ListingPage";
6
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
7
import createRealmRolePage from "../support/pages/admin-ui/manage/realm_roles/CreateRealmRolePage";
8
import AssociatedRolesPage from "../support/pages/admin-ui/manage/realm_roles/AssociatedRolesPage";
9
import { keycloakBefore } from "../support/util/keycloak_hooks";
10
import adminClient from "../support/util/AdminClient";
11
import ClientRolesTab from "../support/pages/admin-ui/manage/clients/ClientRolesTab";
12
import KeyValueInput from "../support/pages/admin-ui/manage/KeyValueInput";
14
let itemId = "realm_role_crud";
15
const loginPage = new LoginPage();
16
const masthead = new Masthead();
17
const modalUtils = new ModalUtils();
18
const sidebarPage = new SidebarPage();
19
const listingPage = new ListingPage();
20
const associatedRolesPage = new AssociatedRolesPage();
21
const rolesTab = new ClientRolesTab();
23
describe("Realm roles test", () => {
27
sidebarPage.goToRealmRoles();
30
it("should fail creating realm role", () => {
31
listingPage.goToCreateItem();
32
createRealmRolePage.save().checkRealmRoleNameRequiredMessage();
33
createRealmRolePage.fillRealmRoleData("admin").save();
35
// The error should inform about duplicated name/id (THIS MESSAGE DOES NOT HAVE QUOTES AS THE OTHERS)
36
masthead.checkNotificationMessage(
37
"Could not create role: Role with name admin already exists",
42
it("shouldn't create a realm role based with only whitespace name", () => {
43
listingPage.goToCreateItem();
45
.fillRealmRoleData(" ")
46
.checkRealmRoleNameRequiredMessage();
49
it("Realm role CRUD test", () => {
50
itemId += "_" + uuid();
53
listingPage.itemExist(itemId, false).goToCreateItem();
54
createRealmRolePage.fillRealmRoleData(itemId).save();
55
masthead.checkNotificationMessage("Role created", true);
56
sidebarPage.goToRealmRoles();
58
const fetchUrl = "/admin/realms/master/roles?first=0&max=11";
59
cy.intercept(fetchUrl).as("fetch");
61
listingPage.deleteItem(itemId);
64
modalUtils.checkModalTitle("Delete role?").confirmModal();
65
masthead.checkNotificationMessage("The role has been deleted", true);
67
listingPage.itemExist(itemId, false);
69
itemId = "realm_role_crud";
72
it("should delete role from details action", () => {
73
itemId += "_" + uuid();
74
listingPage.goToCreateItem();
75
createRealmRolePage.fillRealmRoleData(itemId).save();
76
masthead.checkNotificationMessage("Role created", true);
77
createRealmRolePage.clickActionMenu("Delete this role");
78
modalUtils.confirmModal();
79
masthead.checkNotificationMessage("The role has been deleted", true);
80
itemId = "realm_role_crud";
83
it("should not be able to delete default role", () => {
84
const defaultRole = "default-roles-master";
85
listingPage.itemExist(defaultRole).deleteItem(defaultRole);
86
masthead.checkNotificationMessage(
87
"You cannot delete a default role.",
92
it("Add associated roles test", () => {
93
itemId += "_" + uuid();
96
listingPage.itemExist(itemId, false).goToCreateItem();
97
createRealmRolePage.fillRealmRoleData(itemId).save();
98
masthead.checkNotificationMessage("Role created", true);
100
// Add associated realm role from action dropdown
101
associatedRolesPage.addAssociatedRealmRole("create-realm");
102
masthead.checkNotificationMessage("Associated roles have been added", true);
104
// Add associated realm role from search bar
105
associatedRolesPage.addAssociatedRoleFromSearchBar("offline_access");
106
masthead.checkNotificationMessage("Associated roles have been added", true);
108
rolesTab.goToAssociatedRolesTab();
110
// Add associated client role from search bar
111
associatedRolesPage.addAssociatedRoleFromSearchBar("manage-account", true);
112
masthead.checkNotificationMessage("Associated roles have been added", true);
114
rolesTab.goToAssociatedRolesTab();
116
// Add associated client role
117
associatedRolesPage.addAssociatedRoleFromSearchBar("manage-consent", true);
118
masthead.checkNotificationMessage("Associated roles have been added", true);
120
rolesTab.goToAssociatedRolesTab();
122
// Add associated client role
123
associatedRolesPage.addAssociatedRoleFromSearchBar(
124
"manage-account-links",
127
masthead.checkNotificationMessage("Associated roles have been added", true);
130
it("should search existing associated role by name and go to it", () => {
132
.searchItem("create-realm", false)
133
.itemExist("create-realm")
134
.goToItemDetails("create-realm");
136
cy.findByTestId("view-header").should("contain.text", "create-realm");
137
cy.findByTestId("cancel").click();
140
it("should go to default-roles-master link role name and check assign roles table is not empty", () => {
141
listingPage.goToItemDetails("default-roles-master");
143
rolesTab.goToDefaultGroupsTab();
144
cy.findByTestId("assigned-roles").find("tr").should("have.length.gt", 0);
145
cy.findByTestId("empty-state").contains("No default groups");
147
rolesTab.goToDefaultRolesTab();
148
cy.findByTestId("assigned-roles").find("tr").should("have.length.gt", 0);
151
it("Should search non-existent associated role by name", () => {
152
const itemName = "non-existent-associated-role";
153
listingPage.searchItem(itemName, false);
154
cy.findByTestId(listingPage.emptyState).should("exist");
157
it("Should hide inherited roles test", () => {
158
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
159
rolesTab.goToAssociatedRolesTab();
160
rolesTab.hideInheritedRoles();
163
it("Should fail to remove role when all unchecked from search bar", () => {
164
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
165
rolesTab.goToAssociatedRolesTab();
166
associatedRolesPage.isRemoveAssociatedRolesBtnDisabled();
169
it("Should delete single non-inherited role item", () => {
170
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
171
rolesTab.goToAssociatedRolesTab();
172
listingPage.removeItem("create-realm");
173
sidebarPage.waitForPageLoad();
174
modalUtils.checkModalTitle("Remove role?").confirmModal();
175
sidebarPage.waitForPageLoad();
177
masthead.checkNotificationMessage(
178
"Scope mapping successfully removed",
183
it("Should delete all roles from search bar", () => {
184
listingPage.searchItem(itemId, false).goToItemDetails(itemId);
185
sidebarPage.waitForPageLoad();
186
rolesTab.goToAssociatedRolesTab();
188
cy.get('input[name="check-all"]').check();
190
associatedRolesPage.removeAssociatedRoles();
192
sidebarPage.waitForPageLoad();
193
modalUtils.checkModalTitle("Remove role?").confirmModal();
194
sidebarPage.waitForPageLoad();
196
masthead.checkNotificationMessage(
197
"Scope mapping successfully removed",
202
it("Should delete associated roles from list test", () => {
203
itemId = "realm_role_crud";
204
itemId += "_" + uuid();
207
listingPage.itemExist(itemId, false).goToCreateItem();
208
createRealmRolePage.fillRealmRoleData(itemId).save();
209
masthead.checkNotificationMessage("Role created", true);
211
// Add associated realm role from action dropdown
212
associatedRolesPage.addAssociatedRealmRole("create-realm");
213
masthead.checkNotificationMessage("Associated roles have been added", true);
215
// Add associated realm role from search bar
216
associatedRolesPage.addAssociatedRoleFromSearchBar("offline_access");
217
masthead.checkNotificationMessage("Associated roles have been added", true);
219
rolesTab.goToAssociatedRolesTab();
221
// delete associated roles from list
222
listingPage.removeItem("create-realm");
223
sidebarPage.waitForPageLoad();
224
modalUtils.checkModalTitle("Remove role?").confirmModal();
225
sidebarPage.waitForPageLoad();
227
masthead.checkNotificationMessage(
228
"Scope mapping successfully removed",
231
listingPage.removeItem("offline_access");
232
sidebarPage.waitForPageLoad();
233
modalUtils.checkModalTitle("Remove role?").confirmModal();
234
sidebarPage.waitForPageLoad();
236
masthead.checkNotificationMessage(
237
"Scope mapping successfully removed",
242
describe("edit role details", () => {
243
const editRoleName = "going to edit";
244
const description = "some description";
245
const updateDescription = "updated description";
248
adminClient.createRealmRole({
254
after(() => adminClient.deleteRealmRole(editRoleName));
256
it("should edit realm role details", () => {
257
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
258
createRealmRolePage.checkNameDisabled().checkDescription(description);
259
createRealmRolePage.updateDescription(updateDescription).save();
260
masthead.checkNotificationMessage("The role has been saved", true);
261
createRealmRolePage.checkDescription(updateDescription);
264
const keyValue = new KeyValueInput("attributes");
266
it("should add attribute", () => {
267
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
269
createRealmRolePage.goToAttributesTab();
270
keyValue.fillKeyValue({ key: "one", value: "1" }).validateRows(1);
272
masthead.checkNotificationMessage("The role has been saved", true);
273
keyValue.validateRows(1);
276
it("should add attribute multiple", () => {
277
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
279
createRealmRolePage.goToAttributesTab();
281
.fillKeyValue({ key: "two", value: "2" })
282
.fillKeyValue({ key: "three", value: "3" })
287
it("should delete attribute", () => {
288
listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
289
createRealmRolePage.goToAttributesTab();
291
keyValue.deleteRow(1).save().validateRows(2);
295
describe("Accessibility tests for realm roles", () => {
299
sidebarPage.goToRealmRoles();
303
const role = "a11y-role";
304
const defaultRolesMaster = "default-roles-master";
306
it("Check a11y violations on load/ realm roles", () => {
310
it("Check a11y violations on default-roles-master default tab and default roles tabs", () => {
311
listingPage.goToItemDetails(defaultRolesMaster);
314
rolesTab.goToDefaultGroupsTab();
318
it("Check a11y violations on empty create role form", () => {
319
rolesTab.goToCreateRoleFromToolbar();
323
it("Check a11y violations on role details", () => {
324
const permissionSwitch = "permissionSwitch";
325
rolesTab.goToCreateRoleFromToolbar();
326
createRealmRolePage.fillRealmRoleData(role).save();
329
rolesTab.goToAttributesTab();
332
rolesTab.goToUsersInRoleTab();
335
rolesTab.goToPermissionsTab();
336
cy.findByTestId(permissionSwitch).parent().click();
339
sidebarPage.goToRealmRoles();
340
listingPage.deleteItem(role);
342
cy.findByTestId("confirm").click();