Keycloak

Форк
0
/
realm_roles_test.spec.ts 
345 строк · 11.5 Кб
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";
13

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();
22

23
describe("Realm roles test", () => {
24
  beforeEach(() => {
25
    loginPage.logIn();
26
    keycloakBefore();
27
    sidebarPage.goToRealmRoles();
28
  });
29

30
  it("should fail creating realm role", () => {
31
    listingPage.goToCreateItem();
32
    createRealmRolePage.save().checkRealmRoleNameRequiredMessage();
33
    createRealmRolePage.fillRealmRoleData("admin").save();
34

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",
38
      true,
39
    );
40
  });
41

42
  it("shouldn't create a realm role based with only whitespace name", () => {
43
    listingPage.goToCreateItem();
44
    createRealmRolePage
45
      .fillRealmRoleData("  ")
46
      .checkRealmRoleNameRequiredMessage();
47
  });
48

49
  it("Realm role CRUD test", () => {
50
    itemId += "_" + uuid();
51

52
    // Create
53
    listingPage.itemExist(itemId, false).goToCreateItem();
54
    createRealmRolePage.fillRealmRoleData(itemId).save();
55
    masthead.checkNotificationMessage("Role created", true);
56
    sidebarPage.goToRealmRoles();
57

58
    const fetchUrl = "/admin/realms/master/roles?first=0&max=11";
59
    cy.intercept(fetchUrl).as("fetch");
60

61
    listingPage.deleteItem(itemId);
62

63
    cy.wait(["@fetch"]);
64
    modalUtils.checkModalTitle("Delete role?").confirmModal();
65
    masthead.checkNotificationMessage("The role has been deleted", true);
66

67
    listingPage.itemExist(itemId, false);
68

69
    itemId = "realm_role_crud";
70
  });
71

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";
81
  });
82

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.",
88
      true,
89
    );
90
  });
91

92
  it("Add associated roles test", () => {
93
    itemId += "_" + uuid();
94

95
    // Create
96
    listingPage.itemExist(itemId, false).goToCreateItem();
97
    createRealmRolePage.fillRealmRoleData(itemId).save();
98
    masthead.checkNotificationMessage("Role created", true);
99

100
    // Add associated realm role from action dropdown
101
    associatedRolesPage.addAssociatedRealmRole("create-realm");
102
    masthead.checkNotificationMessage("Associated roles have been added", true);
103

104
    // Add associated realm role from search bar
105
    associatedRolesPage.addAssociatedRoleFromSearchBar("offline_access");
106
    masthead.checkNotificationMessage("Associated roles have been added", true);
107

108
    rolesTab.goToAssociatedRolesTab();
109

110
    // Add associated client role from search bar
111
    associatedRolesPage.addAssociatedRoleFromSearchBar("manage-account", true);
112
    masthead.checkNotificationMessage("Associated roles have been added", true);
113

114
    rolesTab.goToAssociatedRolesTab();
115

116
    // Add associated client role
117
    associatedRolesPage.addAssociatedRoleFromSearchBar("manage-consent", true);
118
    masthead.checkNotificationMessage("Associated roles have been added", true);
119

120
    rolesTab.goToAssociatedRolesTab();
121

122
    // Add associated client role
123
    associatedRolesPage.addAssociatedRoleFromSearchBar(
124
      "manage-account-links",
125
      true,
126
    );
127
    masthead.checkNotificationMessage("Associated roles have been added", true);
128
  });
129

130
  it("should search existing associated role by name and go to it", () => {
131
    listingPage
132
      .searchItem("create-realm", false)
133
      .itemExist("create-realm")
134
      .goToItemDetails("create-realm");
135

136
    cy.findByTestId("view-header").should("contain.text", "create-realm");
137
    cy.findByTestId("cancel").click();
138
  });
139

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");
142

143
    rolesTab.goToDefaultGroupsTab();
144
    cy.findByTestId("assigned-roles").find("tr").should("have.length.gt", 0);
145
    cy.findByTestId("empty-state").contains("No default groups");
146

147
    rolesTab.goToDefaultRolesTab();
148
    cy.findByTestId("assigned-roles").find("tr").should("have.length.gt", 0);
149
  });
150

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");
155
  });
156

157
  it("Should hide inherited roles test", () => {
158
    listingPage.searchItem(itemId, false).goToItemDetails(itemId);
159
    rolesTab.goToAssociatedRolesTab();
160
    rolesTab.hideInheritedRoles();
161
  });
162

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();
167
  });
168

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();
176

177
    masthead.checkNotificationMessage(
178
      "Scope mapping successfully removed",
179
      true,
180
    );
181
  });
182

183
  it("Should delete all roles from search bar", () => {
184
    listingPage.searchItem(itemId, false).goToItemDetails(itemId);
185
    sidebarPage.waitForPageLoad();
186
    rolesTab.goToAssociatedRolesTab();
187

188
    cy.get('input[name="check-all"]').check();
189

190
    associatedRolesPage.removeAssociatedRoles();
191

192
    sidebarPage.waitForPageLoad();
193
    modalUtils.checkModalTitle("Remove role?").confirmModal();
194
    sidebarPage.waitForPageLoad();
195

196
    masthead.checkNotificationMessage(
197
      "Scope mapping successfully removed",
198
      true,
199
    );
200
  });
