dh-auth-library 1.5.1 → 1.6.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.
@@ -1 +1,2 @@
1
1
  export { SessionFileHelper } from './sessionFileHelper';
2
+ export { maskedFill } from './maskedFill';
@@ -0,0 +1,2 @@
1
+ import { Locator } from '@playwright/test';
2
+ export declare function maskedFill(locator: Locator, value: string, propertyName: string, forceMask?: boolean): Promise<void>;
package/dist/index.cjs.js CHANGED
@@ -22,9 +22,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  }) : target, mod));
23
23
  //#endregion
24
24
  let nl_portal_playwright_libraries = require("nl-portal-playwright-libraries");
25
+ let _playwright_test = require("@playwright/test");
25
26
  let node_process = require("node:process");
26
27
  node_process = __toESM(node_process);
27
- let _playwright_test = require("@playwright/test");
28
28
  let totp_generator = require("totp-generator");
29
29
  let node_path = require("node:path");
30
30
  node_path = __toESM(node_path);
@@ -102,6 +102,30 @@ var LoginOverzichtPage = class extends nl_portal_playwright_libraries.BasePage {
102
102
  }
103
103
  };
104
104
  //#endregion
105
+ //#region src/auth/utils/maskedFill.ts
106
+ function isEnvValue(value) {
107
+ return value !== "" && Object.values(process.env).includes(value);
108
+ }
109
+ async function maskedFill(locator, value, propertyName, forceMask = false) {
110
+ const shouldMask = forceMask || isEnvValue(value);
111
+ const displayValue = shouldMask ? "[MASKED VALUE]" : value;
112
+ await _playwright_test.test.step(`Fill "${propertyName}" with value: "${displayValue}"`, async () => {
113
+ if (!shouldMask) {
114
+ await locator.fill(value);
115
+ return;
116
+ }
117
+ await locator.focus();
118
+ await locator.evaluate((el, val) => {
119
+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
120
+ el.value = val;
121
+ el.dispatchEvent(new Event("input", { bubbles: true }));
122
+ el.dispatchEvent(new Event("change", { bubbles: true }));
123
+ }
124
+ }, value);
125
+ await locator.blur();
126
+ });
127
+ }
128
+ //#endregion
105
129
  //#region src/auth/pages/digidLoginPage.ts
