dh-auth-library 2.2.3 → 2.3.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 +3 -2
- package/dist/auth/loginhandlers/adLoginHandler.d.ts +1 -0
- package/dist/auth/sessionHandler.d.ts +1 -0
- package/dist/index.cjs.js +41 -23
- package/dist/index.es.js +41 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,8 @@ A login has two parts:
|
|
|
47
47
|
|
|
48
48
|
`createSessionHandler(testProfile.authType, testProfile.account, loginHandler)` combines them, and
|
|
49
49
|
`SessionManager.getOrCreateSession` gives you a session file: it logs in when there is none, reuses it while it is younger than
|
|
50
|
-
`MAX_SESSION_TIME_IN_MINUTES`, and refreshes it after that.
|
|
50
|
+
`MAX_SESSION_TIME_IN_MINUTES`, and refreshes it after that. An `ad-session` logs in again instead, so a
|
|
51
|
+
longer max age (e.g. 24h) saves AD logins.
|
|
51
52
|
|
|
52
53
|
```ts
|
|
53
54
|
import { ADLoginHandler, createSessionHandler, DigidLoginHandler, MAX_SESSION_TIME_IN_MINUTES, TestProfile } from 'dh-auth-library';
|
|
@@ -199,7 +200,7 @@ navigate to the other.
|
|
|
199
200
|
## Known limitations
|
|
200
201
|
|
|
201
202
|
- `refreshSession` always opens `PORTAL_BASE_URL` to check the session, also for sessions of other
|
|
202
|
-
apps such as Open Forms. Because the DigiD session is shared (see above), an Open Forms session is
|
|
203
|
+
apps such as Open Forms (not for `ad-session`, which logs in again). Because the DigiD session is shared (see above), an Open Forms session is
|
|
203
204
|
checked through the klantportaal.
|
|
204
205
|
- Session file names have a fixed pattern, `<browser>-<authType>-<ENV>-<username>.json`, in
|
|
205
206
|
`SESSIONS_DIR` (default `./sessions`); only the folder can be changed. The app is not part of the
|
|
@@ -2,6 +2,7 @@ import { Page } from '@playwright/test';
|
|
|
2
2
|
import { Account } from 'nl-portal-playwright-libraries';
|
|
3
3
|
import { LoginHandler } from '../loginHandler';
|
|
4
4
|
import { LoginOptions } from '../pages/index';
|
|
5
|
+
/** Logs in to AD. Past the max age the session is logged in again, not refreshed, so a longer max age (e.g. 24h) saves logins. */
|
|
5
6
|
export declare class ADLoginHandler implements LoginHandler {
|
|
6
7
|
private readonly targetUrl;
|
|
7
8
|
private readonly options;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Account, SessionHandler } from 'nl-portal-playwright-libraries';
|
|
2
2
|
import { LoginHandler } from './loginHandler';
|
|
3
3
|
import { AuthType } from '../constants/index';
|
|
4
|
+
/** Default max age for `SessionManager.getOrCreateSession`. For an `ad-session`, a longer one (e.g. 24h) saves AD logins. */
|
|
4
5
|
export declare const MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
5
6
|
/**
|
|
6
7
|
* This class creates the correct SessionHandler
|
package/dist/index.cjs.js
CHANGED
|
@@ -218,6 +218,7 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
|
|
|
218
218
|
};
|
|
219
219
|
//#endregion
|
|
220
220
|
//#region src/auth/loginhandlers/adLoginHandler.ts
|
|
221
|
+
/** Logs in to AD. Past the max age the session is logged in again, not refreshed, so a longer max age (e.g. 24h) saves logins. */
|
|
221
222
|
var ADLoginHandler = class {
|
|
222
223
|
targetUrl;
|
|
223
224
|
options;
|
|
@@ -371,10 +372,12 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
371
372
|
await _playwright_test.test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
372
373
|
await this.openPage(startUrl);
|
|
373
374
|
await this.handleAnySpecialADLoginScreen();
|
|
375
|
+
this.page.waitForLoadState("networkidle");
|
|
374
376
|
try {
|
|
375
377
|
await loginButton.click();
|
|
376
378
|
} catch (_error) {
|
|
377
379
|
await this.openPage(startUrl);
|
|
380
|
+
await this.handleAnySpecialADLoginScreen();
|
|
378
381
|
await loginButton.click();
|
|
379
382
|
}
|
|
380
383
|
await this.loginWithDigid(account, true);
|
|
@@ -388,6 +391,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
388
391
|
*/
|
|
389
392
|
async handleAnySpecialADLoginScreen() {
|
|
390
393
|
try {
|
|
394
|
+
this.page.waitForLoadState("networkidle");
|
|
391
395
|
await this.page.locator(`//div[contains(@data-test-id,'${node_process.default.env.AD_USER}')]`).first().waitFor({ timeout: 1e3 });
|
|
392
396
|
await this.page.locator(`//div[contains(@data-test-id,'${node_process.default.env.AD_USER}')]`).first().click();
|
|
393
397
|
} catch (_error) {}
|
|
@@ -495,11 +499,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
495
499
|
const loginButton = options.loginButton(this.page);
|
|
496
500
|
const { startUrl } = options;
|
|
497
501
|
await this.openPage(startUrl);
|
|
502
|
+
this.page.waitForLoadState("networkidle");
|
|
498
503
|
try {
|
|
499
504
|
await loginButton.click();
|
|
500
505
|
} catch (_error) {
|
|
501
506
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
502
507
|
await this.openPage();
|
|
508
|
+
this.page.waitForLoadState("networkidle");
|
|
503
509
|
await this.loginButton.click();
|
|
504
510
|
}
|
|
505
511
|
await this.loginWithEHerkenning(account, options);
|
|
@@ -528,11 +534,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
528
534
|
const loginButton = options.loginButton(this.page);
|
|
529
535
|
const { startUrl } = options;
|
|
530
536
|
await this.openPage(startUrl);
|
|
537
|
+
this.page.waitForLoadState("networkidle");
|
|
531
538
|
try {
|
|
532
539
|
await loginButton.click();
|
|
533
540
|
} catch (_error) {
|
|
534
541
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
535
542
|
await this.openPage();
|
|
543
|
+
this.page.waitForLoadState("networkidle");
|
|
536
544
|
await loginButton.click();
|
|
537
545
|
}
|
|
538
546
|
await this.loginWithEHerkenningVestiging(account, options);
|
|
@@ -561,6 +569,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
561
569
|
const loginButton = options.loginButton(this.page);
|
|
562
570
|
const { startUrl } = options;
|
|
563
571
|
await this.openPage(startUrl);
|
|
572
|
+
this.page.waitForLoadState("networkidle");
|
|
564
573
|
await loginButton.click();
|
|
565
574
|
});
|
|
566
575
|
await _playwright_test.test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
@@ -719,6 +728,7 @@ function loginOptions(authType, options) {
|
|
|
719
728
|
}
|
|
720
729
|
//#endregion
|
|
721
730
|
//#region src/auth/sessionHandler.ts
|
|
731
|
+
/** Default max age for `SessionManager.getOrCreateSession`. For an `ad-session`, a longer one (e.g. 24h) saves AD logins. */
|
|
722
732
|
var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
723
733
|
/**
|
|
724
734
|
* This class creates the correct SessionHandler
|
|
@@ -729,6 +739,29 @@ var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
|
729
739
|
* @param loginHandler that will handle the login itself
|
|
730
740
|
*/
|
|
731
741
|
function createSessionHandler(authType, account, loginHandler) {
|
|
742
|
+
/**
|
|
743
|
+
* Setup the new session
|
|
744
|
+
* If needed the AD Session if used (Needed outside the firewall)
|
|
745
|
+
*
|
|
746
|
+
* @param browser
|
|
747
|
+
* @param file
|
|
748
|
+
*/
|
|
749
|
+
const setupSession = async (browser, file) => {
|
|
750
|
+
const useADSession = process.env.WITH_AD_SESSION === "true";
|
|
751
|
+
const page = await browser.newPage({
|
|
752
|
+
ignoreHTTPSErrors: true,
|
|
753
|
+
storageState: useADSession && authType !== "ad-session" ? SessionFileHelper.getADFileName(browser, {
|
|
754
|
+
username: `${process.env.AD_USER}`,
|
|
755
|
+
password: `${process.env.AD_PASSWORD}`
|
|
756
|
+
}) : void 0
|
|
757
|
+
});
|
|
758
|
+
console.log(`New session will be created: ${file}`);
|
|
759
|
+
try {
|
|
760
|
+
await loginHandler.loginAndCreateSessionStorage(page, account, file);
|
|
761
|
+
} finally {
|
|
762
|
+
await page.close();
|
|
763
|
+
}
|
|
764
|
+
};
|
|
732
765
|
return {
|
|
733
766
|
getFile: (browser) => {
|
|
734
767
|
switch (authType) {
|
|
@@ -741,39 +774,24 @@ function createSessionHandler(authType, account, loginHandler) {
|
|
|
741
774
|
default: throw new Error(`Unsupported auth type: ${authType}`);
|
|
742
775
|
}
|
|
743
776
|
},
|
|
744
|
-
|
|
745
|
-
* Setup the new session
|
|
746
|
-
* If needed the AD Session if used (Needed outside the firewall)
|
|
747
|
-
*
|
|
748
|
-
* @param browser
|
|
749
|
-
* @param file
|
|
750
|
-
*/
|
|
751
|
-
setupSession: async (browser, file) => {
|
|
752
|
-
const useADSession = process.env.WITH_AD_SESSION === "true";
|
|
753
|
-
const page = await browser.newPage({
|
|
754
|
-
ignoreHTTPSErrors: true,
|
|
755
|
-
storageState: useADSession && authType !== "ad-session" ? SessionFileHelper.getADFileName(browser, {
|
|
756
|
-
username: `${process.env.AD_USER}`,
|
|
757
|
-
password: `${process.env.AD_PASSWORD}`
|
|
758
|
-
}) : void 0
|
|
759
|
-
});
|
|
760
|
-
console.log(`New session will be created: ${file}`);
|
|
761
|
-
try {
|
|
762
|
-
await loginHandler.loginAndCreateSessionStorage(page, account, file);
|
|
763
|
-
} finally {
|
|
764
|
-
await page.close();
|
|
765
|
-
}
|
|
766
|
-
},
|
|
777
|
+
setupSession,
|
|
767
778
|
/**
|
|
768
779
|
* Refresh the current session by opening a page and storing that session
|
|
769
780
|
* The UI should have refreshed the session meanwhile
|
|
770
781
|
*
|
|
771
782
|
* This is being called from the nl-portal-base-library
|
|
772
783
|
*
|
|
784
|
+
* An AD session is logged in again from a clean context instead: PORTAL_BASE_URL doesn't check the Microsoft login.
|
|
785
|
+
*
|
|
773
786
|
* @param browser
|
|
774
787
|
* @param file
|
|
775
788
|
*/
|
|
776
789
|
refreshSession: async (browser, file) => {
|
|
790
|
+
if (authType === "ad-session") {
|
|
791
|
+
console.log(`AD session is too old and will be created again: ${file}`);
|
|
792
|
+
await setupSession(browser, file);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
777
795
|
const page = await browser.newPage({
|
|
778
796
|
ignoreHTTPSErrors: true,
|
|
779
797
|
storageState: file
|
package/dist/index.es.js
CHANGED
|
@@ -194,6 +194,7 @@ var ADLoginPage = class ADLoginPage extends BasePage {
|
|
|
194
194
|
};
|
|
195
195
|
//#endregion
|
|
196
196
|
//#region src/auth/loginhandlers/adLoginHandler.ts
|
|
197
|
+
/** Logs in to AD. Past the max age the session is logged in again, not refreshed, so a longer max age (e.g. 24h) saves logins. */
|
|
197
198
|
var ADLoginHandler = class {
|
|
198
199
|
targetUrl;
|
|
199
200
|
options;
|
|
@@ -347,10 +348,12 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
347
348
|
await test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
348
349
|
await this.openPage(startUrl);
|
|
349
350
|
await this.handleAnySpecialADLoginScreen();
|
|
351
|
+
this.page.waitForLoadState("networkidle");
|
|
350
352
|
try {
|
|
351
353
|
await loginButton.click();
|
|
352
354
|
} catch (_error) {
|
|
353
355
|
await this.openPage(startUrl);
|
|
356
|
+
await this.handleAnySpecialADLoginScreen();
|
|
354
357
|
await loginButton.click();
|
|
355
358
|
}
|
|
356
359
|
await this.loginWithDigid(account, true);
|
|
@@ -364,6 +367,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
364
367
|
*/
|
|
365
368
|
async handleAnySpecialADLoginScreen() {
|
|
366
369
|
try {
|
|
370
|
+
this.page.waitForLoadState("networkidle");
|
|
367
371
|
await this.page.locator(`//div[contains(@data-test-id,'${process$1.env.AD_USER}')]`).first().waitFor({ timeout: 1e3 });
|
|
368
372
|
await this.page.locator(`//div[contains(@data-test-id,'${process$1.env.AD_USER}')]`).first().click();
|
|
369
373
|
} catch (_error) {}
|
|
@@ -471,11 +475,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
471
475
|
const loginButton = options.loginButton(this.page);
|
|
472
476
|
const { startUrl } = options;
|
|
473
477
|
await this.openPage(startUrl);
|
|
478
|
+
this.page.waitForLoadState("networkidle");
|
|
474
479
|
try {
|
|
475
480
|
await loginButton.click();
|
|
476
481
|
} catch (_error) {
|
|
477
482
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
478
483
|
await this.openPage();
|
|
484
|
+
this.page.waitForLoadState("networkidle");
|
|
479
485
|
await this.loginButton.click();
|
|
480
486
|
}
|
|
481
487
|
await this.loginWithEHerkenning(account, options);
|
|
@@ -504,11 +510,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
504
510
|
const loginButton = options.loginButton(this.page);
|
|
505
511
|
const { startUrl } = options;
|
|
506
512
|
await this.openPage(startUrl);
|
|
513
|
+
this.page.waitForLoadState("networkidle");
|
|
507
514
|
try {
|
|
508
515
|
await loginButton.click();
|
|
509
516
|
} catch (_error) {
|
|
510
517
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
511
518
|
await this.openPage();
|
|
519
|
+
this.page.waitForLoadState("networkidle");
|
|
512
520
|
await loginButton.click();
|
|
513
521
|
}
|
|
514
522
|
await this.loginWithEHerkenningVestiging(account, options);
|
|
@@ -537,6 +545,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
537
545
|
const loginButton = options.loginButton(this.page);
|
|
538
546
|
const { startUrl } = options;
|
|
539
547
|
await this.openPage(startUrl);
|
|
548
|
+
this.page.waitForLoadState("networkidle");
|
|
540
549
|
await loginButton.click();
|
|
541
550
|
});
|
|
542
551
|
await test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
@@ -695,6 +704,7 @@ function loginOptions(authType, options) {
|
|
|
695
704
|
}
|
|
696
705
|
//#endregion
|
|
697
706
|
//#region src/auth/sessionHandler.ts
|
|
707
|
+
/** Default max age for `SessionManager.getOrCreateSession`. For an `ad-session`, a longer one (e.g. 24h) saves AD logins. */
|
|
698
708
|
var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
699
709
|
/**
|
|
700
710
|
* This class creates the correct SessionHandler
|
|
@@ -705,6 +715,29 @@ var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
|
705
715
|
* @param loginHandler that will handle the login itself
|
|
706
716
|
*/
|
|
707
717
|
function createSessionHandler(authType, account, loginHandler) {
|
|
718
|
+
/**
|
|
719
|
+
* Setup the new session
|
|
720
|
+
* If needed the AD Session if used (Needed outside the firewall)
|
|
721
|
+
*
|
|
722
|
+
* @param browser
|
|
723
|
+
* @param file
|
|
724
|
+
*/
|
|
725
|
+
const setupSession = async (browser, file) => {
|
|
726
|
+
const useADSession = process.env.WITH_AD_SESSION === "true";
|
|
727
|
+
const page = await browser.newPage({
|
|
728
|
+
ignoreHTTPSErrors: true,
|
|
729
|
+
storageState: useADSession && authType !== "ad-session" ? SessionFileHelper.getADFileName(browser, {
|
|
730
|
+
username: `${process.env.AD_USER}`,
|
|
731
|
+
password: `${process.env.AD_PASSWORD}`
|
|
732
|
+
}) : void 0
|
|
733
|
+
});
|
|
734
|
+
console.log(`New session will be created: ${file}`);
|
|
735
|
+
try {
|
|
736
|
+
await loginHandler.loginAndCreateSessionStorage(page, account, file);
|
|
737
|
+
} finally {
|
|
738
|
+
await page.close();
|
|
739
|
+
}
|
|
740
|
+
};
|
|
708
741
|
return {
|
|
709
742
|
getFile: (browser) => {
|
|
710
743
|
switch (authType) {
|
|
@@ -717,39 +750,24 @@ function createSessionHandler(authType, account, loginHandler) {
|
|
|
717
750
|
default: throw new Error(`Unsupported auth type: ${authType}`);
|
|
718
751
|
}
|
|
719
752
|
},
|
|
720
|
-
|
|
721
|
-
* Setup the new session
|
|
722
|
-
* If needed the AD Session if used (Needed outside the firewall)
|
|
723
|
-
*
|
|
724
|
-
* @param browser
|
|
725
|
-
* @param file
|
|
726
|
-
*/
|
|
727
|
-
setupSession: async (browser, file) => {
|
|
728
|
-
const useADSession = process.env.WITH_AD_SESSION === "true";
|
|
729
|
-
const page = await browser.newPage({
|
|
730
|
-
ignoreHTTPSErrors: true,
|
|
731
|
-
storageState: useADSession && authType !== "ad-session" ? SessionFileHelper.getADFileName(browser, {
|
|
732
|
-
username: `${process.env.AD_USER}`,
|
|
733
|
-
password: `${process.env.AD_PASSWORD}`
|
|
734
|
-
}) : void 0
|
|
735
|
-
});
|
|
736
|
-
console.log(`New session will be created: ${file}`);
|
|
737
|
-
try {
|
|
738
|
-
await loginHandler.loginAndCreateSessionStorage(page, account, file);
|
|
739
|
-
} finally {
|
|
740
|
-
await page.close();
|
|
741
|
-
}
|
|
742
|
-
},
|
|
753
|
+
setupSession,
|
|
743
754
|
/**
|
|
744
755
|
* Refresh the current session by opening a page and storing that session
|
|
745
756
|
* The UI should have refreshed the session meanwhile
|
|
746
757
|
*
|
|
747
758
|
* This is being called from the nl-portal-base-library
|
|
748
759
|
*
|
|
760
|
+
* An AD session is logged in again from a clean context instead: PORTAL_BASE_URL doesn't check the Microsoft login.
|
|
761
|
+
*
|
|
749
762
|
* @param browser
|
|
750
763
|
* @param file
|
|
751
764
|
*/
|
|
752
765
|
refreshSession: async (browser, file) => {
|
|
766
|
+
if (authType === "ad-session") {
|
|
767
|
+
console.log(`AD session is too old and will be created again: ${file}`);
|
|
768
|
+
await setupSession(browser, file);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
753
771
|
const page = await browser.newPage({
|
|
754
772
|
ignoreHTTPSErrors: true,
|
|
755
773
|
storageState: file
|