201

202
  it("Should delete associated roles from list test", () => {
203
    itemId = "realm_role_crud";
204
    itemId += "_" + uuid();
205

206
    // Create
207
    listingPage.itemExist(itemId, false).goToCreateItem();
208
    createRealmRolePage.fillRealmRoleData(itemId).save();
209
    masthead.checkNotificationMessage("Role created", true);
210

211
    // Add associated realm role from action dropdown
212
    associatedRolesPage.addAssociatedRealmRole("create-realm");
213
    masthead.checkNotificationMessage("Associated roles have been added", true);
214

215
    // Add associated realm role from search bar
216
    associatedRolesPage.addAssociatedRoleFromSearchBar("offline_access");
217
    masthead.checkNotificationMessage("Associated roles have been added", true);
218

219
    rolesTab.goToAssociatedRolesTab();
220

221
    // delete associated roles from list
222
    listingPage.removeItem("create-realm");
223
    sidebarPage.waitForPageLoad();
224
    modalUtils.checkModalTitle("Remove role?").confirmModal();
225
    sidebarPage.waitForPageLoad();
226

227
    masthead.checkNotificationMessage(
228
      "Scope mapping successfully removed",
229
      true,
230
    );
231
    listingPage.removeItem("offline_access");
232
    sidebarPage.waitForPageLoad();
233
    modalUtils.checkModalTitle("Remove role?").confirmModal();
234
    sidebarPage.waitForPageLoad();
235

236
    masthead.checkNotificationMessage(
237
      "Scope mapping successfully removed",
238
      true,
239
    );
240
  });
241

242
  describe("edit role details", () => {
243
    const editRoleName = "going to edit";
244
    const description = "some description";
245
    const updateDescription = "updated description";
246

247
    before(() =>
248
      adminClient.createRealmRole({
249
        name: editRoleName,
250
        description,
251
      }),
252
    );
253

254
    after(() => adminClient.deleteRealmRole(editRoleName));
255

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);
262
    });
263

264
    const keyValue = new KeyValueInput("attributes");
265

266
    it("should add attribute", () => {
267
      listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
268

269
      createRealmRolePage.goToAttributesTab();
270
      keyValue.fillKeyValue({ key: "one", value: "1" }).validateRows(1);
271
      keyValue.save();
272
      masthead.checkNotificationMessage("The role has been saved", true);
273
      keyValue.validateRows(1);
274
    });
275

276
    it("should add attribute multiple", () => {
277
      listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
278

279
      createRealmRolePage.goToAttributesTab();
280
      keyValue
281
        .fillKeyValue({ key: "two", value: "2" })
282
        .fillKeyValue({ key: "three", value: "3" })
283
        .save()
284
        .validateRows(3);
285
    });
286

287
    it("should delete attribute", () => {
288
      listingPage.itemExist(editRoleName).goToItemDetails(editRoleName);
289
      createRealmRolePage.goToAttributesTab();
290

291
      keyValue.deleteRow(1).save().validateRows(2);
292
    });
293
  });
294

295
  describe("Accessibility tests for realm roles", () => {
296
    beforeEach(() => {
297
      loginPage.logIn();
298
      keycloakBefore();
299
      sidebarPage.goToRealmRoles();
300
      cy.injectAxe();
301
    });
302

303
    const role = "a11y-role";
304
    const defaultRolesMaster = "default-roles-master";
305

306
    it("Check a11y violations on load/ realm roles", () => {
307
      cy.checkA11y();
308
    });
309

310
    it("Check a11y violations on default-roles-master default tab and default roles tabs", () => {
311
      listingPage.goToItemDetails(defaultRolesMaster);
312
      cy.checkA11y();
313

314
      rolesTab.goToDefaultGroupsTab();
315
      cy.checkA11y();
316
    });
317

318
    it("Check a11y violations on empty create role form", () => {
319
      rolesTab.goToCreateRoleFromToolbar();
320
      cy.checkA11y();
321
    });
322

323
    it("Check a11y violations on role details", () => {
324
      const permissionSwitch = "permissionSwitch";
325
      rolesTab.goToCreateRoleFromToolbar();
326
      createRealmRolePage.fillRealmRoleData(role).save();
327
      cy.checkA11y();
328

329
      rolesTab.goToAttributesTab();
330
      cy.checkA11y();
331

332
      rolesTab.goToUsersInRoleTab();
333
      cy.checkA11y();
334

335
      rolesTab.goToPermissionsTab();
336
      cy.findByTestId(permissionSwitch).parent().click();
337
      cy.checkA11y();
338

339
      sidebarPage.goToRealmRoles();
340
      listingPage.deleteItem(role);
341
      cy.checkA11y();
342
      cy.findByTestId("confirm").click();
343
    });
344
  });
345
});
346

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.