106
130
  var DigidLoginPage = class extends LoginOverzichtPage {
107
131
  constructor(page) {
@@ -112,37 +136,41 @@ var DigidLoginPage = class extends LoginOverzichtPage {
112
136
  * @param fileName path of the storage state file to write the session to
113
137
  */
114
138
  async loginAndCreateNewSession(account, fileName) {
115
- await this.openPage();
116
- await this.handleAnySpecialADLoginScreen();
117
- try {
118
- await this.klikOpDigidLoginOptie();
119
- } catch (_error) {
139
+ await _playwright_test.test.step("Login with DigiD and create session", async () => {
120
140
  await this.openPage();
121
141
  await this.handleAnySpecialADLoginScreen();
122
- await this.klikOpDigidLoginOptie();
123
- }
124
- if (!this.page.url().match(/authn/)) {
125
- await this.loginWithDigid(account);
126
- await this.accepteerCookies();
127
- }
128
- await this.page.context().storageState({ path: fileName });
142
+ try {
143
+ await this.klikOpDigidLoginOptie();
144
+ } catch (_error) {
145
+ await this.openPage();
146
+ await this.handleAnySpecialADLoginScreen();
147
+ await this.klikOpDigidLoginOptie();
148
+ }
149
+ if (!this.page.url().match(/authn/)) {
150
+ await this.loginWithDigid(account);
151
+ await this.accepteerCookies();
152
+ }
153
+ await this.page.context().storageState({ path: fileName });
154
+ });
129
155
  }
130
156
  /**
131
157
  * @param account login details, supplied by the consumer of this library
132
158
  * @param fileName path of the storage state file to write the session to
133
159
  */
134
160
  async loginAndCreateNewGemachtigdeSession(account, fileName) {
135
- await this.openPage();
136
- await this.handleAnySpecialADLoginScreen();
137
- try {
138
- await this.klikOpDigidMachtigenLoginOptie();
139
- } catch (_error) {
161
+ await _playwright_test.test.step("Login with DigiD as gemachtigde and create session", async () => {
140
162
  await this.openPage();
141
- await this.klikOpDigidMachtigenLoginOptie();
142
- }
143
- await this.loginWithDigid(account, true);
144
- await this.accepteerCookies();
145
- await this.page.context().storageState({ path: fileName });
163
+ await this.handleAnySpecialADLoginScreen();
164
+ try {
165
+ await this.klikOpDigidMachtigenLoginOptie();
166
+ } catch (_error) {
167
+ await this.openPage();
168
+ await this.klikOpDigidMachtigenLoginOptie();
169
+ }
170
+ await this.loginWithDigid(account, true);
171
+ await this.accepteerCookies();
172
+ await this.page.context().storageState({ path: fileName });
173
+ });
146
174
  }
147
175
  /**
148
176
  * Indien er al een AD sessie is maar voor de verkeerde omgeving
@@ -159,22 +187,26 @@ var DigidLoginPage = class extends LoginOverzichtPage {
159
187
  * @param gemachtigde whether to log in as an authorized representative (machtiging) instead of a regular user
160
188
  */
161
189
  async loginWithDigid(account, gemachtigde) {
162
- await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
163
- await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
164
- await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
165
- await this.page.getByLabel("Wachtwoord", { exact: true }).fill(account.password);
166
- const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
167
- await this.page.getByRole("button", { name: "Inloggen" }).click();
168
- if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
169
- return await responsePromise;
190
+ return await _playwright_test.test.step("Fill DigiD credentials and submit", async () => {
191
+ await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
192
+ await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
193
+ await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
194
+ await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "wachtwoord");
195
+ const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
196
+ await this.page.getByRole("button", { name: "Inloggen" }).click();
197
+ if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
198
+ return await responsePromise;
199
+ });
170
200
  }
171
201
  async loginAlsDigidGemachtigde() {
172
- const gemachtigde = {
173
- username: `${node_process.default.env.DIGID_GEMACHTIGDE_USER}`,
174
- password: `${node_process.default.env.DIGID_GEMACHTIGDE_PASSWORD}`
175
- };
176
- await this.klikOpDigidMachtigenLoginOptie();
177
- await this.loginWithDigid(gemachtigde, true);
202
+ await _playwright_test.test.step("Login as DigiD gemachtigde", async () => {
203
+ const gemachtigde = {
204
+ username: `${node_process.default.env.DIGID_GEMACHTIGDE_USER}`,
205
+ password: `${node_process.default.env.DIGID_GEMACHTIGDE_PASSWORD}`
206
+ };
207
+ await this.klikOpDigidMachtigenLoginOptie();
208
+ await this.loginWithDigid(gemachtigde, true);
209
+ });
178
210
  }
179
211
  };
180
212
  //#endregion
@@ -217,83 +249,101 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
217
249
  * @param account login details, supplied by the consumer of this library
218
250
  */
219
251
  async probeerInTeLoggenMetEHerkenning(account) {
220
- await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
221
- await this.page.locator("#remember").click();
222
- await this.buttonConfirmIdentityProviderSelection.click();
223
- await this.textfieldUsername.fill(account.username);
224
- await this.verderKnop.click();
225
- await this.textfieldPassword.fill(account.password);
226
- await this.inloggenKnop.click();
252
+ await _playwright_test.test.step("Fill eHerkenning credentials and submit", async () => {
253
+ await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
254
+ await this.page.locator("#remember").click();
255
+ await this.buttonConfirmIdentityProviderSelection.click();
256
+ await this.textfieldUsername.fill(account.username);
257
+ await this.verderKnop.click();
258
+ await maskedFill(this.textfieldPassword, account.password, "wachtwoord");
259
+ await this.inloggenKnop.click();
260
+ });
227
261
  }
228
262
  /**
229
263
  * @param fileName path of the storage state file to write the session to
230
264
  * @param account login details, supplied by the consumer of this library
231
265
  */
232
266
  async loginWithEHerkenningAndCreateSession(fileName, account) {
233
- await this.openPage();
234
- try {
235
- await this.klikOpEHerkenningLoginOptie();
236
- } catch (_error) {
267
+ await _playwright_test.test.step("Login with eHerkenning and create session", async () => {
237
268
  await this.openPage();
238
- await this.klikOpEHerkenningLoginOptie();
239
- }
240
- await this.loginWithEHerkenning(account);
241
- await this.page.context().storageState({ path: fileName });
269
+ try {
270
+ await this.klikOpEHerkenningLoginOptie();
271
+ } catch (_error) {
272
+ await this.openPage();
273
+ await this.klikOpEHerkenningLoginOptie();
274
+ }
275
+ await this.loginWithEHerkenning(account);
276
+ await this.page.context().storageState({ path: fileName });
277
+ });
242
278
  }
243
279
  /**
244
280
  * @param account login details, supplied by the consumer of this library
245
281
  */
246
282
  async loginWithEHerkenning(account) {
247
283
  await this.probeerInTeLoggenMetEHerkenning(account);
248
- await this.page.waitForTimeout(2e3);
249
- if (await this.verderKnop.isVisible()) await this.verderKnop.click();
250
- await this.accepteerCookies();
284
+ await _playwright_test.test.step("Confirm eHerkenning login and accept cookies", async () => {
285
+ await this.page.waitForTimeout(2e3);
286
+ if (await this.verderKnop.isVisible()) await this.verderKnop.click();
287
+ await this.accepteerCookies();
288
+ });
251
289
  }
252
290
  /**
253
291
  * @param fileName path of the storage state file to write the session to
254
292
  * @param account login details, supplied by the consumer of this library
255
293
  */
256
294
  async loginWithEHerkenningVestigingAndCreateSession(fileName, account) {
257
- await this.openPage();
258
- try {
259
- await this.klikOpEHerkenningLoginOptie();
260
- } catch (_error) {
295
+ await _playwright_test.test.step("Login with eHerkenning vestiging and create session", async () => {
261
296
  await this.openPage();
262
- await this.klikOpEHerkenningLoginOptie();
263
- }
264
- await this.loginWithEHerkenningVestiging(account);
265
- await this.page.context().storageState({ path: fileName });
297
+ try {
298
+ await this.klikOpEHerkenningLoginOptie();
299
+ } catch (_error) {
300
+ await this.openPage();
301
+ await this.klikOpEHerkenningLoginOptie();
302
+ }
303
+ await this.loginWithEHerkenningVestiging(account);
304
+ await this.page.context().storageState({ path: fileName });
305
+ });
266
306
  }
267
307
  /**
268
308
  * @param account login details, supplied by the consumer of this library
269
309
  */
270
310
  async loginWithEHerkenningVestiging(account) {
271
311
  await this.probeerInTeLoggenMetEHerkenning(account);
272
- await this.page.waitForTimeout(2e3);
273
- if (await this.verderKnop.isVisible()) await this.verderKnop.click();
274
- await this.accepteerCookies();
312
+ await _playwright_test.test.step("Confirm eHerkenning vestiging login and accept cookies", async () => {
313
+ await this.page.waitForTimeout(2e3);
314
+ if (await this.verderKnop.isVisible()) await this.verderKnop.click();
315
+ await this.accepteerCookies();
316
+ });
275
317
  }
276
318
  /**
277
319
  * @param gemachtigde login details of the authorized representative (bewindvoerder), supplied by the consumer of this library
278
320
  * @param file optional path of the storage state file to write the session to
279
321
  */
280
322
  async loginAlsProfessioneelBewindvoerder(gemachtigde, file) {
281
- await this.openPage();
282
- await this.klikOpProfessioneelBewindvoerderLoginOptie();
283
- try {
284
- await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
285
- } catch (_error) {
323
+ await _playwright_test.test.step("Open bewindvoerder login option", async () => {
286
324
  await this.openPage();
287
- await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
288
- }
289
- if (gemachtigde.bsn != null) {
325
+ await this.klikOpProfessioneelBewindvoerderLoginOptie();
326
+ });
327
+ await _playwright_test.test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
328
+ try {
329
+ await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
330
+ } catch (_error) {
331
+ await this.openPage();
332
+ await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
333
+ }
334
+ });
335
+ await _playwright_test.test.step("Search for client by BSN and accept cookies", async () => {
336
+ if (gemachtigde.bsn != null) {
337
+ await this.verderLink.click();
338
+ await maskedFill(this.inputBsn, gemachtigde.bsn, "bsn");
339
+ }
340
+ await this.buttonZoek.click();
290
341
  await this.verderLink.click();
291
- await this.inputBsn.fill(gemachtigde.bsn);
292
- }
293
- await this.buttonZoek.click();
294
- await this.verderLink.click();
295
- await this.accepteerCookies();
296
- if (file) await this.page.context().storageState({ path: file });
342
+ await this.accepteerCookies();
343
+ });
344
+ if (file) await _playwright_test.test.step("Save session state", async () => {
345
+ await this.page.context().storageState({ path: file });
346
+ });
297
347
  }
