dh-auth-library 1.6.1 → 2.0.1
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 +201 -31
- package/dist/auth/getLoginHandler.d.ts +21 -4
- package/dist/auth/getSessionHandler.d.ts +17 -5
- package/dist/auth/loginhandlers/digidGemachtigdeLoginHandler.d.ts +9 -0
- package/dist/auth/loginhandlers/digidLoginHandler.d.ts +9 -0
- package/dist/auth/pages/adLoginPage.d.ts +7 -7
- package/dist/auth/pages/digidLoginPage.d.ts +18 -7
- package/dist/auth/pages/eHerkenningLoginPage.d.ts +6 -6
- package/dist/auth/pages/index.d.ts +1 -1
- package/dist/auth/pages/loginOverzichtPage.d.ts +65 -10
- package/dist/index.cjs.js +223 -115
- package/dist/index.es.js +223 -115
- package/package.json +58 -57
package/dist/index.cjs.js
CHANGED
|
@@ -42,59 +42,96 @@ var LocalhostLoginHandler = class {
|
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/auth/pages/loginOverzichtPage.ts
|
|
44
44
|
var LoginOverzichtPage = class extends nl_portal_playwright_libraries.BasePage {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
digidLoginButton;
|
|
46
|
+
digidMachtigenLoginButton;
|
|
47
|
+
eHerkenningLoginButton;
|
|
48
|
+
eHerkenningMachtigingLoginButton;
|
|
49
|
+
klantportaalCookieButton;
|
|
49
50
|
constructor(page) {
|
|
50
51
|
super(page);
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
52
|
+
this.digidLoginButton = page.locator("#oidc-digid");
|
|
53
|
+
this.digidMachtigenLoginButton = page.locator("#digid-machtigen");
|
|
54
|
+
this.eHerkenningLoginButton = page.locator("#oidc-eHerkenning");
|
|
55
|
+
this.eHerkenningMachtigingLoginButton = page.locator("#eherkenning-bewindvoering");
|
|
56
|
+
this.klantportaalCookieButton = page.locator("#ppms_cm_agree-to-all");
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Clicks the button that starts the login flow. Not every consumer has the login overzicht
|
|
60
|
+
* page (e.g. Open Forms), so the button to click can be supplied by the consumer.
|
|
61
|
+
*
|
|
62
|
+
* @param loginButton the button that starts the login flow
|
|
63
|
+
*/
|
|
64
|
+
async clickLoginButton(loginButton) {
|
|
65
|
+
await loginButton.waitFor();
|
|
58
66
|
await this.page.waitForTimeout(2e3);
|
|
59
|
-
await
|
|
67
|
+
await loginButton.click();
|
|
60
68
|
}
|
|
61
|
-
async
|
|
62
|
-
await this.
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
async clickDigidLoginOption() {
|
|
70
|
+
await this.clickLoginButton(this.digidLoginButton);
|
|
71
|
+
}
|
|
72
|
+
async clickDigidMachtigenLoginOption() {
|
|
73
|
+
await this.clickLoginButton(this.digidMachtigenLoginButton);
|
|
65
74
|
}
|
|
66
|
-
async
|
|
67
|
-
await this.
|
|
75
|
+
async clickEHerkenningLoginOption() {
|
|
76
|
+
await this.eHerkenningLoginButton.waitFor();
|
|
68
77
|
await this.page.waitForTimeout(2e3);
|
|
69
78
|
try {
|
|
70
|
-
await this.
|
|
79
|
+
await this.eHerkenningLoginButton.click();
|
|
71
80
|
} catch (_error) {
|
|
72
81
|
await this.reloadPage();
|
|
73
|
-
await this.
|
|
82
|
+
await this.eHerkenningLoginButton.waitFor();
|
|
74
83
|
await this.page.waitForTimeout(2e3);
|
|
75
|
-
await this.
|
|
84
|
+
await this.eHerkenningLoginButton.click();
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
|
-
async
|
|
79
|
-
await this.
|
|
87
|
+
async clickProfessionalBewindvoerderLoginOption() {
|
|
88
|
+
await this.eHerkenningMachtigingLoginButton.waitFor();
|
|
80
89
|
await this.page.waitForTimeout(2e3);
|
|
81
90
|
try {
|
|
82
|
-
await this.
|
|
91
|
+
await this.eHerkenningMachtigingLoginButton.click();
|
|
83
92
|
} catch (_error) {
|
|
84
93
|
await this.reloadPage();
|
|
85
|
-
await this.
|
|
94
|
+
await this.eHerkenningMachtigingLoginButton.waitFor();
|
|
86
95
|
await this.page.waitForTimeout(2e3);
|
|
87
|
-
await this.
|
|
96
|
+
await this.eHerkenningMachtigingLoginButton.click();
|
|
88
97
|
}
|
|
89
98
|
}
|
|
90
|
-
async
|
|
99
|
+
async verifyLoginOverviewIsVisible() {
|
|
91
100
|
await (0, _playwright_test.expect)(this.page.getByRole("heading", { name: "Inloggen voor mijzelf" })).toBeVisible();
|
|
92
101
|
}
|
|
93
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Accepts the cookie banner and waits until the consent is stored in a cookie; skipped when the
|
|
104
|
+
* banner doesn't show within 10 seconds.
|
|
105
|
+
*
|
|
106
|
+
* @param cookieButton the button that accepts the cookie banner, defaults to the klantportaal banner
|
|
107
|
+
*/
|
|
108
|
+
async acceptCookies(cookieButton = this.klantportaalCookieButton) {
|
|
94
109
|
try {
|
|
95
|
-
await this.
|
|
110
|
+
const cookiesBeforeAccepting = await this.cookiesAsText();
|
|
111
|
+
await cookieButton.click({ timeout: 1e4 });
|
|
112
|
+
await this.waitForCookiesToSettle(cookiesBeforeAccepting);
|
|
96
113
|
} catch (_ignore) {}
|
|
97
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Waits until the cookies differ from `cookiesBefore` and have not changed for a second, at most 10 seconds.
|
|
117
|
+
*/
|
|
118
|
+
async waitForCookiesToSettle(cookiesBefore) {
|
|
119
|
+
const settledAfterMs = 1e3;
|
|
120
|
+
const deadline = Date.now() + 1e4;
|
|
121
|
+
let current = cookiesBefore;
|
|
122
|
+
let changedAt = Date.now();
|
|
123
|
+
while (Date.now() < deadline) {
|
|
124
|
+
await this.page.waitForTimeout(250);
|
|
125
|
+
const cookies = await this.cookiesAsText();
|
|
126
|
+
if (cookies !== current) {
|
|
127
|
+
current = cookies;
|
|
128
|
+
changedAt = Date.now();
|
|
129
|
+
} else if (current !== cookiesBefore && Date.now() - changedAt >= settledAfterMs) return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async cookiesAsText() {
|
|
133
|
+
return (await this.page.context().cookies()).map((c) => `${c.domain}|${c.name}=${c.value}`).sort().join(";");
|
|
134
|
+
}
|
|
98
135
|
async reloadPage() {
|
|
99
136
|
try {
|
|
100
137
|
await this.page.reload();
|
|
@@ -134,21 +171,25 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
134
171
|
/**
|
|
135
172
|
* @param account login details, supplied by the consumer of this library
|
|
136
173
|
* @param fileName path of the storage state file to write the session to
|
|
174
|
+
* @param options the app's DigiD login button, and optionally where to start and its cookie
|
|
175
|
+
* banner, supplied by the consumer of this library
|
|
137
176
|
*/
|
|
138
|
-
async loginAndCreateNewSession(account, fileName) {
|
|
177
|
+
async loginAndCreateNewSession(account, fileName, options) {
|
|
178
|
+
const loginButton = options.loginButton(this.page);
|
|
179
|
+
const { startUrl } = options;
|
|
139
180
|
await _playwright_test.test.step("Login with DigiD and create session", async () => {
|
|
140
|
-
await this.openPage();
|
|
181
|
+
await this.openPage(startUrl);
|
|
141
182
|
await this.handleAnySpecialADLoginScreen();
|
|
142
183
|
try {
|
|
143
|
-
await this.
|
|
184
|
+
await this.clickLoginButton(loginButton);
|
|
144
185
|
} catch (_error) {
|
|
145
|
-
await this.openPage();
|
|
186
|
+
await this.openPage(startUrl);
|
|
146
187
|
await this.handleAnySpecialADLoginScreen();
|
|
147
|
-
await this.
|
|
188
|
+
await this.clickLoginButton(loginButton);
|
|
148
189
|
}
|
|
149
190
|
if (!this.page.url().match(/authn/)) {
|
|
150
191
|
await this.loginWithDigid(account);
|
|
151
|
-
await this.
|
|
192
|
+
await this.acceptCookiesForApp(options);
|
|
152
193
|
}
|
|
153
194
|
await this.page.context().storageState({ path: fileName });
|
|
154
195
|
});
|
|
@@ -156,25 +197,35 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
156
197
|
/**
|
|
157
198
|
* @param account login details, supplied by the consumer of this library
|
|
158
199
|
* @param fileName path of the storage state file to write the session to
|
|
200
|
+
* @param options the app's DigiD machtigen login button, and optionally where to start and its cookie
|
|
201
|
+
* banner, supplied by the consumer of this library
|
|
159
202
|
*/
|
|
160
|
-
async loginAndCreateNewGemachtigdeSession(account, fileName) {
|
|
203
|
+
async loginAndCreateNewGemachtigdeSession(account, fileName, options) {
|
|
204
|
+
const loginButton = options.loginButton(this.page);
|
|
205
|
+
const { startUrl } = options;
|
|
161
206
|
await _playwright_test.test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
162
|
-
await this.openPage();
|
|
207
|
+
await this.openPage(startUrl);
|
|
163
208
|
await this.handleAnySpecialADLoginScreen();
|
|
164
209
|
try {
|
|
165
|
-
await this.
|
|
210
|
+
await this.clickLoginButton(loginButton);
|
|
166
211
|
} catch (_error) {
|
|
167
|
-
await this.openPage();
|
|
168
|
-
await this.
|
|
212
|
+
await this.openPage(startUrl);
|
|
213
|
+
await this.clickLoginButton(loginButton);
|
|
169
214
|
}
|
|
170
215
|
await this.loginWithDigid(account, true);
|
|
171
|
-
await this.
|
|
216
|
+
await this.acceptCookiesForApp(options);
|
|
172
217
|
await this.page.context().storageState({ path: fileName });
|
|
173
218
|
});
|
|
174
219
|
}
|
|
175
220
|
/**
|
|
176
|
-
*
|
|
177
|
-
|
|
221
|
+
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
222
|
+
*/
|
|
223
|
+
async acceptCookiesForApp(options) {
|
|
224
|
+
if (options.cookieButton) await this.acceptCookies(options.cookieButton(this.page));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* When there is already an AD session, but for another environment, a special screen asks to
|
|
228
|
+
* confirm the account before you can continue.
|
|
178
229
|
*/
|
|
179
230
|
async handleAnySpecialADLoginScreen() {
|
|
180
231
|
try {
|
|
@@ -191,20 +242,23 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
191
242
|
await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
|
|
192
243
|
await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
|
|
193
244
|
await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
|
|
194
|
-
await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "
|
|
245
|
+
await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "password");
|
|
195
246
|
const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
|
|
196
247
|
await this.page.getByRole("button", { name: "Inloggen" }).click();
|
|
197
248
|
if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
|
|
198
249
|
return await responsePromise;
|
|
199
250
|
});
|
|
200
251
|
}
|
|
201
|
-
|
|
252
|
+
/**
|
|
253
|
+
* @param loginButton button that starts the DigiD machtigen login, supplied by the consumer of this library
|
|
254
|
+
*/
|
|
255
|
+
async loginAsDigidGemachtigde(loginButton) {
|
|
202
256
|
await _playwright_test.test.step("Login as DigiD gemachtigde", async () => {
|
|
203
257
|
const gemachtigde = {
|
|
204
258
|
username: `${node_process.default.env.DIGID_GEMACHTIGDE_USER}`,
|
|
205
259
|
password: `${node_process.default.env.DIGID_GEMACHTIGDE_PASSWORD}`
|
|
206
260
|
};
|
|
207
|
-
await this.
|
|
261
|
+
await this.clickLoginButton(loginButton);
|
|
208
262
|
await this.loginWithDigid(gemachtigde, true);
|
|
209
263
|
});
|
|
210
264
|
}
|
|
@@ -212,13 +266,23 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
212
266
|
//#endregion
|
|
213
267
|
//#region src/auth/loginhandlers/digidLoginHandler.ts
|
|
214
268
|
var DigidLoginHandler = class {
|
|
269
|
+
options;
|
|
270
|
+
/**
|
|
271
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
272
|
+
*
|
|
273
|
+
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
274
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
275
|
+
*/
|
|
276
|
+
constructor(options) {
|
|
277
|
+
this.options = options;
|
|
278
|
+
}
|
|
215
279
|
/**
|
|
216
280
|
* @param page the Playwright page to perform the login on
|
|
217
281
|
* @param account login details, supplied by the consumer of this library
|
|
218
282
|
* @param file path of the storage state file to write the session to
|
|
219
283
|
*/
|
|
220
284
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
221
|
-
await new DigidLoginPage(page).loginAndCreateNewSession(account, file);
|
|
285
|
+
await new DigidLoginPage(page).loginAndCreateNewSession(account, file, this.options);
|
|
222
286
|
}
|
|
223
287
|
};
|
|
224
288
|
//#endregion
|
|
@@ -228,35 +292,35 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
228
292
|
buttonConfirmIdentityProviderSelection;
|
|
229
293
|
textfieldUsername;
|
|
230
294
|
textfieldPassword;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
295
|
+
loginButton;
|
|
296
|
+
continueButton;
|
|
297
|
+
continueLink;
|
|
234
298
|
inputBsn;
|
|
235
|
-
|
|
299
|
+
searchButton;
|
|
236
300
|
constructor(page) {
|
|
237
301
|
super(page);
|
|
238
302
|
this.dropdownSelectIdentityProvider = page.locator("#identity_provider");
|
|
239
303
|
this.buttonConfirmIdentityProviderSelection = page.locator("//*[@name='commit']");
|
|
240
304
|
this.textfieldUsername = page.locator("#account_username");
|
|
241
305
|
this.textfieldPassword = page.locator("#account_password");
|
|
242
|
-
this.
|
|
243
|
-
this.
|
|
306
|
+
this.loginButton = page.getByRole("button", { name: /Inloggen|Log in/ });
|
|
307
|
+
this.continueButton = page.getByRole("button", { name: /Verder|Continue|Ga verder/ });
|
|
244
308
|
this.inputBsn = page.locator("#bsn-input");
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
309
|
+
this.searchButton = page.locator("#search-submit");
|
|
310
|
+
this.continueLink = page.getByRole("link", { name: /Verder|Continue|Ga verder/ });
|
|
247
311
|
}
|
|
248
312
|
/**
|
|
249
313
|
* @param account login details, supplied by the consumer of this library
|
|
250
314
|
*/
|
|
251
|
-
async
|
|
315
|
+
async tryLoginWithEHerkenning(account) {
|
|
252
316
|
await _playwright_test.test.step("Fill eHerkenning credentials and submit", async () => {
|
|
253
317
|
await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
|
|
254
318
|
await this.page.locator("#remember").click();
|
|
255
319
|
await this.buttonConfirmIdentityProviderSelection.click();
|
|
256
320
|
await this.textfieldUsername.fill(account.username);
|
|
257
|
-
await this.
|
|
258
|
-
await maskedFill(this.textfieldPassword, account.password, "
|
|
259
|
-
await this.
|
|
321
|
+
await this.continueButton.click();
|
|
322
|
+
await maskedFill(this.textfieldPassword, account.password, "password");
|
|
323
|
+
await this.loginButton.click();
|
|
260
324
|
});
|
|
261
325
|
}
|
|
262
326
|
/**
|
|
@@ -267,10 +331,10 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
267
331
|
await _playwright_test.test.step("Login with eHerkenning and create session", async () => {
|
|
268
332
|
await this.openPage();
|
|
269
333
|
try {
|
|
270
|
-
await this.
|
|
334
|
+
await this.clickEHerkenningLoginOption();
|
|
271
335
|
} catch (_error) {
|
|
272
336
|
await this.openPage();
|
|
273
|
-
await this.
|
|
337
|
+
await this.clickEHerkenningLoginOption();
|
|
274
338
|
}
|
|
275
339
|
await this.loginWithEHerkenning(account);
|
|
276
340
|
await this.page.context().storageState({ path: fileName });
|
|
@@ -280,11 +344,11 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
280
344
|
* @param account login details, supplied by the consumer of this library
|
|
281
345
|
*/
|
|
282
346
|
async loginWithEHerkenning(account) {
|
|
283
|
-
await this.
|
|
347
|
+
await this.tryLoginWithEHerkenning(account);
|
|
284
348
|
await _playwright_test.test.step("Confirm eHerkenning login and accept cookies", async () => {
|
|
285
349
|
await this.page.waitForTimeout(2e3);
|
|
286
|
-
if (await this.
|
|
287
|
-
await this.
|
|
350
|
+
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
351
|
+
await this.acceptCookies();
|
|
288
352
|
});
|
|
289
353
|
}
|
|
290
354
|
/**
|
|
@@ -295,10 +359,10 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
295
359
|
await _playwright_test.test.step("Login with eHerkenning vestiging and create session", async () => {
|
|
296
360
|
await this.openPage();
|
|
297
361
|
try {
|
|
298
|
-
await this.
|
|
362
|
+
await this.clickEHerkenningLoginOption();
|
|
299
363
|
} catch (_error) {
|
|
300
364
|
await this.openPage();
|
|
301
|
-
await this.
|
|
365
|
+
await this.clickEHerkenningLoginOption();
|
|
302
366
|
}
|
|
303
367
|
await this.loginWithEHerkenningVestiging(account);
|
|
304
368
|
await this.page.context().storageState({ path: fileName });
|
|
@@ -308,38 +372,38 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
308
372
|
* @param account login details, supplied by the consumer of this library
|
|
309
373
|
*/
|
|
310
374
|
async loginWithEHerkenningVestiging(account) {
|
|
311
|
-
await this.
|
|
375
|
+
await this.tryLoginWithEHerkenning(account);
|
|
312
376
|
await _playwright_test.test.step("Confirm eHerkenning vestiging login and accept cookies", async () => {
|
|
313
377
|
await this.page.waitForTimeout(2e3);
|
|
314
|
-
if (await this.
|
|
315
|
-
await this.
|
|
378
|
+
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
379
|
+
await this.acceptCookies();
|
|
316
380
|
});
|
|
317
381
|
}
|
|
318
382
|
/**
|
|
319
383
|
* @param gemachtigde login details of the authorized representative (bewindvoerder), supplied by the consumer of this library
|
|
320
384
|
* @param file optional path of the storage state file to write the session to
|
|
321
385
|
*/
|
|
322
|
-
async
|
|
386
|
+
async loginAsProfessionalBewindvoerder(gemachtigde, file) {
|
|
323
387
|
await _playwright_test.test.step("Open bewindvoerder login option", async () => {
|
|
324
388
|
await this.openPage();
|
|
325
|
-
await this.
|
|
389
|
+
await this.clickProfessionalBewindvoerderLoginOption();
|
|
326
390
|
});
|
|
327
391
|
await _playwright_test.test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
328
392
|
try {
|
|
329
|
-
await this.
|
|
393
|
+
await this.tryLoginWithEHerkenning(gemachtigde);
|
|
330
394
|
} catch (_error) {
|
|
331
395
|
await this.openPage();
|
|
332
|
-
await this.
|
|
396
|
+
await this.tryLoginWithEHerkenning(gemachtigde);
|
|
333
397
|
}
|
|
334
398
|
});
|
|
335
399
|
await _playwright_test.test.step("Search for client by BSN and accept cookies", async () => {
|
|
336
400
|
if (gemachtigde.bsn != null) {
|
|
337
|
-
await this.
|
|
401
|
+
await this.continueLink.click();
|
|
338
402
|
await maskedFill(this.inputBsn, gemachtigde.bsn, "bsn");
|
|
339
403
|
}
|
|
340
|
-
await this.
|
|
341
|
-
await this.
|
|
342
|
-
await this.
|
|
404
|
+
await this.searchButton.click();
|
|
405
|
+
await this.continueLink.click();
|
|
406
|
+
await this.acceptCookies();
|
|
343
407
|
});
|
|
344
408
|
if (file) await _playwright_test.test.step("Save session state", async () => {
|
|
345
409
|
await this.page.context().storageState({ path: file });
|
|
@@ -361,13 +425,23 @@ var EHerkenningLoginHandler = class {
|
|
|
361
425
|
//#endregion
|
|
362
426
|
//#region src/auth/loginhandlers/digidGemachtigdeLoginHandler.ts
|
|
363
427
|
var DigidGemachtigdeLoginHandler = class {
|
|
428
|
+
options;
|
|
429
|
+
/**
|
|
430
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
431
|
+
*
|
|
432
|
+
* @param options the app's DigiD machtigen login button (required), and optionally where to start and the
|
|
433
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
434
|
+
*/
|
|
435
|
+
constructor(options) {
|
|
436
|
+
this.options = options;
|
|
437
|
+
}
|
|
364
438
|
/**
|
|
365
439
|
* @param page the Playwright page to perform the login on
|
|
366
440
|
* @param account login details, supplied by the consumer of this library
|
|
367
441
|
* @param file path of the storage state file to write the session to
|
|
368
442
|
*/
|
|
369
443
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
370
|
-
await new DigidLoginPage(page).loginAndCreateNewGemachtigdeSession(account, file);
|
|
444
|
+
await new DigidLoginPage(page).loginAndCreateNewGemachtigdeSession(account, file, this.options);
|
|
371
445
|
}
|
|
372
446
|
};
|
|
373
447
|
//#endregion
|
|
@@ -379,7 +453,7 @@ var EHerkenningBewindvoerderLoginHandler = class {
|
|
|
379
453
|
* @param file path of the storage state file to write the session to
|
|
380
454
|
*/
|
|
381
455
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
382
|
-
await new EHerkenningLoginPage(page).
|
|
456
|
+
await new EHerkenningLoginPage(page).loginAsProfessionalBewindvoerder(account, file);
|
|
383
457
|
}
|
|
384
458
|
};
|
|
385
459
|
//#endregion
|
|
@@ -391,24 +465,24 @@ function escapeRegExp(value) {
|
|
|
391
465
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
392
466
|
}
|
|
393
467
|
var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BasePage {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
468
|
+
usernameInput;
|
|
469
|
+
passwordInput;
|
|
470
|
+
nextInput;
|
|
471
|
+
signInInput;
|
|
472
|
+
cannotUseAuthAppLink;
|
|
473
|
+
useVerificationCode;
|
|
400
474
|
codeInput;
|
|
401
|
-
|
|
475
|
+
verifyInput;
|
|
402
476
|
constructor(page) {
|
|
403
477
|
super(page);
|
|
404
|
-
this.
|
|
405
|
-
this.
|
|
406
|
-
this.
|
|
407
|
-
this.
|
|
408
|
-
this.
|
|
409
|
-
this.
|
|
478
|
+
this.usernameInput = page.locator("//input[@type='email']");
|
|
479
|
+
this.passwordInput = page.locator("//input[@name='passwd']");
|
|
480
|
+
this.nextInput = page.locator("//input[@type='submit']");
|
|
481
|
+
this.signInInput = page.locator("//input[@type='submit']");
|
|
482
|
+
this.cannotUseAuthAppLink = page.locator("//*[@id='signInAnotherWay']");
|
|
483
|
+
this.useVerificationCode = page.getByText(/Gebruik een verificatiecode|Use a verification code/);
|
|
410
484
|
this.codeInput = page.locator("//input[@name='otc']");
|
|
411
|
-
this.
|
|
485
|
+
this.verifyInput = page.locator("//input[@type='submit']");
|
|
412
486
|
}
|
|
413
487
|
async openPage(path) {
|
|
414
488
|
await this.page.goto(path);
|
|
@@ -451,7 +525,7 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
|
|
|
451
525
|
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
452
526
|
if (alreadyFullyAuthenticated) return;
|
|
453
527
|
const cachedAccountTile = this.page.getByRole("button", { name: new RegExp(escapeRegExp(account.username), "i") });
|
|
454
|
-
await cachedAccountTile.or(adLoginPage.
|
|
528
|
+
await cachedAccountTile.or(adLoginPage.usernameInput).waitFor({
|
|
455
529
|
state: "visible",
|
|
456
530
|
timeout: 1e4
|
|
457
531
|
}).catch(() => {});
|
|
@@ -460,9 +534,9 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
|
|
|
460
534
|
await cachedAccountTile.click();
|
|
461
535
|
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
462
536
|
} else {
|
|
463
|
-
await adLoginPage.
|
|
464
|
-
await adLoginPage.
|
|
465
|
-
await adLoginPage.
|
|
537
|
+
await adLoginPage.usernameInput.waitFor();
|
|
538
|
+
await adLoginPage.usernameInput.fill(account.username);
|
|
539
|
+
await adLoginPage.nextInput.click();
|
|
466
540
|
await this.page.getByText("Uw wachtwoord gebruiken").click();
|
|
467
541
|
}
|
|
468
542
|
});
|
|
@@ -470,18 +544,18 @@ var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BaseP
|
|
|
470
544
|
if (!alreadyFullyAuthenticated) {
|
|
471
545
|
await _playwright_test.test.step("Fill AD password and submit", async () => {
|
|
472
546
|
if (!cachedAccountUsed) {
|
|
473
|
-
await maskedFill(adLoginPage.
|
|
474
|
-
await adLoginPage.
|
|
547
|
+
await maskedFill(adLoginPage.passwordInput, account.password, "password");
|
|
548
|
+
await adLoginPage.signInInput.click();
|
|
475
549
|
await this.page.waitForTimeout(1e3);
|
|
476
550
|
}
|
|
477
551
|
sessionWasStale = await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible().catch(() => false);
|
|
478
552
|
});
|
|
479
553
|
await _playwright_test.test.step("Complete MFA via TOTP", async () => {
|
|
480
|
-
if (!sessionWasStale) await adLoginPage.
|
|
481
|
-
await adLoginPage.
|
|
554
|
+
if (!sessionWasStale) await adLoginPage.cannotUseAuthAppLink.click();
|
|
555
|
+
await adLoginPage.useVerificationCode.click();
|
|
482
556
|
const token = await totp_generator.TOTP.generate(`${process.env.AD_SECRET}`);
|
|
483
557
|
await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
|
|
484
|
-
await adLoginPage.
|
|
558
|
+
await adLoginPage.verifyInput.click();
|
|
485
559
|
await adLoginPage.page.waitForTimeout(5e3);
|
|
486
560
|
});
|
|
487
561
|
}
|
|
@@ -531,24 +605,47 @@ var ADLoginHandler = class {
|
|
|
531
605
|
//#endregion
|
|
532
606
|
//#region src/auth/getLoginHandler.ts
|
|
533
607
|
/**
|
|
608
|
+
* Shortcut for creating the login handler for an auth type. Creating the handler directly, e.g.
|
|
609
|
+
* `new DigidLoginHandler(options)`, checks at compile time that the required options are there;
|
|
610
|
+
* this function checks at runtime.
|
|
611
|
+
*
|
|
534
612
|
* @param authType type of login
|
|
535
|
-
* @param
|
|
536
|
-
* app behind the firewall
|
|
537
|
-
* `
|
|
613
|
+
* @param options where to start the login, supplied by the consumer of this library.
|
|
614
|
+
* - `ad-session`: `startUrl` is required - the app behind the firewall to navigate to before logging in.
|
|
615
|
+
* - `digid` / `digid_gemachtigde`: `loginButton` is required - the app's DigiD button. `startUrl` defaults
|
|
616
|
+
* to `PORTAL_BASE_URL`; `cookieButton` is optional.
|
|
617
|
+
* - other auth types: ignored.
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* getLoginHandler('digid', {
|
|
621
|
+
* startUrl: 'https://openformulieren-zgw.acc.denhaag.nl/<form>/startpagina',
|
|
622
|
+
* loginButton: (page) => page.getByRole('link', { name: 'Inloggen met DigiD' }),
|
|
623
|
+
* cookieButton: (page) => page.locator('button[class*="cookie-notice__accept"]'),
|
|
624
|
+
* });
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* getLoginHandler('ad-session', { startUrl: 'https://alg-zgw.test.denhaag.nl/' });
|
|
538
628
|
*/
|
|
539
|
-
function getLoginHandler(authType,
|
|
629
|
+
function getLoginHandler(authType, options = {}) {
|
|
540
630
|
switch (authType) {
|
|
541
|
-
case "digid": return (0, nl_portal_playwright_libraries.isRunningOnLocalhost)() ? new LocalhostLoginHandler() : new DigidLoginHandler();
|
|
542
|
-
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler();
|
|
631
|
+
case "digid": return (0, nl_portal_playwright_libraries.isRunningOnLocalhost)() ? new LocalhostLoginHandler() : new DigidLoginHandler(digidOptions(authType, options));
|
|
632
|
+
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler(digidOptions(authType, options));
|
|
543
633
|
case "eherkenning": return (0, nl_portal_playwright_libraries.isRunningOnLocalhost)() ? new LocalhostLoginHandler() : new EHerkenningLoginHandler();
|
|
544
634
|
case "eherkenning_vestiging": return new EHerkenningLoginHandler();
|
|
545
635
|
case "eherkenning_bewindvoerder": return new EHerkenningBewindvoerderLoginHandler();
|
|
546
636
|
case "ad-session":
|
|
547
|
-
if (!
|
|
548
|
-
return new ADLoginHandler(
|
|
637
|
+
if (!options.startUrl) throw new Error("startUrl is required when authType is 'ad-session'");
|
|
638
|
+
return new ADLoginHandler(options.startUrl);
|
|
549
639
|
default: throw new Error(`Unsupported auth type: ${authType}. If needed please create a new LoginHandler and register it here in getLoginHandler().`);
|
|
550
640
|
}
|
|
551
641
|
}
|
|
642
|
+
function digidOptions(authType, options) {
|
|
643
|
+
if (!options.loginButton) throw new Error(`loginButton is required when authType is '${authType}'`);
|
|
644
|
+
return {
|
|
645
|
+
...options,
|
|
646
|
+
loginButton: options.loginButton
|
|
647
|
+
};
|
|
648
|
+
}
|
|
552
649
|
//#endregion
|
|
553
650
|
//#region src/auth/utils/sessionFileHelper.ts
|
|
554
651
|
var sessionsDir = node_process.env.SESSIONS_DIR ?? node_path.resolve(node_process.cwd(), "sessions");
|
|
@@ -749,13 +846,24 @@ function getApiTokenFromSession(baseTest, handler) {
|
|
|
749
846
|
//#endregion
|
|
750
847
|
//#region src/auth/getSessionHandler.ts
|
|
751
848
|
/**
|
|
752
|
-
* @param testProfile
|
|
753
|
-
* @param
|
|
754
|
-
* `
|
|
755
|
-
*
|
|
849
|
+
* @param testProfile the test user to log in
|
|
850
|
+
* @param loginHandler the login handler for the app the user logs in to, with that app's options, e.g.
|
|
851
|
+
* `new DigidLoginHandler({ loginButton, ... })` or `getLoginHandler(authType, options)`. Required for
|
|
852
|
+
* auth types that need options (`ad-session`, `digid`, `digid_gemachtigde`); left out, the handler
|
|
853
|
+
* for `testProfile.authType` is created without options.
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* // once per app
|
|
857
|
+
* export const openFormsDigid = new DigidLoginHandler({
|
|
858
|
+
* startUrl: 'https://openformulieren-zgw.acc.denhaag.nl/<form>/startpagina',
|
|
859
|
+
* loginButton: (page) => page.getByRole('link', { name: 'Inloggen met DigiD' }),
|
|
860
|
+
* cookieButton: (page) => page.locator('button[class*="cookie-notice__accept"]'),
|
|
861
|
+
* });
|
|
862
|
+
*
|
|
863
|
+
* getSessionHandler(digidUser1, openFormsDigid);
|
|
756
864
|
*/
|
|
757
|
-
function getSessionHandler(testProfile,
|
|
758
|
-
return createSessionHandler(testProfile.authType, testProfile.account, getLoginHandler(testProfile.authType
|
|
865
|
+
function getSessionHandler(testProfile, loginHandler) {
|
|
866
|
+
return createSessionHandler(testProfile.authType, testProfile.account, loginHandler ?? getLoginHandler(testProfile.authType));
|
|
759
867
|
}
|
|
760
868
|
//#endregion
|
|
761
869
|
exports.ADLoginHandler = ADLoginHandler;
|