-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathoidc.spec.ts
More file actions
536 lines (453 loc) · 19 KB
/
Copy pathoidc.spec.ts
File metadata and controls
536 lines (453 loc) · 19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
import { test, expect, Page, BrowserContext } from "@playwright/test";
import RHDHDeployment from "../../utils/authentication-providers/rhdh-deployment";
import { Common, setupBrowser } from "../../utils/common";
import { UIhelper } from "../../utils/ui-helper";
import { KeycloakHelper } from "../../utils/authentication-providers/keycloak-helper";
import { NO_USER_FOUND_IN_CATALOG_ERROR_MESSAGE } from "../../utils/constants";
let page: Page;
let context: BrowserContext;
/* SUPPORTED RESOLVERS
OIDC:
❗Changed from 1.5
[x] oidcSubClaimMatchingIdPUserId -> (Default, no setting specified)
[x] oidcSubClaimMatchingKeycloakUserId -> (same as above, but need to be set explicitly in the config)
[x] preferredUsernameMatchingUserEntityName (patched)
[x] emailLocalPartMatchingUserEntityName
[x] emailMatchingUserEntityProfileEmail -> email will always match, just making sure it logs in
[-] oidcSubClaimMatchingPingIdentityUserId -> Ping Identity not supported
*/
test.describe("Configure OIDC provider (using RHBK)", async () => {
let common: Common;
let uiHelper: UIhelper;
const namespace = "albarbaro-test-namespace-oidc";
const appConfigMap = "app-config-rhdh";
const rbacConfigMap = "rbac-policy";
const dynamicPluginsConfigMap = "dynamic-plugins";
const secretName = "rhdh-secrets";
const keycloakHelper = new KeycloakHelper({
baseUrl: process.env.RHBK_BASE_URL,
realmName: process.env.RHBK_REALM,
clientId: process.env.RHBK_CLIENT_ID,
clientSecret: process.env.RHBK_CLIENT_SECRET,
});
// set deployment instance
const deployment: RHDHDeployment = new RHDHDeployment(
namespace,
appConfigMap,
rbacConfigMap,
dynamicPluginsConfigMap,
secretName,
);
deployment.instanceName = "rhdh";
// compute backstage baseurl
const backstageUrl = await deployment.computeBackstageUrl();
const backstageBackendUrl = await deployment.computeBackstageBackendUrl();
console.log(`Backstage BaseURL is: ${backstageUrl}`);
test.use({ baseURL: backstageUrl });
test.beforeAll(async ({ browser }, testInfo) => {
test.info().annotations.push({
type: "component",
description: "authentication",
});
test.info().setTimeout(600 * 1000);
// load default configs from yaml files
await deployment.loadAllConfigs();
// setup playwright helpers
({ context, page } = await setupBrowser(browser, testInfo));
common = new Common(page);
uiHelper = new UIhelper(page);
// initialize keycloak helper
console.log("[TEST] Initializing Keycloak helper...");
await keycloakHelper.initialize();
console.log("[TEST] Keycloak helper initialized successfully");
// expect some expected variables
expect(process.env.DEFAULT_USER_PASSWORD).toBeDefined();
expect(process.env.RHBK_BASE_URL).toBeDefined();
expect(process.env.RHBK_REALM).toBeDefined();
expect(process.env.RHBK_CLIENT_ID).toBeDefined();
expect(process.env.RHBK_CLIENT_SECRET).toBeDefined();
// clean old namespaces
await deployment.deleteNamespaceIfExists();
// create namespace and wait for it to be active
await (await deployment.createNamespace()).waitForNamespaceActive();
// create all base configmaps
await deployment.createAllConfigs();
// generate static token
await deployment.generateStaticToken();
// set enviroment variables and create secret
if (!process.env.ISRUNNINGLOCAL) {
await deployment.addSecretData("BASE_URL", backstageUrl);
await deployment.addSecretData("BASE_BACKEND_URL", backstageBackendUrl);
}
await deployment.addSecretData(
"DEFAULT_USER_PASSWORD",
process.env.DEFAULT_USER_PASSWORD,
);
await deployment.addSecretData(
"DEFAULT_USER_PASSWORD_2",
process.env.DEFAULT_USER_PASSWORD_2,
);
await deployment.addSecretData("RHBK_BASE_URL", process.env.RHBK_BASE_URL);
await deployment.addSecretData("RHBK_REALM", process.env.RHBK_REALM);
await deployment.addSecretData(
"RHBK_CLIENT_ID",
process.env.RHBK_CLIENT_ID,
);
await deployment.addSecretData(
"RHBK_CLIENT_SECRET",
process.env.RHBK_CLIENT_SECRET,
);
await deployment.addSecretData(
"AUTH_PROVIDERS_GH_ORG_CLIENT_ID",
process.env.AUTH_PROVIDERS_GH_ORG_CLIENT_ID,
);
await deployment.addSecretData(
"AUTH_PROVIDERS_GH_ORG_CLIENT_SECRET",
process.env.AUTH_PROVIDERS_GH_ORG_CLIENT_SECRET,
);
await deployment.createSecret();
// create initial deployment
// enable keycloak login with ingestion
console.log("[TEST] Enabling OIDC login with ingestion...");
await deployment.enableOIDCLoginWithIngestion();
await deployment.updateAllConfigs();
console.log("[TEST] OIDC login with ingestion enabled successfully");
// create backstage deployment and wait for it to be ready
await deployment.createBackstageDeployment();
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
});
test.beforeEach(async () => {
test.info().setTimeout(600 * 1000);
console.log(
`Running test case ${test.info().title} - Attempt #${test.info().retry}`,
);
});
test("Login with OIDC default resolver", async () => {
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await uiHelper.hideQuickstartIfVisible();
// Click "Show more" button to display metadata info
await page.getByTitle("Show more").click();
// Verify Metadata text is present
await uiHelper.verifyText("RHDH Metadata");
await common.signOut();
});
test("Login with OIDC oidcSubClaimMatchingKeycloakUserId resolver", async () => {
await deployment.enableOIDCLoginWithIngestion();
await deployment.setOIDCResolver(
"oidcSubClaimMatchingKeycloakUserId",
false,
);
await deployment.updateAllConfigs();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.restartLocalDeployment();
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
});
test("Login with OIDC emailMatchingUserEntityProfileEmail resolver", async () => {
await deployment.setOIDCResolver(
"emailMatchingUserEntityProfileEmail",
false,
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
});
test("Login with OIDC emailLocalPartMatchingUserEntityName resolver", async () => {
await deployment.setOIDCResolver(
"emailLocalPartMatchingUserEntityName",
false,
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
const login2 = await common.keycloakLogin(
"atena",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login2).toBe("Login successful");
await uiHelper.verifyAlertErrorMessage(
NO_USER_FOUND_IN_CATALOG_ERROR_MESSAGE,
);
await keycloakHelper.initialize();
await keycloakHelper.clearUserSessions("atena");
});
test("Login with OIDC emailLocalPartMatchingUserEntityName with dangerouslyAllowSignInWithoutUserInCatalog resolver", async () => {
await deployment.setOIDCResolver(
"emailLocalPartMatchingUserEntityName",
true,
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
const login2 = await common.keycloakLogin(
"atena",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login2).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Atena Minerva");
await common.signOut();
});
test("Login with OIDC preferredUsernameMatchingUserEntityName resolver", async () => {
await deployment.setOIDCResolver(
"preferredUsernameMatchingUserEntityName",
false,
);
await deployment.updateAllConfigs();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.restartLocalDeployment();
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"atena",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Atena Minerva");
await common.signOut();
});
test(`Set sessionDuration and confirm in auth cookie duration has been set`, async () => {
deployment.setAppConfigProperty(
"auth.providers.oidc.production.sessionDuration",
"3days",
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await page.reload();
const cookies = await context.cookies();
const authCookie = cookies.find(
(cookie) => cookie.name === "oidc-refresh-token",
);
const threeDays = 3 * 24 * 60 * 60 * 1000; // expected duration of 3 days in ms
const tolerance = 3 * 60 * 1000; // allow for 3 minutes tolerance
const actualDuration = authCookie.expires * 1000 - Date.now();
expect(actualDuration).toBeGreaterThan(threeDays - tolerance);
expect(actualDuration).toBeLessThan(threeDays + tolerance);
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
});
test(`Ingestion of users and groups: verify the user entities and groups are created with the correct relationships`, async () => {
expect(
await deployment.checkUserIsIngestedInCatalog([
"Admin E2e",
"Atena Minerva",
"Elio Sole",
"Tyke Fortuna",
"Zeus Giove",
]),
).toBe(true);
expect(
await deployment.checkGroupIsIngestedInCatalog([
"admins",
"goddesses",
"gods",
]),
).toBe(true);
expect(await deployment.checkUserIsInGroup("admin", "admins")).toBe(true);
expect(await deployment.checkUserIsInGroup("zeus", "admins")).toBe(true);
expect(await deployment.checkUserIsInGroup("atena", "goddesses")).toBe(
true,
);
expect(await deployment.checkUserIsInGroup("tyke", "goddesses")).toBe(true);
expect(await deployment.checkUserIsInGroup("elio", "gods")).toBe(true);
expect(await deployment.checkUserIsInGroup("zeus", "gods")).toBe(true);
expect(await deployment.checkGroupIsChildOfGroup("gods", "all")).toBe(true);
expect(await deployment.checkGroupIsChildOfGroup("goddesses", "all")).toBe(
true,
);
expect(await deployment.checkGroupIsParentOfGroup("all", "gods")).toBe(
true,
);
expect(await deployment.checkGroupIsParentOfGroup("all", "goddesses")).toBe(
true,
);
});
test(`Ingestion of users and groups with invalid characters: check sanitize[User/Group]NameTransformer`, async () => {
expect(
await deployment.checkUserIsIngestedInCatalog(["Invalid Username"]),
).toBe(true);
expect(
await deployment.checkGroupIsIngestedInCatalog(["invalid@groupname"]),
).toBe(true);
});
test("Ensure Guest login is disabled when setting environment to production", async () => {
await uiHelper.goToPageUrl("/", "Select a sign-in method");
// Scope to the main content area to get only sign-in method card headers
const signInMethodsContainer = page.getByRole("main");
const singInMethods = await signInMethodsContainer
.getByRole("heading", { level: 6 })
.allInnerTexts();
expect(singInMethods).not.toContain("Guest");
});
test("Login with OIDC as primary sign in provider and GitHub auth as secondary", async () => {
const oidcLogin = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(oidcLogin).toBe("Login successful");
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
expect(process.env.AUTH_PROVIDERS_GH_ORG_CLIENT_SECRET).toBeDefined();
expect(process.env.AUTH_PROVIDERS_GH_ORG_CLIENT_ID).toBeDefined();
// set up GitHub auth
deployment.setAppConfigProperty("auth.providers.github", {
production: {
clientId: "${AUTH_PROVIDERS_GH_ORG_CLIENT_ID}",
clientSecret: "${AUTH_PROVIDERS_GH_ORG_CLIENT_SECRET}",
callbackUrl:
"${BASE_URL:-http://localhost:7007}/api/auth/github/handler/frame",
},
});
deployment.setAppConfigProperty(
"auth.providers.github.production.disableIdentityResolution",
"true",
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
await uiHelper.hideQuickstartIfVisible();
const ghLogin = await common.githubLoginFromSettingsPage(
"rhdhqeauth1",
process.env.AUTH_PROVIDERS_GH_USER_PASSWORD,
process.env.AUTH_PROVIDERS_GH_USER_2FA,
);
expect(ghLogin).toBe("Login successful");
// Sign out for GitHub
await page.getByTitle("Sign out from GitHub").click();
// Sign out for OIDC
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
await context.clearCookies();
});
test(`Enable autologout and user is logged out after inactivity`, async () => {
deployment.setAppConfigProperty("auth.autologout.enabled", "true");
deployment.setAppConfigProperty(
"auth.autologout.idleTimeoutMinutes",
0.5, // minimum allowed value is 0.5 minutes
);
deployment.setAppConfigProperty(
"auth.autologout.promptBeforeIdleSeconds",
5,
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.verifyTextVisible(
"Logging out due to inactivity",
false,
60000,
);
await page.waitForTimeout(5000);
await page.reload();
const cookies = await context.cookies();
const authCookie = cookies.find(
(cookie) => cookie.name === "oidc-refresh-token",
);
expect(authCookie).toBeUndefined();
});
test(`Enable autologout and user stays logged in after clicking "Don't log me out"`, async () => {
deployment.setAppConfigProperty("auth.autologout.enabled", "true");
deployment.setAppConfigProperty(
"auth.autologout.idleTimeoutMinutes",
0.5, // minimum allowed value is 0.5 minutes
);
deployment.setAppConfigProperty(
"auth.autologout.promptBeforeIdleSeconds",
5,
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000); // wait is needed or the openshift rollout won't be detected - WORKING A MORE PERMANENT FIX TO REMOVE EXPLICIT TIMEOUT - FOR NOW IT UNBLOCK THE TESTS
await deployment.waitForDeploymentReady();
// wait for rhdh first sync and portal to be reachable
await deployment.waitForSynced();
const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");
await uiHelper.clickButtonByText("Don't log me out", { timeout: 60000 });
await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
});
test.afterAll(async () => {
console.log("[TEST] Starting cleanup...");
await deployment.killRunningProcess();
console.log("[TEST] Cleanup completed");
});
});