298
348
  };
299
349
  //#endregion
@@ -384,25 +434,33 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
384
434
  */
385
435
  async loginWithADAccountAndCreateSession(account, targetUrl, fileName) {
386
436
  const adLoginPage = new ADLoginPage(this.page);
387
- await this.page.goto(targetUrl);
388
- await adLoginPage.gebruikersnaamInput.waitFor();
389
- await adLoginPage.gebruikersnaamInput.fill(account.username);
390
- await adLoginPage.volgendeInput.click();
391
- await this.page.getByText("Uw wachtwoord gebruiken").click();
392
- await adLoginPage.wachtwoordInput.fill(account.password);
393
- await adLoginPage.aanmeldenInput.click();
394
- await this.page.waitForTimeout(1e3);
395
- try {
396
- if (await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible()) await this.tryAgainUntilSuccesful();
397
- } catch (_error) {}
398
- await adLoginPage.kanAuthAppNietGebruikenLink.click();
399
- await adLoginPage.gebruikVerificatieCode.click();
400
- const token = await totp_generator.TOTP.generate(`${process.env.AD_SECRET}`);
401
- await adLoginPage.codeInput.fill(token.otp);
402
- await adLoginPage.verifierenInput.click();
403
- await adLoginPage.page.waitForTimeout(5e3);
404
- adLoginPage.page.on("domcontentloaded", () => {});
405
- await adLoginPage.page.context().storageState({ path: fileName });
437
+ await _playwright_test.test.step("Fill AD username and submit", async () => {
438
+ await this.page.goto(targetUrl);
439
+ await adLoginPage.gebruikersnaamInput.waitFor();
440
+ await adLoginPage.gebruikersnaamInput.fill(account.username);
441
+ await adLoginPage.volgendeInput.click();
442
+ await this.page.getByText("Uw wachtwoord gebruiken").click();
443
+ });
444
+ await _playwright_test.test.step("Fill AD password and submit", async () => {
445
+ await maskedFill(adLoginPage.wachtwoordInput, account.password, "wachtwoord");
446
+ await adLoginPage.aanmeldenInput.click();
447
+ await this.page.waitForTimeout(1e3);
448
+ try {
449
+ if (await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible()) await this.tryAgainUntilSuccesful();
450
+ } catch (_error) {}
451
+ });
452
+ await _playwright_test.test.step("Complete MFA via TOTP", async () => {
453
+ await adLoginPage.kanAuthAppNietGebruikenLink.click();
454
+ await adLoginPage.gebruikVerificatieCode.click();
455
+ const token = await totp_generator.TOTP.generate(`${process.env.AD_SECRET}`);
456
+ await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
457
+ await adLoginPage.verifierenInput.click();
458
+ await adLoginPage.page.waitForTimeout(5e3);
459
+ adLoginPage.page.on("domcontentloaded", () => {});
460
+ });
461
+ await _playwright_test.test.step("Save session state", async () => {
462
+ await adLoginPage.page.context().storageState({ path: fileName });
463
+ });
406
464
  }
