Keycloak

Форк
0
/
realm_settings_events_test.spec.ts 
417 строк · 11.9 Кб
1
import { v4 as uuid } from "uuid";
2
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
3
import LoginPage from "../support/pages/LoginPage";
4
import RealmSettingsPage from "../support/pages/admin-ui/manage/realm_settings/RealmSettingsPage";
5
import Masthead from "../support/pages/admin-ui/Masthead";
6
import ModalUtils from "../support/util/ModalUtils";
7
import { keycloakBefore } from "../support/util/keycloak_hooks";
8
import ListingPage from "../support/pages/admin-ui/ListingPage";
9
import adminClient from "../support/util/AdminClient";
10
import KeysTab from "../support/pages/admin-ui/manage/realm_settings/KeysTab";
11

12
const loginPage = new LoginPage();
13
const sidebarPage = new SidebarPage();
14
const masthead = new Masthead();
15
const modalUtils = new ModalUtils();
16
const realmSettingsPage = new RealmSettingsPage();
17
const keysTab = new KeysTab();
18

19
describe("Realm settings events tab tests", () => {
20
  const realmName = "Realm_" + uuid();
21
  const listingPage = new ListingPage();
22

23
  beforeEach(() => {
24
    loginPage.logIn();
25
    keycloakBefore();
26
    sidebarPage.goToRealm(realmName);
27
  });
28

29
  before(async () => {
30
    await adminClient.createRealm(realmName);
31
  });
32

33
  after(async () => {
34
    await adminClient.deleteRealm(realmName);
35
  });
36

37
  const goToDetails = () => {
38
    const keysUrl = `/admin/realms/${realmName}/keys`;
39
    cy.intercept(keysUrl).as("keysFetch");
40

41
    keysTab.goToKeysTab();
42
    cy.findByTestId("rs-providers-tab").click();
43
    cy.findAllByTestId("provider-name-link")
44
      .contains("test_aes-generated")
45
      .click();
46

47
    sidebarPage.goToRealmSettings();
48

49
    keysTab.goToKeysTab();
50
    cy.findByTestId("rs-providers-tab").click();
51
    cy.findAllByTestId("provider-name-link")
52
      .contains("test_hmac-generated")
53
      .click();
54

55
    sidebarPage.goToRealmSettings();
56

57
    keysTab.goToKeysTab();
58
    cy.findByTestId("rs-providers-tab").click();
59
    cy.findAllByTestId("provider-name-link").contains("test_rsa").click();
60

61
    sidebarPage.goToRealmSettings();
62

63
    keysTab.goToKeysTab();
64
    cy.findByTestId("rs-providers-tab").click();
65
    cy.findAllByTestId("provider-name-link")
66
      .contains("test_rsa-generated")
67
      .click();
68

69
    sidebarPage.goToRealmSettings();
70

71
    keysTab.goToKeysTab();
72
    cy.findByTestId("rs-providers-tab").click();
73
    cy.findAllByTestId("provider-name-link")
74
      .contains("test_rsa-enc-generated")
75
      .click();
76

77
    cy.wait(["@keysFetch"]);
78

79
    return this;
80
  };
81

82
  const goToKeys = () => {
83
    const keysUrl = `/admin/realms/${realmName}/keys`;
84
    cy.intercept(keysUrl).as("keysFetch");
85
    keysTab.goToKeysTab();
86
    cy.findByTestId("rs-keys-list-tab").click();
87
    cy.wait(["@keysFetch"]);
88

89
    return this;
90
  };
91

92
  it("Enable user events", () => {
93
    cy.intercept("GET", `/admin/realms/${realmName}/events/config`).as("load");
94
    sidebarPage.goToRealmSettings();
95
    cy.findByTestId("rs-realm-events-tab").click();
96
    cy.findByTestId("rs-events-tab").click();
97
    cy.wait("@load");
98
    realmSettingsPage
99
      .toggleSwitch(realmSettingsPage.enableEvents, false)
100
      .save(realmSettingsPage.eventsUserSave);
101
    masthead.checkNotificationMessage("Successfully saved configuration");
102
    realmSettingsPage.clearEvents("user");
103
    modalUtils
104
      .checkModalMessage(
105
        "If you clear all events of this realm, all records will be permanently cleared in the database",
106
      )
107
      .confirmModal();
108
    masthead.checkNotificationMessage("The user events have been cleared");
109
    const events = ["Client info", "Client info error"];
110
    cy.intercept("GET", `/admin/realms/${realmName}/events/config`).as(
111
      "fetchConfig",
112
    );
113
    realmSettingsPage.addUserEvents(events).clickAdd();
114
    masthead.checkNotificationMessage("Successfully saved configuration");
115
    cy.wait(["@fetchConfig"]);
116
    sidebarPage.waitForPageLoad();
117
    cy.wait(1000);
118
    for (const event of events) {
119
      listingPage.searchItem(event, false).itemExist(event);
120
    }
121
  });
122

123
  it("Go to keys tab", () => {
124
    sidebarPage.goToRealmSettings();
125

126
    keysTab.goToKeysTab();
127
  });
128

129
  it("add Providers", () => {
130
    sidebarPage.goToRealmSettings();
131

132
    keysTab.goToKeysTab();
133

134
    cy.findByTestId("rs-providers-tab").click();
135

136
    realmSettingsPage.toggleAddProviderDropdown();
137

138
    cy.findByTestId("option-aes-generated").click();
139
    realmSettingsPage.enterUIDisplayName("test_aes-generated");
140
    realmSettingsPage.addProvider();
141

142
    realmSettingsPage.toggleAddProviderDropdown();
143

144
    cy.findByTestId("option-ecdsa-generated").click();
145
    realmSettingsPage.enterUIDisplayName("test_ecdsa-generated");
146
    realmSettingsPage.toggleSwitch("active", false);
147
    realmSettingsPage.addProvider();
148

149
    realmSettingsPage.toggleAddProviderDropdown();
150

151
    cy.findByTestId("option-hmac-generated").click();
152
    realmSettingsPage.enterUIDisplayName("test_hmac-generated");
153
    realmSettingsPage.toggleSwitch("enabled", false);
154
    realmSettingsPage.addProvider();
155

156
    realmSettingsPage.toggleAddProviderDropdown();
157

158
    cy.findByTestId("option-rsa-generated").click();
159
    realmSettingsPage.enterUIDisplayName("test_rsa-generated");
160
    realmSettingsPage.addProvider();
161

162
    realmSettingsPage.toggleAddProviderDropdown();
163

164
    cy.findByTestId("option-rsa-enc-generated").click();
165
    realmSettingsPage.enterUIDisplayName("test_rsa-enc-generated");
166
    realmSettingsPage.addProvider();
167
  });
168

169
  it("search providers", () => {
170
    sidebarPage.goToRealmSettings();
171

172
    keysTab.goToKeysTab();
173

174
    cy.findByTestId("rs-providers-tab").click();
175

176
    // search providers
177
    cy.findByTestId("provider-search-input").type("rsa{enter}");
178
    listingPage.checkTableLength(4, "kc-draggable-table");
179
    cy.findByTestId("provider-search-input").clear().type("{enter}");
180
  });
181

182
  it("go to details", () => {
183
    sidebarPage.goToRealmSettings();
184
    goToDetails();
185
  });
186

187
  it("Test keys", () => {
188
    sidebarPage.goToRealmSettings();
189
    goToKeys();
190

191
    realmSettingsPage.testSelectFilter();
192
  });
193

194
  it.skip("Should search active keys", () => {
195
    sidebarPage.goToRealmSettings();
196
    goToKeys();
197

198
    realmSettingsPage.switchToActiveFilter();
199
    listingPage.searchItem("rs", false);
200
    listingPage.checkTableLength(3, "kc-keys-list");
201
  });
202

203
  it("Should search passive keys", () => {
204
    sidebarPage.goToRealmSettings();
205
    goToKeys();
206

207
    realmSettingsPage.switchToPassiveFilter();
208
    listingPage.searchItem("ec", false);
209
    listingPage.checkTableLength(1, "kc-keys-list");
210
  });
211

212
  it("Should search disabled keys", () => {
213
    sidebarPage.goToRealmSettings();
214
    goToKeys();
215

216
    realmSettingsPage.switchToDisabledFilter();
217
    listingPage.searchItem("hs", false);
218
    listingPage.checkTableLength(1, "kc-keys-list");
219
  });
220

221
  it("delete provider", () => {
222
    sidebarPage.goToRealmSettings();
223

224
    keysTab.goToKeysTab();
225

226
    cy.findByTestId("rs-providers-tab").click();
227

228
    realmSettingsPage.deleteProvider("test_aes-generated");
229
  });
230

231
  it("list keys", () => {
232
    sidebarPage.goToRealmSettings();
233
    keysTab.goToKeysTab();
234
    realmSettingsPage.checkKeyPublic();
235
  });
236

237
  it("Realm header settings", () => {
238
    sidebarPage.goToRealmSettings();
239
    cy.findByTestId("rs-security-defenses-tab").click();
240
    cy.findByTestId("headers-form-tab-save").should("be.disabled");
241
    cy.get("#xFrameOptions").clear().type("DENY");
242
    cy.findByTestId("headers-form-tab-save").should("be.enabled").click();
243

244
    masthead.checkNotificationMessage("Realm successfully updated");
245
  });
246

247
  it("Brute force detection", () => {
248
    sidebarPage.goToRealmSettings();
249
    cy.findAllByTestId("rs-security-defenses-tab").click();
250
    cy.get("#pf-tab-20-bruteForce").click();
251

252
    cy.findByTestId("brute-force-tab-save").should("be.disabled");
253

254
    cy.get("#kc-brute-force-mode").click();
255
    cy.findByTestId("select-brute-force-mode")
256
      .contains("Lockout temporarily")
257
      .click();
258
    cy.findByTestId("waitIncrementSeconds").type("1");
259
    cy.findByTestId("maxFailureWaitSeconds").type("1");
260
    cy.findByTestId("maxDeltaTimeSeconds").type("1");
261
    cy.findByTestId("minimumQuickLoginWaitSeconds").type("1");
262

263
    cy.findByTestId("brute-force-tab-save").should("be.enabled").click();
264
    masthead.checkNotificationMessage("Realm successfully updated");
265
  });
266

267
  it("add session data", () => {
268
    sidebarPage.goToRealmSettings();
269

270
    cy.findByTestId("rs-sessions-tab").click();
271

272
    realmSettingsPage.populateSessionsPage();
273
    realmSettingsPage.save("sessions-tab-save");
274

275
    masthead.checkNotificationMessage("Realm successfully updated");
276
  });
277

278
  it("check that sessions data was saved", () => {
279
    sidebarPage.goToAuthentication();
280
    sidebarPage.goToRealmSettings();
281

282
    cy.findByTestId("rs-sessions-tab").click();
283

284
    cy.findByTestId(realmSettingsPage.ssoSessionIdleInput).should(
285
      "have.value",
286
      1,
287
    );
288
    cy.findByTestId(realmSettingsPage.ssoSessionMaxInput).should(
289
      "have.value",
290
      2,
291
    );
292
    cy.findByTestId(realmSettingsPage.ssoSessionIdleRememberMeInput).should(
293
      "have.value",
294
      3,
295
    );
296
    cy.findByTestId(realmSettingsPage.ssoSessionMaxRememberMeInput).should(
297
      "have.value",
298
      4,
299
    );
300

301
    cy.findByTestId(realmSettingsPage.clientSessionIdleInput).should(
302
      "have.value",
303
      5,
304
    );
305
    cy.findByTestId(realmSettingsPage.clientSessionMaxInput).should(
306
      "have.value",
307
      6,
308
    );
309

310
    cy.findByTestId(realmSettingsPage.offlineSessionIdleInput).should(
311
      "have.value",
312
      7,
313
    );
314
    cy.findByTestId(realmSettingsPage.offlineSessionMaxSwitch).should(
315
      "have.value",
316
      "on",
317
    );
318

319
    cy.findByTestId(realmSettingsPage.loginTimeoutInput).should(
320
      "have.value",
321
      9,
322
    );
323
    cy.findByTestId(realmSettingsPage.loginActionTimeoutInput).should(
324
      "have.value",
325
      10,
326
    );
327
  });
328

329
  it("add token data", () => {
330
    sidebarPage.goToRealmSettings();
331

332
    cy.findByTestId("rs-tokens-tab").click();
333

334
    realmSettingsPage.populateTokensPage();
335
    realmSettingsPage.save("tokens-tab-save");
336

337
    masthead.checkNotificationMessage("Realm successfully updated");
338
  });
339

340
  it("check that token data was saved", () => {
341
    sidebarPage.goToRealmSettings();
342

343
    cy.findByTestId("rs-tokens-tab").click();
344

345
    cy.findByTestId(realmSettingsPage.accessTokenLifespanInput).should(
346
      "have.value",
347
      1,
348
    );
349
    cy.findByTestId(realmSettingsPage.accessTokenLifespanImplicitInput).should(
350
      "have.value",
351
      2,
352
    );
353
    cy.findByTestId(realmSettingsPage.clientLoginTimeoutInput).should(
354
      "have.value",
355
      3,
356
    );
357
    cy.findByTestId(realmSettingsPage.userInitiatedActionLifespanInput).should(
358
      "have.value",
359
      4,
360
    );
361

362
    cy.findByTestId(realmSettingsPage.defaultAdminInitatedInput).should(
363
      "have.value",
364
      5,
365
    );
366
    cy.findByTestId(realmSettingsPage.emailVerificationInput).should(
367
      "have.value",
368
      6,
369
    );
370

371
    cy.findByTestId(realmSettingsPage.idpEmailVerificationInput).should(
372
      "have.value",
373
      7,
374
    );
375
    cy.findByTestId(realmSettingsPage.forgotPasswordInput).should(
376
      "have.value",
377
      8,
378
    );
379

380
    cy.findByTestId(realmSettingsPage.executeActionsInput).should(
381
      "have.value",
382
      9,
383
    );
384
  });
385
});
386

387
describe("Realm settings events tab tests", () => {
388
  beforeEach(() => {
389
    loginPage.logIn();
390
    keycloakBefore();
391
    sidebarPage.goToRealmSettings();
392
    cy.findByTestId("rs-realm-events-tab").click();
393
    cy.findByTestId("rs-event-listeners-tab").click();
394
  });
395

396
  it("Should display event listeners form", () => {
397
    realmSettingsPage.shouldDisplayEventListenersForm();
398
  });
399

400
  it("Should revert saving event listener", () => {
401
    realmSettingsPage.shouldRevertSavingEventListener();
402
  });
403

404
  it("Should save event listener", () => {
405
    realmSettingsPage.shouldSaveEventListener();
406
  });
407

408
  it("Should remove event from event listener", () => {
409
    realmSettingsPage.shouldRemoveEventFromEventListener();
410
  });
411

412
  it("Should remove all events from event listener and re-save original", () => {
413
    realmSettingsPage.shouldSaveEventListener();
414
    realmSettingsPage.shouldRemoveAllEventListeners();
415
    realmSettingsPage.shouldReSaveEventListener();
416
  });
417
});
418

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

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

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

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