dh-auth-library 2.2.3 → 2.4.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 +44 -24
- package/dist/index.es.js +44 -24
- 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
|
@@ -156,7 +156,9 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
|
|
|
156
156
|
await adLoginPage.usernameInput.waitFor();
|
|
157
157
|
await adLoginPage.usernameInput.fill(account.username);
|
|
158
158
|
await adLoginPage.nextInput.click();
|
|
159
|
-
|
|
159
|
+
const usePasswordLink = this.page.getByText("Uw wachtwoord gebruiken");
|
|
160
|
+
await usePasswordLink.or(adLoginPage.passwordInput).filter({ visible: true }).first().waitFor();
|
|
161
|
+
if (await usePasswordLink.isVisible()) await usePasswordLink.click();
|
|
160
162
|
}
|
|
161
163
|
});
|
|
162
164
|
let sessionWasStale = false;
|
|
@@ -218,6 +220,7 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
|
|
|
218
220
|
};
|
|
219
221
|
//#endregion
|
|
220
222
|
//#region src/auth/loginhandlers/adLoginHandler.ts
|
|
223
|
+
/** 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
224
|
var ADLoginHandler = class {
|
|
222
225
|
targetUrl;
|
|
223
226
|
options;
|
|
@@ -371,10 +374,12 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
371
374
|
await _playwright_test.test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
372
375
|
await this.openPage(startUrl);
|
|
373
376
|
await this.handleAnySpecialADLoginScreen();
|
|
377
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
374
378
|
try {
|
|
375
379
|
await loginButton.click();
|
|
376
380
|
} catch (_error) {
|
|
377
381
|
await this.openPage(startUrl);
|
|
382
|
+
await this.handleAnySpecialADLoginScreen();
|
|
378
383
|
await loginButton.click();
|
|
379
384
|
}
|
|
380
385
|
await this.loginWithDigid(account, true);
|
|
@@ -388,6 +393,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
388
393
|
*/
|
|
389
394
|
async handleAnySpecialADLoginScreen() {
|
|
390
395
|
try {
|
|
396
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
391
397
|
await this.page.locator(`//div[contains(@data-test-id,'${node_process.default.env.AD_USER}')]`).first().waitFor({ timeout: 1e3 });
|
|
392
398
|
await this.page.locator(`//div[contains(@data-test-id,'${node_process.default.env.AD_USER}')]`).first().click();
|
|
393
399
|
} catch (_error) {}
|
|
@@ -495,11 +501,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
495
501
|
const loginButton = options.loginButton(this.page);
|
|
496
502
|
const { startUrl } = options;
|
|
497
503
|
await this.openPage(startUrl);
|
|
504
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
498
505
|
try {
|
|
499
506
|
await loginButton.click();
|
|
500
507
|
} catch (_error) {
|
|
501
508
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
502
509
|
await this.openPage();
|
|
510
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
503
511
|
await this.loginButton.click();
|
|
504
512
|
}
|
|
505
513
|
await this.loginWithEHerkenning(account, options);
|
|
@@ -528,11 +536,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
528
536
|
const loginButton = options.loginButton(this.page);
|
|
529
537
|
const { startUrl } = options;
|
|
530
538
|
await this.openPage(startUrl);
|
|
539
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
531
540
|
try {
|
|
532
541
|
await loginButton.click();
|
|
533
542
|
} catch (_error) {
|
|
534
543
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
535
544
|
await this.openPage();
|
|
545
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
536
546
|
await loginButton.click();
|
|
537
547
|
}
|
|
538
548
|
await this.loginWithEHerkenningVestiging(account, options);
|
|
@@ -561,6 +571,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
561
571
|
const loginButton = options.loginButton(this.page);
|
|
562
572
|
const { startUrl } = options;
|
|
563
573
|
await this.openPage(startUrl);
|
|
574
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
564
575
|
await loginButton.click();
|
|
565
576
|
});
|
|
566
577
|
await _playwright_test.test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
@@ -719,6 +730,7 @@ function loginOptions(authType, options) {
|
|
|
719
730
|
}
|
|
720
731
|
//#endregion
|
|
721
732
|
//#region src/auth/sessionHandler.ts
|
|
733
|
+
/** Default max age for `SessionManager.getOrCreateSession`. For an `ad-session`, a longer one (e.g. 24h) saves AD logins. */
|
|
722
734
|
var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
723
735
|
/**
|
|
724
736
|
* This class creates the correct SessionHandler
|
|
@@ -729,6 +741,29 @@ var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
|
729
741
|
* @param loginHandler that will handle the login itself
|
|
730
742
|
*/
|
|
731
743
|
function createSessionHandler(authType, account, loginHandler) {
|
|
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
|
+
const 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
|
+
};
|
|
732
767
|
return {
|
|
733
768
|
getFile: (browser) => {
|
|
734
769
|
switch (authType) {
|
|
@@ -741,39 +776,24 @@ function createSessionHandler(authType, account, loginHandler) {
|
|
|
741
776
|
default: throw new Error(`Unsupported auth type: ${authType}`);
|
|
742
777
|
}
|
|
743
778
|
},
|
|
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
|
-
},
|
|
779
|
+
setupSession,
|
|
767
780
|
/**
|
|
768
781
|
* Refresh the current session by opening a page and storing that session
|
|
769
782
|
* The UI should have refreshed the session meanwhile
|
|
770
783
|
*
|
|
771
784
|
* This is being called from the nl-portal-base-library
|
|
772
785
|
*
|
|
786
|
+
* An AD session is logged in again from a clean context instead: PORTAL_BASE_URL doesn't check the Microsoft login.
|
|
787
|
+
*
|
|
773
788
|
* @param browser
|
|
774
789
|
* @param file
|
|
775
790
|
*/
|
|
776
791
|
refreshSession: async (browser, file) => {
|
|
792
|
+
if (authType === "ad-session") {
|
|
793
|
+
console.log(`AD session is too old and will be created again: ${file}`);
|
|
794
|
+
await setupSession(browser, file);
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
777
797
|
const page = await browser.newPage({
|
|
778
798
|
ignoreHTTPSErrors: true,
|
|
779
799
|
storageState: file
|
package/dist/index.es.js
CHANGED
|
@@ -132,7 +132,9 @@ var ADLoginPage = class ADLoginPage extends BasePage {
|
|
|
132
132
|
await adLoginPage.usernameInput.waitFor();
|
|
133
133
|
await adLoginPage.usernameInput.fill(account.username);
|
|
134
134
|
await adLoginPage.nextInput.click();
|
|
135
|
-
|
|
135
|
+
const usePasswordLink = this.page.getByText("Uw wachtwoord gebruiken");
|
|
136
|
+
await usePasswordLink.or(adLoginPage.passwordInput).filter({ visible: true }).first().waitFor();
|
|
137
|
+
if (await usePasswordLink.isVisible()) await usePasswordLink.click();
|
|
136
138
|
}
|
|
137
139
|
});
|
|
138
140
|
let sessionWasStale = false;
|
|
@@ -194,6 +196,7 @@ var ADLoginPage = class ADLoginPage extends BasePage {
|
|
|
194
196
|
};
|
|
195
197
|
//#endregion
|
|
196
198
|
//#region src/auth/loginhandlers/adLoginHandler.ts
|
|
199
|
+
/** 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
200
|
var ADLoginHandler = class {
|
|
198
201
|
targetUrl;
|
|
199
202
|
options;
|
|
@@ -347,10 +350,12 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
347
350
|
await test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
348
351
|
await this.openPage(startUrl);
|
|
349
352
|
await this.handleAnySpecialADLoginScreen();
|
|
353
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
350
354
|
try {
|
|
351
355
|
await loginButton.click();
|
|
352
356
|
} catch (_error) {
|
|
353
357
|
await this.openPage(startUrl);
|
|
358
|
+
await this.handleAnySpecialADLoginScreen();
|
|
354
359
|
await loginButton.click();
|
|
355
360
|
}
|
|
356
361
|
await this.loginWithDigid(account, true);
|
|
@@ -364,6 +369,7 @@ var DigidLoginPage = class extends BaseLoginPage {
|
|
|
364
369
|
*/
|
|
365
370
|
async handleAnySpecialADLoginScreen() {
|
|
366
371
|
try {
|
|
372
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
367
373
|
await this.page.locator(`//div[contains(@data-test-id,'${process$1.env.AD_USER}')]`).first().waitFor({ timeout: 1e3 });
|
|
368
374
|
await this.page.locator(`//div[contains(@data-test-id,'${process$1.env.AD_USER}')]`).first().click();
|
|
369
375
|
} catch (_error) {}
|
|
@@ -471,11 +477,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
471
477
|
const loginButton = options.loginButton(this.page);
|
|
472
478
|
const { startUrl } = options;
|
|
473
479
|
await this.openPage(startUrl);
|
|
480
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
474
481
|
try {
|
|
475
482
|
await loginButton.click();
|
|
476
483
|
} catch (_error) {
|
|
477
484
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
478
485
|
await this.openPage();
|
|
486
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
479
487
|
await this.loginButton.click();
|
|
480
488
|
}
|
|
481
489
|
await this.loginWithEHerkenning(account, options);
|
|
@@ -504,11 +512,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
504
512
|
const loginButton = options.loginButton(this.page);
|
|
505
513
|
const { startUrl } = options;
|
|
506
514
|
await this.openPage(startUrl);
|
|
515
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
507
516
|
try {
|
|
508
517
|
await loginButton.click();
|
|
509
518
|
} catch (_error) {
|
|
510
519
|
console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
|
|
511
520
|
await this.openPage();
|
|
521
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
512
522
|
await loginButton.click();
|
|
513
523
|
}
|
|
514
524
|
await this.loginWithEHerkenningVestiging(account, options);
|
|
@@ -537,6 +547,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
|
537
547
|
const loginButton = options.loginButton(this.page);
|
|
538
548
|
const { startUrl } = options;
|
|
539
549
|
await this.openPage(startUrl);
|
|
550
|
+
await this.page.waitForLoadState("networkidle", { timeout: 1e4 }).catch(() => {});
|
|
540
551
|
await loginButton.click();
|
|
541
552
|
});
|
|
542
553
|
await test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
@@ -695,6 +706,7 @@ function loginOptions(authType, options) {
|
|
|
695
706
|
}
|
|
696
707
|
//#endregion
|
|
697
708
|
//#region src/auth/sessionHandler.ts
|
|
709
|
+
/** Default max age for `SessionManager.getOrCreateSession`. For an `ad-session`, a longer one (e.g. 24h) saves AD logins. */
|
|
698
710
|
var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
699
711
|
/**
|
|
700
712
|
* This class creates the correct SessionHandler
|
|
@@ -705,6 +717,29 @@ var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
|
705
717
|
* @param loginHandler that will handle the login itself
|
|
706
718
|
*/
|
|
707
719
|
function createSessionHandler(authType, account, loginHandler) {
|
|
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
|
+
const 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
|
+
};
|
|
708
743
|
return {
|
|
709
744
|
getFile: (browser) => {
|
|
710
745
|
switch (authType) {
|
|
@@ -717,39 +752,24 @@ function createSessionHandler(authType, account, loginHandler) {
|
|
|
717
752
|
default: throw new Error(`Unsupported auth type: ${authType}`);
|
|
718
753
|
}
|
|
719
754
|
},
|
|
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
|
-
},
|
|
755
|
+
setupSession,
|
|
743
756
|
/**
|
|
744
757
|
* Refresh the current session by opening a page and storing that session
|
|
745
758
|
* The UI should have refreshed the session meanwhile
|
|
746
759
|
*
|
|
747
760
|
* This is being called from the nl-portal-base-library
|
|
748
761
|
*
|
|
762
|
+
* An AD session is logged in again from a clean context instead: PORTAL_BASE_URL doesn't check the Microsoft login.
|
|
763
|
+
*
|
|
749
764
|
* @param browser
|
|
750
765
|
* @param file
|
|
751
766
|
*/
|
|
752
767
|
refreshSession: async (browser, file) => {
|
|
768
|
+
if (authType === "ad-session") {
|
|
769
|
+
console.log(`AD session is too old and will be created again: ${file}`);
|
|
770
|
+
await setupSession(browser, file);
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
753
773
|
const page = await browser.newPage({
|
|
754
774
|
ignoreHTTPSErrors: true,
|
|
755
775
|
storageState: file
|