407
465
  async tryAgainUntilSuccesful() {
408
466
  let maxNumberOfTries = 6;
@@ -705,3 +763,4 @@ exports.createSessionHandler = createSessionHandler;
705
763
  exports.getApiTokenFromSession = getApiTokenFromSession;
706
764
  exports.getLoginHandler = getLoginHandler;
707
765
  exports.getSessionHandler = getSessionHandler;
766
+ exports.maskedFill = maskedFill;
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BasePage, LocalLoginPage, SessionManager, Url, getUrl, isRunningOnLocalhost, urls } from "nl-portal-playwright-libraries";
2
+ import { expect, test } from "@playwright/test";
2
3
  import * as process$2 from "node:process";
3
4
  import process$1 from "node:process";
4
- import { expect } from "@playwright/test";
5
5
  import { TOTP } from "totp-generator";
6
6
  import * as path from "node:path";
7
7
  //#region src/auth/loginhandlers/localhostLoginHandler.ts
@@ -78,6 +78,30 @@ var LoginOverzichtPage = class extends BasePage {
78
78
  }
79
79
  };
80
80
  //#endregion
81
+ //#region src/auth/utils/maskedFill.ts
82
+ function isEnvValue(value) {
83
+ return value !== "" && Object.values(process.env).includes(value);
84
+ }
85
+ async function maskedFill(locator, value, propertyName, forceMask = false) {
86
+ const shouldMask = forceMask || isEnvValue(value);
87
+ const displayValue = shouldMask ? "[MASKED VALUE]" : value;
88
+ await test.step(`Fill "${propertyName}" with value: "${displayValue}"`, async () => {
89
+ if (!shouldMask) {
90
+ await locator.fill(value);
91
+ return;
92
+ }
93
+ await locator.focus();
94
+ await locator.evaluate((el, val) => {
95
+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
96
+ el.value = val;
97
+ el.dispatchEvent(new Event("input", { bubbles: true }));
98
+ el.dispatchEvent(new Event("change", { bubbles: true }));
99
+ }
100
+ }, value);
101
+ await locator.blur();
102
+ });
103
+ }
104
+ //#endregion
81
105
  //#region src/auth/pages/digidLoginPage.ts
