dh-auth-library 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/auth/pages/baseLoginPage.d.ts +10 -0
- package/dist/index.cjs.js +52 -5
- package/dist/index.es.js +52 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A Playwright library for all logins used by Den Haag applications: AD, DigiD and
|
|
|
4
4
|
It logs in, stores the session and keeps it alive during a test run, so each repository doesn't
|
|
5
5
|
need its own login implementation.
|
|
6
6
|
|
|
7
|
-
It is published as an npm package.
|
|
7
|
+
It is published as an npm package.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -22,6 +22,8 @@ export interface LoginOptions {
|
|
|
22
22
|
*/
|
|
23
23
|
excludeCookies?: Array<string>;
|
|
24
24
|
}
|
|
25
|
+
/** Whether `url` is authn (Keycloak) answering with a server error, e.g. its IdP broker endpoint with `error=server_error`. */
|
|
26
|
+
export declare function isAuthnServerError(url: string, status?: number): boolean;
|
|
25
27
|
export declare class BaseLoginPage extends BasePage {
|
|
26
28
|
constructor(page: Page);
|
|
27
29
|
/**
|
|
@@ -29,6 +31,14 @@ export declare class BaseLoginPage extends BasePage {
|
|
|
29
31
|
* throws instead of saving the page it ended on.
|
|
30
32
|
*/
|
|
31
33
|
waitForApp(options: LoginOptionsWithButton): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Runs `action`, but throws as soon as authn answers with a server error, instead of letting its next wait time out.
|
|
36
|
+
*/
|
|
37
|
+
failOnAuthnServerError<T>(action: () => Promise<T>): Promise<T>;
|
|
38
|
+
/** Waits for the redirects after the login button, which can land on an authn server error instead of the login. */
|
|
39
|
+
waitForLoginStart(): Promise<void>;
|
|
40
|
+
/** Throws when the page is on an authn server error, e.g. after a login button redirected there. */
|
|
41
|
+
throwOnAuthnServerError(): Promise<void>;
|
|
32
42
|
/**
|
|
33
43
|
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
34
44
|
*/
|
package/dist/index.cjs.js
CHANGED
|
@@ -310,6 +310,15 @@ var SessionFileHelper = class {
|
|
|
310
310
|
}
|
|
311
311
|
};
|
|
312
312
|
// src/auth/pages/baseLoginPage.ts
|
|
313
|
+
/** Whether `url` is authn (Keycloak) answering with a server error, e.g. its IdP broker endpoint with `error=server_error`. */
|
|
314
|
+
function isAuthnServerError(url, status = 200) {
|
|
315
|
+
const { hostname, searchParams } = new URL(url);
|
|
316
|
+
return hostname.startsWith("authn.") && (status >= 500 || searchParams.get("error") === "server_error");
|
|
317
|
+
}
|
|
318
|
+
function authnServerError(url, status) {
|
|
319
|
+
const { origin, pathname } = new URL(url);
|
|
320
|
+
return status !== void 0 && status >= 500 && status < 600 ? /* @__PURE__ */ new Error(`authn returned status ${status} on ${origin}${pathname}: this is not a test failure, contact Team ADM`) : /* @__PURE__ */ new Error(`authn returned an error on ${origin}${pathname} (status ${status ?? "unknown"}): verify the error yourself`);
|
|
321
|
+
}
|
|
313
322
|
var BaseLoginPage = class extends nl_portal_playwright_libraries.BasePage {
|
|
314
323
|
constructor(page) {
|
|
315
324
|
super(page);
|
|
@@ -323,11 +332,44 @@ var BaseLoginPage = class extends nl_portal_playwright_libraries.BasePage {
|
|
|
323
332
|
await this.page.waitForURL((url) => url.origin === appOrigin, {
|
|
324
333
|
waitUntil: "commit",
|
|
325
334
|
timeout: 3e4
|
|
326
|
-
}).catch(() => {
|
|
335
|
+
}).catch(async () => {
|
|
336
|
+
await this.throwOnAuthnServerError();
|
|
327
337
|
throw new Error(`Login didn't return to ${appOrigin}, stuck on ${this.page.url()}`);
|
|
328
338
|
});
|
|
329
339
|
}
|
|
330
340
|
/**
|
|
341
|
+
* Runs `action`, but throws as soon as authn answers with a server error, instead of letting its next wait time out.
|
|
342
|
+
*/
|
|
343
|
+
async failOnAuthnServerError(action) {
|
|
344
|
+
await this.throwOnAuthnServerError();
|
|
345
|
+
let onResponse = () => {};
|
|
346
|
+
const serverError = new Promise((_, reject) => {
|
|
347
|
+
onResponse = (response) => {
|
|
348
|
+
if (response.request().isNavigationRequest() && isAuthnServerError(response.url(), response.status())) reject(authnServerError(response.url(), response.status()));
|
|
349
|
+
};
|
|
350
|
+
this.page.on("response", onResponse);
|
|
351
|
+
});
|
|
352
|
+
try {
|
|
353
|
+
return await Promise.race([action(), serverError]);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
await this.throwOnAuthnServerError();
|
|
356
|
+
throw error;
|
|
357
|
+
} finally {
|
|
358
|
+
this.page.off("response", onResponse);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/** Waits for the redirects after the login button, which can land on an authn server error instead of the login. */
|
|
362
|
+
async waitForLoginStart() {
|
|
363
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
364
|
+
await this.throwOnAuthnServerError();
|
|
365
|
+
}
|
|
366
|
+
/** Throws when the page is on an authn server error, e.g. after a login button redirected there. */
|
|
367
|
+
async throwOnAuthnServerError() {
|
|
368
|
+
const url = this.page.url();
|
|
369
|
+
if (!isAuthnServerError(url)) return;
|
|
370
|
+
throw authnServerError(url, await this.page.evaluate(() => performance.getEntriesByType("navigation")[0]?.responseStatus).catch(() => void 0));
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
331
373
|
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
332
374
|
*/
|
|
333
375
|
async acceptCookiesForApp(options) {
|
|
@@ -375,6 +417,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
375
417
|
await this.handleAnySpecialADLoginScreen();
|
|
376
418
|
await loginButton.click();
|
|
377
419
|
}
|
|
420
|
+
await this.waitForLoginStart();
|
|
378
421
|
if (!this.page.url().match(/authn/)) {
|
|
379
422
|
await this.loginWithDigid(account);
|
|
380
423
|
await this.waitForApp(options);
|
|
@@ -403,6 +446,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
403
446
|
await this.handleAnySpecialADLoginScreen();
|
|
404
447
|
await loginButton.click();
|
|
405
448
|
}
|
|
449
|
+
await this.waitForLoginStart();
|
|
406
450
|
await this.loginWithDigid(account, true);
|
|
407
451
|
await this.waitForApp(options);
|
|
408
452
|
await this.acceptCookiesForApp(options);
|
|
@@ -414,7 +458,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
414
458
|
* @param gemachtigde whether to log in as an authorized representative (machtiging) instead of a regular user
|
|
415
459
|
*/
|
|
416
460
|
async loginWithDigid(account, gemachtigde) {
|
|
417
|
-
return await _playwright_test.test.step("Fill DigiD credentials and submit", async () => {
|
|
461
|
+
return await _playwright_test.test.step("Fill DigiD credentials and submit", async () => this.failOnAuthnServerError(async () => {
|
|
418
462
|
await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
|
|
419
463
|
await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
|
|
420
464
|
await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
|
|
@@ -423,7 +467,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
423
467
|
await this.page.getByRole("button", { name: "Inloggen" }).click();
|
|
424
468
|
if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
|
|
425
469
|
return await responsePromise;
|
|
426
|
-
});
|
|
470
|
+
}));
|
|
427
471
|
}
|
|
428
472
|
/**
|
|
429
473
|
* @param loginButton button that starts the DigiD machtigen login, supplied by the consumer of this library
|
|
@@ -515,7 +559,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
515
559
|
* @param account login details, supplied by the consumer of this library
|
|
516
560
|
*/
|
|
517
561
|
async tryLoginWithEHerkenning(account) {
|
|
518
|
-
await _playwright_test.test.step("Fill eHerkenning credentials and submit", async () => {
|
|
562
|
+
await _playwright_test.test.step("Fill eHerkenning credentials and submit", async () => this.failOnAuthnServerError(async () => {
|
|
519
563
|
await this.dropdownSelectIdentityProvider.or(this.textfieldUsername).first().waitFor();
|
|
520
564
|
if (await this.dropdownSelectIdentityProvider.isVisible()) {
|
|
521
565
|
await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
|
|
@@ -526,7 +570,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
526
570
|
await this.continueButton.click();
|
|
527
571
|
await maskedFill(this.textfieldPassword, account.password, "password");
|
|
528
572
|
await this.loginButton.click();
|
|
529
|
-
});
|
|
573
|
+
}));
|
|
530
574
|
}
|
|
531
575
|
/**
|
|
532
576
|
* @param fileName path of the storage state file to write the session to
|
|
@@ -547,6 +591,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
547
591
|
await this.handleAnySpecialADLoginScreen();
|
|
548
592
|
await loginButton.click();
|
|
549
593
|
}
|
|
594
|
+
await this.waitForLoginStart();
|
|
550
595
|
await this.loginWithEHerkenning(account, options);
|
|
551
596
|
await saveSession(this.page.context(), fileName, options.excludeCookies);
|
|
552
597
|
});
|
|
@@ -582,6 +627,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
582
627
|
await this.handleAnySpecialADLoginScreen();
|
|
583
628
|
await loginButton.click();
|
|
584
629
|
}
|
|
630
|
+
await this.waitForLoginStart();
|
|
585
631
|
await this.loginWithEHerkenningVestiging(account, options);
|
|
586
632
|
await saveSession(this.page.context(), fileName, options.excludeCookies);
|
|
587
633
|
});
|
|
@@ -610,6 +656,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
610
656
|
await this.openPage(startUrl);
|
|
611
657
|
await this.handleAnySpecialADLoginScreen();
|
|
612
658
|
await loginButton.click();
|
|
659
|
+
await this.waitForLoginStart();
|
|
613
660
|
};
|
|
614
661
|
await _playwright_test.test.step("Open bewindvoerder login option", async () => {
|
|
615
662
|
try {
|
package/dist/index.es.js
CHANGED
|
@@ -285,6 +285,15 @@ var SessionFileHelper = class {
|
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
287
|
// src/auth/pages/baseLoginPage.ts
|
|
288
|
+
/** Whether `url` is authn (Keycloak) answering with a server error, e.g. its IdP broker endpoint with `error=server_error`. */
|
|
289
|
+
function isAuthnServerError(url, status = 200) {
|
|
290
|
+
const { hostname, searchParams } = new URL(url);
|
|
291
|
+
return hostname.startsWith("authn.") && (status >= 500 || searchParams.get("error") === "server_error");
|
|
292
|
+
}
|
|
293
|
+
function authnServerError(url, status) {
|
|
294
|
+
const { origin, pathname } = new URL(url);
|
|
295
|
+
return status !== void 0 && status >= 500 && status < 600 ? /* @__PURE__ */ new Error(`authn returned status ${status} on ${origin}${pathname}: this is not a test failure, contact Team ADM`) : /* @__PURE__ */ new Error(`authn returned an error on ${origin}${pathname} (status ${status ?? "unknown"}): verify the error yourself`);
|
|
296
|
+
}
|
|
288
297
|
var BaseLoginPage = class extends BasePage {
|
|
289
298
|
constructor(page) {
|
|
290
299
|
super(page);
|
|
@@ -298,11 +307,44 @@ var BaseLoginPage = class extends BasePage {
|
|
|
298
307
|
await this.page.waitForURL((url) => url.origin === appOrigin, {
|
|
299
308
|
waitUntil: "commit",
|
|
300
309
|
timeout: 3e4
|
|
301
|
-
}).catch(() => {
|
|
310
|
+
}).catch(async () => {
|
|
311
|
+
await this.throwOnAuthnServerError();
|
|
302
312
|
throw new Error(`Login didn't return to ${appOrigin}, stuck on ${this.page.url()}`);
|
|
303
313
|
});
|
|
304
314
|
}
|
|
305
315
|
/**
|
|
316
|
+
* Runs `action`, but throws as soon as authn answers with a server error, instead of letting its next wait time out.
|
|
317
|
+
*/
|
|
318
|
+
async failOnAuthnServerError(action) {
|
|
319
|
+
await this.throwOnAuthnServerError();
|
|
320
|
+
let onResponse = () => {};
|
|
321
|
+
const serverError = new Promise((_, reject) => {
|
|
322
|
+
onResponse = (response) => {
|
|
323
|
+
if (response.request().isNavigationRequest() && isAuthnServerError(response.url(), response.status())) reject(authnServerError(response.url(), response.status()));
|
|
324
|
+
};
|
|
325
|
+
this.page.on("response", onResponse);
|
|
326
|
+
});
|
|
327
|
+
try {
|
|
328
|
+
return await Promise.race([action(), serverError]);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
await this.throwOnAuthnServerError();
|
|
331
|
+
throw error;
|
|
332
|
+
} finally {
|
|
333
|
+
this.page.off("response", onResponse);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/** Waits for the redirects after the login button, which can land on an authn server error instead of the login. */
|
|
337
|
+
async waitForLoginStart() {
|
|
338
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
339
|
+
await this.throwOnAuthnServerError();
|
|
340
|
+
}
|
|
341
|
+
/** Throws when the page is on an authn server error, e.g. after a login button redirected there. */
|
|
342
|
+
async throwOnAuthnServerError() {
|
|
343
|
+
const url = this.page.url();
|
|
344
|
+
if (!isAuthnServerError(url)) return;
|
|
345
|
+
throw authnServerError(url, await this.page.evaluate(() => performance.getEntriesByType("navigation")[0]?.responseStatus).catch(() => void 0));
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
306
348
|
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
307
349
|
*/
|
|
308
350
|
async acceptCookiesForApp(options) {
|
|
@@ -350,6 +392,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
350
392
|
await this.handleAnySpecialADLoginScreen();
|
|
351
393
|
await loginButton.click();
|
|
352
394
|
}
|
|
395
|
+
await this.waitForLoginStart();
|
|
353
396
|
if (!this.page.url().match(/authn/)) {
|
|
354
397
|
await this.loginWithDigid(account);
|
|
355
398
|
await this.waitForApp(options);
|
|
@@ -378,6 +421,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
378
421
|
await this.handleAnySpecialADLoginScreen();
|
|
379
422
|
await loginButton.click();
|
|
380
423
|
}
|
|
424
|
+
await this.waitForLoginStart();
|
|
381
425
|
await this.loginWithDigid(account, true);
|
|
382
426
|
await this.waitForApp(options);
|
|
383
427
|
await this.acceptCookiesForApp(options);
|
|
@@ -389,7 +433,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
389
433
|
* @param gemachtigde whether to log in as an authorized representative (machtiging) instead of a regular user
|
|
390
434
|
*/
|
|
391
435
|
async loginWithDigid(account, gemachtigde) {
|
|
392
|
-
return await test.step("Fill DigiD credentials and submit", async () => {
|
|
436
|
+
return await test.step("Fill DigiD credentials and submit", async () => this.failOnAuthnServerError(async () => {
|
|
393
437
|
await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
|
|
394
438
|
await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
|
|
395
439
|
await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
|
|
@@ -398,7 +442,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
398
442
|
await this.page.getByRole("button", { name: "Inloggen" }).click();
|
|
399
443
|
if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
|
|
400
444
|
return await responsePromise;
|
|
401
|
-
});
|
|
445
|
+
}));
|
|
402
446
|
}
|
|
403
447
|
/**
|
|
404
448
|
* @param loginButton button that starts the DigiD machtigen login, supplied by the consumer of this library
|
|
@@ -490,7 +534,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
490
534
|
* @param account login details, supplied by the consumer of this library
|
|
491
535
|
*/
|
|
492
536
|
async tryLoginWithEHerkenning(account) {
|
|
493
|
-
await test.step("Fill eHerkenning credentials and submit", async () => {
|
|
537
|
+
await test.step("Fill eHerkenning credentials and submit", async () => this.failOnAuthnServerError(async () => {
|
|
494
538
|
await this.dropdownSelectIdentityProvider.or(this.textfieldUsername).first().waitFor();
|
|
495
539
|
if (await this.dropdownSelectIdentityProvider.isVisible()) {
|
|
496
540
|
await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
|
|
@@ -501,7 +545,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
501
545
|
await this.continueButton.click();
|
|
502
546
|
await maskedFill(this.textfieldPassword, account.password, "password");
|
|
503
547
|
await this.loginButton.click();
|
|
504
|
-
});
|
|
548
|
+
}));
|
|
505
549
|
}
|
|
506
550
|
/**
|
|
507
551
|
* @param fileName path of the storage state file to write the session to
|
|
@@ -522,6 +566,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
522
566
|
await this.handleAnySpecialADLoginScreen();
|
|
523
567
|
await loginButton.click();
|
|
524
568
|
}
|
|
569
|
+
await this.waitForLoginStart();
|
|
525
570
|
await this.loginWithEHerkenning(account, options);
|
|
526
571
|
await saveSession(this.page.context(), fileName, options.excludeCookies);
|
|
527
572
|
});
|
|
@@ -557,6 +602,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
557
602
|
await this.handleAnySpecialADLoginScreen();
|
|
558
603
|
await loginButton.click();
|
|
559
604
|
}
|
|
605
|
+
await this.waitForLoginStart();
|
|
560
606
|
await this.loginWithEHerkenningVestiging(account, options);
|
|
561
607
|
await saveSession(this.page.context(), fileName, options.excludeCookies);
|
|
562
608
|
});
|
|
@@ -585,6 +631,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
585
631
|
await this.openPage(startUrl);
|
|
586
632
|
await this.handleAnySpecialADLoginScreen();
|
|
587
633
|
await loginButton.click();
|
|
634
|
+
await this.waitForLoginStart();
|
|
588
635
|
};
|
|
589
636
|
await test.step("Open bewindvoerder login option", async () => {
|
|
590
637
|
try {
|