dh-auth-library 2.2.2 → 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 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;
@@ -345,12 +346,12 @@ var DigidLoginPage = class extends BaseLoginPage {
345
346
  await this.openPage(startUrl);
346
347
  await this.handleAnySpecialADLoginScreen();
347
348
  try {
348
- await loginButton.click({ timeout: 3e4 });
349
+ await loginButton.click();
349
350
  } catch (_error) {
350
351
  console.error(`Loginbutton click failed with error: ${_error}`);
351
352
  await this.openPage(startUrl);
352
353
  await this.handleAnySpecialADLoginScreen();
353
- await loginButton.click({ timeout: 3e4 });
354
+ await loginButton.click();
354
355
  }
355
356
  if (!this.page.url().match(/authn/)) {
356
357
  await this.loginWithDigid(account);
@@ -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,10 +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) {
506
+ console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
501
507
  await this.openPage();
508
+ this.page.waitForLoadState("networkidle");
502
509
  await this.loginButton.click();
503
510
  }
504
511
  await this.loginWithEHerkenning(account, options);
@@ -527,10 +534,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
527
534
  const loginButton = options.loginButton(this.page);
528
535
  const { startUrl } = options;
529
536
  await this.openPage(startUrl);
537
+ this.page.waitForLoadState("networkidle");
530
538
  try {
531
539
  await loginButton.click();
532
540
  } catch (_error) {
541
+ console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
533
542
  await this.openPage();
543
+ this.page.waitForLoadState("networkidle");
534
544
  await loginButton.click();
535
545
  }
536
546
  await this.loginWithEHerkenningVestiging(account, options);
@@ -559,6 +569,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
559
569
  const loginButton = options.loginButton(this.page);
560
570
  const { startUrl } = options;
561
571
  await this.openPage(startUrl);
572
+ this.page.waitForLoadState("networkidle");
562
573
  await loginButton.click();
563
574
  });
564
575
  await _playwright_test.test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
@@ -717,6 +728,7 @@ function loginOptions(authType, options) {
717
728
  }
718
729
  //#endregion
719
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. */
720
732
  var MAX_SESSION_TIME_IN_MINUTES = 10;
721
733
  /**
722
734
  * This class creates the correct SessionHandler
@@ -727,6 +739,29 @@ var MAX_SESSION_TIME_IN_MINUTES = 10;
727
739
  * @param loginHandler that will handle the login itself
728
740
  */
729
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
+ };
730
765
  return {
731
766
  getFile: (browser) => {
732
767
  switch (authType) {
@@ -739,39 +774,24 @@ function createSessionHandler(authType, account, loginHandler) {
739
774
  default: throw new Error(`Unsupported auth type: ${authType}`);
740
775
  }
741
776
  },
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
- 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
- },
777
+ setupSession,
765
778
  /**
766
779
  * Refresh the current session by opening a page and storing that session
767
780
  * The UI should have refreshed the session meanwhile
768
781
  *
769
782
  * This is being called from the nl-portal-base-library
770
783
  *
784
+ * An AD session is logged in again from a clean context instead: PORTAL_BASE_URL doesn't check the Microsoft login.
785
+ *
771
786
  * @param browser
772
787
  * @param file
773
788
  */
774
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
+ }
775
795
  const page = await browser.newPage({
776
796
  ignoreHTTPSErrors: true,
777
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;
@@ -321,12 +322,12 @@ var DigidLoginPage = class extends BaseLoginPage {
321
322
  await this.openPage(startUrl);
322
323
  await this.handleAnySpecialADLoginScreen();
323
324
  try {
324
- await loginButton.click({ timeout: 3e4 });
325
+ await loginButton.click();
325
326
  } catch (_error) {
326
327
  console.error(`Loginbutton click failed with error: ${_error}`);
327
328
  await this.openPage(startUrl);
328
329
  await this.handleAnySpecialADLoginScreen();
329
- await loginButton.click({ timeout: 3e4 });
330
+ await loginButton.click();
330
331
  }
331
332
  if (!this.page.url().match(/authn/)) {
332
333
  await this.loginWithDigid(account);
@@ -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,10 +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) {
482
+ console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
477
483
  await this.openPage();
484
+ this.page.waitForLoadState("networkidle");
478
485
  await this.loginButton.click();
479
486
  }
480
487
  await this.loginWithEHerkenning(account, options);
@@ -503,10 +510,13 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
503
510
  const loginButton = options.loginButton(this.page);
504
511
  const { startUrl } = options;
505
512
  await this.openPage(startUrl);
513
+ this.page.waitForLoadState("networkidle");
506
514
  try {
507
515
  await loginButton.click();
508
516
  } catch (_error) {
517
+ console.error(`EHerkenning Loginbutton click failed with error: ${_error}`);
509
518
  await this.openPage();
519
+ this.page.waitForLoadState("networkidle");
510
520
  await loginButton.click();
511
521
  }
512
522
  await this.loginWithEHerkenningVestiging(account, options);
@@ -535,6 +545,7 @@ var EHerkenningLoginPage = class extends BaseLoginPage {
535
545
  const loginButton = options.loginButton(this.page);
536
546
  const { startUrl } = options;
537
547
  await this.openPage(startUrl);
548
+ this.page.waitForLoadState("networkidle");
538
549
  await loginButton.click();
539
550
  });
540
551
  await test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
@@ -693,6 +704,7 @@ function loginOptions(authType, options) {
693
704
  }
694
705
  //#endregion
695
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. */
696
708
  var MAX_SESSION_TIME_IN_MINUTES = 10;
697
709
  /**
698
710
  * This class creates the correct SessionHandler
@@ -703,6 +715,29 @@ var MAX_SESSION_TIME_IN_MINUTES = 10;
703
715
  * @param loginHandler that will handle the login itself
704
716
  */
705
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
+ };
706
741
  return {
707
742
  getFile: (browser) => {
708
743
  switch (authType) {
@@ -715,39 +750,24 @@ function createSessionHandler(authType, account, loginHandler) {
715
750
  default: throw new Error(`Unsupported auth type: ${authType}`);
716
751
  }
717
752
  },
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
- 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
- },
753
+ setupSession,
741
754
  /**
742
755
  * Refresh the current session by opening a page and storing that session
743
756
  * The UI should have refreshed the session meanwhile
744
757
  *
745
758
  * This is being called from the nl-portal-base-library
746
759
  *
760
+ * An AD session is logged in again from a clean context instead: PORTAL_BASE_URL doesn't check the Microsoft login.
761
+ *
747
762
  * @param browser
748
763
  * @param file
749
764
  */
750
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
+ }
751
771
  const page = await browser.newPage({
752
772
  ignoreHTTPSErrors: true,
753
773
  storageState: file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dh-auth-library",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Gemeente-DenHaag/dh-auth-library.git"