82
106
  var DigidLoginPage = class extends LoginOverzichtPage {
83
107
  constructor(page) {
@@ -88,37 +112,41 @@ var DigidLoginPage = class extends LoginOverzichtPage {
88
112
  * @param fileName path of the storage state file to write the session to
89
113
  */
90
114
  async loginAndCreateNewSession(account, fileName) {
91
- await this.openPage();
92
- await this.handleAnySpecialADLoginScreen();
93
- try {
94
- await this.klikOpDigidLoginOptie();
95
- } catch (_error) {
115
+ await test.step("Login with DigiD and create session", async () => {
96
116
  await this.openPage();
97
117
  await this.handleAnySpecialADLoginScreen();
98
- await this.klikOpDigidLoginOptie();
99
- }
100
- if (!this.page.url().match(/authn/)) {
101
- await this.loginWithDigid(account);
102
- await this.accepteerCookies();
103
- }
104
- await this.page.context().storageState({ path: fileName });
118
+ try {
119
+ await this.klikOpDigidLoginOptie();
120
+ } catch (_error) {
121
+ await this.openPage();
122
+ await this.handleAnySpecialADLoginScreen();
123
+ await this.klikOpDigidLoginOptie();
124
+ }
125
+ if (!this.page.url().match(/authn/)) {
126
+ await this.loginWithDigid(account);
127
+ await this.accepteerCookies();
128
+ }
129
+ await this.page.context().storageState({ path: fileName });
130
+ });
105
131
  }
106
132
  /**
107
133
  * @param account login details, supplied by the consumer of this library
108
134
  * @param fileName path of the storage state file to write the session to
109
135
  */
110
136
  async loginAndCreateNewGemachtigdeSession(account, fileName) {
111
- await this.openPage();
112
- await this.handleAnySpecialADLoginScreen();
113
- try {
114
- await this.klikOpDigidMachtigenLoginOptie();
115
- } catch (_error) {
137
+ await test.step("Login with DigiD as gemachtigde and create session", async () => {
116
138
  await this.openPage();
117
- await this.klikOpDigidMachtigenLoginOptie();
118
- }
119
- await this.loginWithDigid(account, true);
120
- await this.accepteerCookies();
121
- await this.page.context().storageState({ path: fileName });
139
+ await this.handleAnySpecialADLoginScreen();
140
+ try {
141
+ await this.klikOpDigidMachtigenLoginOptie();
142
+ } catch (_error) {
143
+ await this.openPage();
144
+ await this.klikOpDigidMachtigenLoginOptie();
145
+ }
146
+ await this.loginWithDigid(account, true);
147
+ await this.accepteerCookies();
148
+ await this.page.context().storageState({ path: fileName });
149
+ });
122
150
  }
123
151
  /**
124
152
  * Indien er al een AD sessie is maar voor de verkeerde omgeving
@@ -135,22 +163,26 @@ var DigidLoginPage = class extends LoginOverzichtPage {
135
163
  * @param gemachtigde whether to log in as an authorized representative (machtiging) instead of a regular user
136
164
  */
137
165
  async loginWithDigid(account, gemachtigde) {
138
- await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
139
- await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
140
- await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
141
- await this.page.getByLabel("Wachtwoord", { exact: true }).fill(account.password);
142
- const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
143
- await this.page.getByRole("button", { name: "Inloggen" }).click();
144
- if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
145
- return await responsePromise;
166
+ return await test.step("Fill DigiD credentials and submit", async () => {
167
+ await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
168
+ await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
169
+ await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
170
+ await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "wachtwoord");
171
+ const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
172
+ await this.page.getByRole("button", { name: "Inloggen" }).click();
173
+ if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
174
+ return await responsePromise;
175
+ });
146
176
  }
147
177
  async loginAlsDigidGemachtigde() {
148
- const gemachtigde = {
149
- username: `${process$1.env.DIGID_GEMACHTIGDE_USER}`,
150
- password: `${process$1.env.DIGID_GEMACHTIGDE_PASSWORD}`
151
- };
152
- await this.klikOpDigidMachtigenLoginOptie();
153
- await this.loginWithDigid(gemachtigde, true);
178
+ await test.step("Login as DigiD gemachtigde", async () => {
179
+ const gemachtigde = {
180
+ username: `${process$1.env.DIGID_GEMACHTIGDE_USER}`,
181
+ password: `${process$1.env.DIGID_GEMACHTIGDE_PASSWORD}`
182
+ };
183
+ await this.klikOpDigidMachtigenLoginOptie();
184
+ await this.loginWithDigid(gemachtigde, true);
185
+ });
154
186
  }
155
187
  };
156
188
  //#endregion
@@ -193,83 +225,101 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
193
225
  * @param account login details, supplied by the consumer of this library
194
226
  */
195
227
  async probeerInTeLoggenMetEHerkenning(account) {
196
- await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
197
- await this.page.locator("#remember").click();
198
- await this.buttonConfirmIdentityProviderSelection.click();
199
- await this.textfieldUsername.fill(account.username);
200
- await this.verderKnop.click();
201
- await this.textfieldPassword.fill(account.password);
202
- await this.inloggenKnop.click();
228
+ await test.step("Fill eHerkenning credentials and submit", async () => {
229
+ await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
230
+ await this.page.locator("#remember").click();
231
+ await this.buttonConfirmIdentityProviderSelection.click();
232
+ await this.textfieldUsername.fill(account.username);
233
+ await this.verderKnop.click();
234
+ await maskedFill(this.textfieldPassword, account.password, "wachtwoord");
235
+ await this.inloggenKnop.click();
236
+ });
203
237
  }
204
238
  /**
205
239
  * @param fileName path of the storage state file to write the session to
206
240
  * @param account login details, supplied by the consumer of this library
207
241
  */
208
242
  async loginWithEHerkenningAndCreateSession(fileName, account) {
209
- await this.openPage();
210
- try {
211
- await this.klikOpEHerkenningLoginOptie();
212
- } catch (_error) {
243
+ await test.step("Login with eHerkenning and create session", async () => {
213
244
  await this.openPage();
214
- await this.klikOpEHerkenningLoginOptie();
215
- }
216
- await this.loginWithEHerkenning(account);
217
- await this.page.context().storageState({ path: fileName });
245
+ try {
246
+ await this.klikOpEHerkenningLoginOptie();
247
+ } catch (_error) {
248
+ await this.openPage();
249
+ await this.klikOpEHerkenningLoginOptie();
250
+ }
251
+ await this.loginWithEHerkenning(account);
252
+ await this.page.context().storageState({ path: fileName });
253
+ });
218
254
  }
219
255
  /**
220
256
  * @param account login details, supplied by the consumer of this library
221
257
  */
222
258
  async loginWithEHerkenning(account) {
223
259
  await this.probeerInTeLoggenMetEHerkenning(account);
224
- await this.page.waitForTimeout(2e3);
225
- if (await this.verderKnop.isVisible()) await this.verderKnop.click();
226
- await this.accepteerCookies();
260
+ await test.step("Confirm eHerkenning login and accept cookies", async () => {
261
+ await this.page.waitForTimeout(2e3);
262
+ if (await this.verderKnop.isVisible()) await this.verderKnop.click();
263
+ await this.accepteerCookies();
264
+ });
227
265
  }
228
266
  /**
229
267
  * @param fileName path of the storage state file to write the session to
230
268
  * @param account login details, supplied by the consumer of this library
231
269
  */
232
270
  async loginWithEHerkenningVestigingAndCreateSession(fileName, account) {
233
- await this.openPage();
234
- try {
235
- await this.klikOpEHerkenningLoginOptie();
236
- } catch (_error) {
271
+ await test.step("Login with eHerkenning vestiging and create session", async () => {
237
272
  await this.openPage();
238
- await this.klikOpEHerkenningLoginOptie();
239
- }
240
- await this.loginWithEHerkenningVestiging(account);
241
- await this.page.context().storageState({ path: fileName });
273
+ try {
274
+ await this.klikOpEHerkenningLoginOptie();
275
+ } catch (_error) {
276
+ await this.openPage();
277
+ await this.klikOpEHerkenningLoginOptie();
278
+ }
279
+ await this.loginWithEHerkenningVestiging(account);
280
+ await this.page.context().storageState({ path: fileName });
281
+ });
242
282
  }
243
283
  /**
244
284
  * @param account login details, supplied by the consumer of this library
245
285
  */
246
286
  async loginWithEHerkenningVestiging(account) {
247
287
  await this.probeerInTeLoggenMetEHerkenning(account);
248
- await this.page.waitForTimeout(2e3);
249
- if (await this.verderKnop.isVisible()) await this.verderKnop.click();
250
- await this.accepteerCookies();
288
+ await test.step("Confirm eHerkenning vestiging login and accept cookies", async () => {
289
+ await this.page.waitForTimeout(2e3);
290
+ if (await this.verderKnop.isVisible()) await this.verderKnop.click();
291
+ await this.accepteerCookies();
292
+ });
251
293
  }
252
294
  /**
253
295
  * @param gemachtigde login details of the authorized representative (bewindvoerder), supplied by the consumer of this library
254
296
  * @param file optional path of the storage state file to write the session to
255
297
  */
256
298
  async loginAlsProfessioneelBewindvoerder(gemachtigde, file) {
257
- await this.openPage();
258
- await this.klikOpProfessioneelBewindvoerderLoginOptie();
259
- try {
260
- await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
261
- } catch (_error) {
299
+ await test.step("Open bewindvoerder login option", async () => {
262
300
  await this.openPage();
263
- await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
264
- }
265
- if (gemachtigde.bsn != null) {
301
+ await this.klikOpProfessioneelBewindvoerderLoginOptie();
302
+ });
303
+ await test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
304
+ try {
305
+ await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
306
+ } catch (_error) {
307
+ await this.openPage();
308
+ await this.probeerInTeLoggenMetEHerkenning(gemachtigde);
309
+ }
310
+ });
311
+ await test.step("Search for client by BSN and accept cookies", async () => {
312
+ if (gemachtigde.bsn != null) {
313
+ await this.verderLink.click();
314
+ await maskedFill(this.inputBsn, gemachtigde.bsn, "bsn");
315
+ }
316
+ await this.buttonZoek.click();
266
317
  await this.verderLink.click();
267
- await this.inputBsn.fill(gemachtigde.bsn);
268
- }
269
- await this.buttonZoek.click();
270
- await this.verderLink.click();
271
- await this.accepteerCookies();
272
- if (file) await this.page.context().storageState({ path: file });
318
+ await this.accepteerCookies();
319
+ });
320
+ if (file) await test.step("Save session state", async () => {
321
+ await this.page.context().storageState({ path: file });
322
+ });
273
323
  }
274
324
  };
275
325
  //#endregion
@@ -360,25 +410,33 @@ var ADLoginPage = class ADLoginPage extends BasePage {
360
410
  */
361
411
  async loginWithADAccountAndCreateSession(account, targetUrl, fileName) {
362
412
  const adLoginPage = new ADLoginPage(this.page);
363
- await this.page.goto(targetUrl);
364
- await adLoginPage.gebruikersnaamInput.waitFor();
365
- await adLoginPage.gebruikersnaamInput.fill(account.username);
366
- await adLoginPage.volgendeInput.click();
367
- await this.page.getByText("Uw wachtwoord gebruiken").click();
368
- await adLoginPage.wachtwoordInput.fill(account.password);
369
- await adLoginPage.aanmeldenInput.click();
370
- await this.page.waitForTimeout(1e3);
371
- try {
372
- if (await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible()) await this.tryAgainUntilSuccesful();
373
- } catch (_error) {}
374
- await adLoginPage.kanAuthAppNietGebruikenLink.click();
375
- await adLoginPage.gebruikVerificatieCode.click();
376
- const token = await TOTP.generate(`${process.env.AD_SECRET}`);
377
- await adLoginPage.codeInput.fill(token.otp);
378
- await adLoginPage.verifierenInput.click();
379
- await adLoginPage.page.waitForTimeout(5e3);
380
- adLoginPage.page.on("domcontentloaded", () => {});
381
- await adLoginPage.page.context().storageState({ path: fileName });
413
+ await test.step("Fill AD username and submit", async () => {
414
+ await this.page.goto(targetUrl);
415
+ await adLoginPage.gebruikersnaamInput.waitFor();
416
+ await adLoginPage.gebruikersnaamInput.fill(account.username);
417
+ await adLoginPage.volgendeInput.click();
418
+ await this.page.getByText("Uw wachtwoord gebruiken").click();
419
+ });
420
+ await test.step("Fill AD password and submit", async () => {
421
+ await maskedFill(adLoginPage.wachtwoordInput, account.password, "wachtwoord");
422
+ await adLoginPage.aanmeldenInput.click();
423
+ await this.page.waitForTimeout(1e3);
424
+ try {
425
+ if (await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible()) await this.tryAgainUntilSuccesful();
426
+ } catch (_error) {}
427
+ });
428
+ await test.step("Complete MFA via TOTP", async () => {
429
+ await adLoginPage.kanAuthAppNietGebruikenLink.click();
430
+ await adLoginPage.gebruikVerificatieCode.click();
431
+ const token = await TOTP.generate(`${process.env.AD_SECRET}`);
432
+ await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
433
+ await adLoginPage.verifierenInput.click();
434
+ await adLoginPage.page.waitForTimeout(5e3);
435
+ adLoginPage.page.on("domcontentloaded", () => {});
436
+ });
437
+ await test.step("Save session state", async () => {
438
+ await adLoginPage.page.context().storageState({ path: fileName });
439
+ });
382
440
  }
383
441
  async tryAgainUntilSuccesful() {
384
442
  let maxNumberOfTries = 6;
@@ -665,4 +723,4 @@ function getSessionHandler(testProfile, adTargetUrl) {
665
723
  return createSessionHandler(testProfile.authType, testProfile.account, getLoginHandler(testProfile.authType, adTargetUrl));
666
724
  }
667
725
  //#endregion
668
- export { ADLoginHandler, ADLoginPage, DigidGemachtigdeLoginHandler, DigidLoginHandler, DigidLoginPage, EHerkenningBewindvoerderLoginHandler, EHerkenningLoginHandler, EHerkenningLoginPage, LocalhostLoginHandler, LoginOverzichtPage, MAX_SESSION_TIME_IN_MINUTES, SessionFileHelper, createSessionHandler, getApiTokenFromSession, getLoginHandler, getSessionHandler };
726
+ export { ADLoginHandler, ADLoginPage, DigidGemachtigdeLoginHandler, DigidLoginHandler, DigidLoginPage, EHerkenningBewindvoerderLoginHandler, EHerkenningLoginHandler, EHerkenningLoginPage, LocalhostLoginHandler, LoginOverzichtPage, MAX_SESSION_TIME_IN_MINUTES, SessionFileHelper, createSessionHandler, getApiTokenFromSession, getLoginHandler, getSessionHandler, maskedFill };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dh-auth-library",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Gemeente-DenHaag/dh-auth-library.git"