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.es.js
CHANGED
|
@@ -18,59 +18,96 @@ var LocalhostLoginHandler = class {
|
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/auth/pages/loginOverzichtPage.ts
|
|
20
20
|
var LoginOverzichtPage = class extends BasePage {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
digidLoginButton;
|
|
22
|
+
digidMachtigenLoginButton;
|
|
23
|
+
eHerkenningLoginButton;
|
|
24
|
+
eHerkenningMachtigingLoginButton;
|
|
25
|
+
klantportaalCookieButton;
|
|
25
26
|
constructor(page) {
|
|
26
27
|
super(page);
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
28
|
+
this.digidLoginButton = page.locator("#oidc-digid");
|
|
29
|
+
this.digidMachtigenLoginButton = page.locator("#digid-machtigen");
|
|
30
|
+
this.eHerkenningLoginButton = page.locator("#oidc-eHerkenning");
|
|
31
|
+
this.eHerkenningMachtigingLoginButton = page.locator("#eherkenning-bewindvoering");
|
|
32
|
+
this.klantportaalCookieButton = page.locator("#ppms_cm_agree-to-all");
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Clicks the button that starts the login flow. Not every consumer has the login overzicht
|
|
36
|
+
* page (e.g. Open Forms), so the button to click can be supplied by the consumer.
|
|
37
|
+
*
|
|
38
|
+
* @param loginButton the button that starts the login flow
|
|
39
|
+
*/
|
|
40
|
+
async clickLoginButton(loginButton) {
|
|
41
|
+
await loginButton.waitFor();
|
|
34
42
|
await this.page.waitForTimeout(2e3);
|
|
35
|
-
await
|
|
43
|
+
await loginButton.click();
|
|
36
44
|
}
|
|
37
|
-
async
|
|
38
|
-
await this.
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
async clickDigidLoginOption() {
|
|
46
|
+
await this.clickLoginButton(this.digidLoginButton);
|
|
47
|
+
}
|
|
48
|
+
async clickDigidMachtigenLoginOption() {
|
|
49
|
+
await this.clickLoginButton(this.digidMachtigenLoginButton);
|
|
41
50
|
}
|
|
42
|
-
async
|
|
43
|
-
await this.
|
|
51
|
+
async clickEHerkenningLoginOption() {
|
|
52
|
+
await this.eHerkenningLoginButton.waitFor();
|
|
44
53
|
await this.page.waitForTimeout(2e3);
|
|
45
54
|
try {
|
|
46
|
-
await this.
|
|
55
|
+
await this.eHerkenningLoginButton.click();
|
|
47
56
|
} catch (_error) {
|
|
48
57
|
await this.reloadPage();
|
|
49
|
-
await this.
|
|
58
|
+
await this.eHerkenningLoginButton.waitFor();
|
|
50
59
|
await this.page.waitForTimeout(2e3);
|
|
51
|
-
await this.
|
|
60
|
+
await this.eHerkenningLoginButton.click();
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
|
-
async
|
|
55
|
-
await this.
|
|
63
|
+
async clickProfessionalBewindvoerderLoginOption() {
|
|
64
|
+
await this.eHerkenningMachtigingLoginButton.waitFor();
|
|
56
65
|
await this.page.waitForTimeout(2e3);
|
|
57
66
|
try {
|
|
58
|
-
await this.
|
|
67
|
+
await this.eHerkenningMachtigingLoginButton.click();
|
|
59
68
|
} catch (_error) {
|
|
60
69
|
await this.reloadPage();
|
|
61
|
-
await this.
|
|
70
|
+
await this.eHerkenningMachtigingLoginButton.waitFor();
|
|
62
71
|
await this.page.waitForTimeout(2e3);
|
|
63
|
-
await this.
|
|
72
|
+
await this.eHerkenningMachtigingLoginButton.click();
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
|
-
async
|
|
75
|
+
async verifyLoginOverviewIsVisible() {
|
|
67
76
|
await expect(this.page.getByRole("heading", { name: "Inloggen voor mijzelf" })).toBeVisible();
|
|
68
77
|
}
|
|
69
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Accepts the cookie banner and waits until the consent is stored in a cookie; skipped when the
|
|
80
|
+
* banner doesn't show within 10 seconds.
|
|
81
|
+
*
|
|
82
|
+
* @param cookieButton the button that accepts the cookie banner, defaults to the klantportaal banner
|
|
83
|
+
*/
|
|
84
|
+
async acceptCookies(cookieButton = this.klantportaalCookieButton) {
|
|
70
85
|
try {
|
|
71
|
-
await this.
|
|
86
|
+
const cookiesBeforeAccepting = await this.cookiesAsText();
|
|
87
|
+
await cookieButton.click({ timeout: 1e4 });
|
|
88
|
+
await this.waitForCookiesToSettle(cookiesBeforeAccepting);
|
|
72
89
|
} catch (_ignore) {}
|
|
73
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Waits until the cookies differ from `cookiesBefore` and have not changed for a second, at most 10 seconds.
|
|
93
|
+
*/
|
|
94
|
+
async waitForCookiesToSettle(cookiesBefore) {
|
|
95
|
+
const settledAfterMs = 1e3;
|
|
96
|
+
const deadline = Date.now() + 1e4;
|
|
97
|
+
let current = cookiesBefore;
|
|
98
|
+
let changedAt = Date.now();
|
|
99
|
+
while (Date.now() < deadline) {
|
|
100
|
+
await this.page.waitForTimeout(250);
|
|
101
|
+
const cookies = await this.cookiesAsText();
|
|
102
|
+
if (cookies !== current) {
|
|
103
|
+
current = cookies;
|
|
104
|
+
changedAt = Date.now();
|
|
105
|
+
} else if (current !== cookiesBefore && Date.now() - changedAt >= settledAfterMs) return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async cookiesAsText() {
|
|
109
|
+
return (await this.page.context().cookies()).map((c) => `${c.domain}|${c.name}=${c.value}`).sort().join(";");
|
|
110
|
+
}
|
|
74
111
|
async reloadPage() {
|
|
75
112
|
try {
|
|
76
113
|
await this.page.reload();
|
|
@@ -110,21 +147,25 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
110
147
|
/**
|
|
111
148
|
* @param account login details, supplied by the consumer of this library
|
|
112
149
|
* @param fileName path of the storage state file to write the session to
|
|
150
|
+
* @param options the app's DigiD login button, and optionally where to start and its cookie
|
|
151
|
+
* banner, supplied by the consumer of this library
|
|
113
152
|
*/
|
|
114
|
-
async loginAndCreateNewSession(account, fileName) {
|
|
153
|
+
async loginAndCreateNewSession(account, fileName, options) {
|
|
154
|
+
const loginButton = options.loginButton(this.page);
|
|
155
|
+
const { startUrl } = options;
|
|
115
156
|
await test.step("Login with DigiD and create session", async () => {
|
|
116
|
-
await this.openPage();
|
|
157
|
+
await this.openPage(startUrl);
|
|
117
158
|
await this.handleAnySpecialADLoginScreen();
|
|
118
159
|
try {
|
|
119
|
-
await this.
|
|
160
|
+
await this.clickLoginButton(loginButton);
|
|
120
161
|
} catch (_error) {
|
|
121
|
-
await this.openPage();
|
|
162
|
+
await this.openPage(startUrl);
|
|
122
163
|
await this.handleAnySpecialADLoginScreen();
|
|
123
|
-
await this.
|
|
164
|
+
await this.clickLoginButton(loginButton);
|
|
124
165
|
}
|
|
125
166
|
if (!this.page.url().match(/authn/)) {
|
|
126
167
|
await this.loginWithDigid(account);
|
|
127
|
-
await this.
|
|
168
|
+
await this.acceptCookiesForApp(options);
|
|
128
169
|
}
|
|
129
170
|
await this.page.context().storageState({ path: fileName });
|
|
130
171
|
});
|
|
@@ -132,25 +173,35 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
132
173
|
/**
|
|
133
174
|
* @param account login details, supplied by the consumer of this library
|
|
134
175
|
* @param fileName path of the storage state file to write the session to
|
|
176
|
+
* @param options the app's DigiD machtigen login button, and optionally where to start and its cookie
|
|
177
|
+
* banner, supplied by the consumer of this library
|
|
135
178
|
*/
|
|
136
|
-
async loginAndCreateNewGemachtigdeSession(account, fileName) {
|
|
179
|
+
async loginAndCreateNewGemachtigdeSession(account, fileName, options) {
|
|
180
|
+
const loginButton = options.loginButton(this.page);
|
|
181
|
+
const { startUrl } = options;
|
|
137
182
|
await test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
138
|
-
await this.openPage();
|
|
183
|
+
await this.openPage(startUrl);
|
|
139
184
|
await this.handleAnySpecialADLoginScreen();
|
|
140
185
|
try {
|
|
141
|
-
await this.
|
|
186
|
+
await this.clickLoginButton(loginButton);
|
|
142
187
|
} catch (_error) {
|
|
143
|
-
await this.openPage();
|
|
144
|
-
await this.
|
|
188
|
+
await this.openPage(startUrl);
|
|
189
|
+
await this.clickLoginButton(loginButton);
|
|
145
190
|
}
|
|
146
191
|
await this.loginWithDigid(account, true);
|
|
147
|
-
await this.
|
|
192
|
+
await this.acceptCookiesForApp(options);
|
|
148
193
|
await this.page.context().storageState({ path: fileName });
|
|
149
194
|
});
|
|
150
195
|
}
|
|
151
196
|
/**
|
|
152
|
-
*
|
|
153
|
-
|
|
197
|
+
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
198
|
+
*/
|
|
199
|
+
async acceptCookiesForApp(options) {
|
|
200
|
+
if (options.cookieButton) await this.acceptCookies(options.cookieButton(this.page));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* When there is already an AD session, but for another environment, a special screen asks to
|
|
204
|
+
* confirm the account before you can continue.
|
|
154
205
|
*/
|
|
155
206
|
async handleAnySpecialADLoginScreen() {
|
|
156
207
|
try {
|
|
@@ -167,20 +218,23 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
167
218
|
await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
|
|
168
219
|
await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
|
|
169
220
|
await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
|
|
170
|
-
await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "
|
|
221
|
+
await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "password");
|
|
171
222
|
const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
|
|
172
223
|
await this.page.getByRole("button", { name: "Inloggen" }).click();
|
|
173
224
|
if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
|
|
174
225
|
return await responsePromise;
|
|
175
226
|
});
|
|
176
227
|
}
|
|
177
|
-
|
|
228
|
+
/**
|
|
229
|
+
* @param loginButton button that starts the DigiD machtigen login, supplied by the consumer of this library
|
|
230
|
+
*/
|
|
231
|
+
async loginAsDigidGemachtigde(loginButton) {
|
|
178
232
|
await test.step("Login as DigiD gemachtigde", async () => {
|
|
179
233
|
const gemachtigde = {
|
|
180
234
|
username: `${process$1.env.DIGID_GEMACHTIGDE_USER}`,
|
|
181
235
|
password: `${process$1.env.DIGID_GEMACHTIGDE_PASSWORD}`
|
|
182
236
|
};
|
|
183
|
-
await this.
|
|
237
|
+
await this.clickLoginButton(loginButton);
|
|
184
238
|
await this.loginWithDigid(gemachtigde, true);
|
|
185
239
|
});
|
|
186
240
|
}
|
|
@@ -188,13 +242,23 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
188
242
|
//#endregion
|
|
189
243
|
//#region src/auth/loginhandlers/digidLoginHandler.ts
|
|
190
244
|
var DigidLoginHandler = class {
|
|
245
|
+
options;
|
|
246
|
+
/**
|
|
247
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
248
|
+
*
|
|
249
|
+
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
250
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
251
|
+
*/
|
|
252
|
+
constructor(options) {
|
|
253
|
+
this.options = options;
|
|
254
|
+
}
|
|
191
255
|
/**
|
|
192
256
|
* @param page the Playwright page to perform the login on
|
|
193
257
|
* @param account login details, supplied by the consumer of this library
|
|
194
258
|
* @param file path of the storage state file to write the session to
|
|
195
259
|
*/
|
|
196
260
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
197
|
-
await new DigidLoginPage(page).loginAndCreateNewSession(account, file);
|
|
261
|
+
await new DigidLoginPage(page).loginAndCreateNewSession(account, file, this.options);
|
|
198
262
|
}
|
|
199
263
|
};
|
|
200
264
|
//#endregion
|
|
@@ -204,35 +268,35 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
204
268
|
buttonConfirmIdentityProviderSelection;
|
|
205
269
|
textfieldUsername;
|
|
206
270
|
textfieldPassword;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
271
|
+
loginButton;
|
|
272
|
+
continueButton;
|
|
273
|
+
continueLink;
|
|
210
274
|
inputBsn;
|
|
211
|
-
|
|
275
|
+
searchButton;
|
|
212
276
|
constructor(page) {
|
|
213
277
|
super(page);
|
|
214
278
|
this.dropdownSelectIdentityProvider = page.locator("#identity_provider");
|
|
215
279
|
this.buttonConfirmIdentityProviderSelection = page.locator("//*[@name='commit']");
|
|
216
280
|
this.textfieldUsername = page.locator("#account_username");
|
|
217
281
|
this.textfieldPassword = page.locator("#account_password");
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
282
|
+
this.loginButton = page.getByRole("button", { name: /Inloggen|Log in/ });
|
|
283
|
+
this.continueButton = page.getByRole("button", { name: /Verder|Continue|Ga verder/ });
|
|
220
284
|
this.inputBsn = page.locator("#bsn-input");
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
285
|
+
this.searchButton = page.locator("#search-submit");
|
|
286
|
+
this.continueLink = page.getByRole("link", { name: /Verder|Continue|Ga verder/ });
|
|
223
287
|
}
|
|
224
288
|
/**
|
|
225
289
|
* @param account login details, supplied by the consumer of this library
|
|
226
290
|
*/
|
|
227
|
-
async
|
|
291
|
+
async tryLoginWithEHerkenning(account) {
|
|
228
292
|
await test.step("Fill eHerkenning credentials and submit", async () => {
|
|
229
293
|
await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
|
|
230
294
|
await this.page.locator("#remember").click();
|
|
231
295
|
await this.buttonConfirmIdentityProviderSelection.click();
|
|
232
296
|
await this.textfieldUsername.fill(account.username);
|
|
233
|
-
await this.
|
|
234
|
-
await maskedFill(this.textfieldPassword, account.password, "
|
|
235
|
-
await this.
|
|
297
|
+
await this.continueButton.click();
|
|
298
|
+
await maskedFill(this.textfieldPassword, account.password, "password");
|
|
299
|
+
await this.loginButton.click();
|
|
236
300
|
});
|
|
237
301
|
}
|
|
238
302
|
/**
|
|
@@ -243,10 +307,10 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
243
307
|
await test.step("Login with eHerkenning and create session", async () => {
|
|
244
308
|
await this.openPage();
|
|
245
309
|
try {
|
|
246
|
-
await this.
|
|
310
|
+
await this.clickEHerkenningLoginOption();
|
|
247
311
|
} catch (_error) {
|
|
248
312
|
await this.openPage();
|
|
249
|
-
await this.
|
|
313
|
+
await this.clickEHerkenningLoginOption();
|
|
250
314
|
}
|
|
251
315
|
await this.loginWithEHerkenning(account);
|
|
252
316
|
await this.page.context().storageState({ path: fileName });
|
|
@@ -256,11 +320,11 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
256
320
|
* @param account login details, supplied by the consumer of this library
|
|
257
321
|
*/
|
|
258
322
|
async loginWithEHerkenning(account) {
|
|
259
|
-
await this.
|
|
323
|
+
await this.tryLoginWithEHerkenning(account);
|
|
260
324
|
await test.step("Confirm eHerkenning login and accept cookies", async () => {
|
|
261
325
|
await this.page.waitForTimeout(2e3);
|
|
262
|
-
if (await this.
|
|
263
|
-
await this.
|
|
326
|
+
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
327
|
+
await this.acceptCookies();
|
|
264
328
|
});
|
|
265
329
|
}
|
|
266
330
|
/**
|
|
@@ -271,10 +335,10 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
271
335
|
await test.step("Login with eHerkenning vestiging and create session", async () => {
|
|
272
336
|
await this.openPage();
|
|
273
337
|
try {
|
|
274
|
-
await this.
|
|
338
|
+
await this.clickEHerkenningLoginOption();
|
|
275
339
|
} catch (_error) {
|
|
276
340
|
await this.openPage();
|
|
277
|
-
await this.
|
|
341
|
+
await this.clickEHerkenningLoginOption();
|
|
278
342
|
}
|
|
279
343
|
await this.loginWithEHerkenningVestiging(account);
|
|
280
344
|
await this.page.context().storageState({ path: fileName });
|
|
@@ -284,38 +348,38 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
284
348
|
* @param account login details, supplied by the consumer of this library
|
|
285
349
|
*/
|
|
286
350
|
async loginWithEHerkenningVestiging(account) {
|
|
287
|
-
await this.
|
|
351
|
+
await this.tryLoginWithEHerkenning(account);
|
|
288
352
|
await test.step("Confirm eHerkenning vestiging login and accept cookies", async () => {
|
|
289
353
|
await this.page.waitForTimeout(2e3);
|
|
290
|
-
if (await this.
|
|
291
|
-
await this.
|
|
354
|
+
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
355
|
+
await this.acceptCookies();
|
|
292
356
|
});
|
|
293
357
|
}
|
|
294
358
|
/**
|
|
295
359
|
* @param gemachtigde login details of the authorized representative (bewindvoerder), supplied by the consumer of this library
|
|
296
360
|
* @param file optional path of the storage state file to write the session to
|
|
297
361
|
*/
|
|
298
|
-
async
|
|
362
|
+
async loginAsProfessionalBewindvoerder(gemachtigde, file) {
|
|
299
363
|
await test.step("Open bewindvoerder login option", async () => {
|
|
300
364
|
await this.openPage();
|
|
301
|
-
await this.
|
|
365
|
+
await this.clickProfessionalBewindvoerderLoginOption();
|
|
302
366
|
});
|
|
303
367
|
await test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
304
368
|
try {
|
|
305
|
-
await this.
|
|
369
|
+
await this.tryLoginWithEHerkenning(gemachtigde);
|
|
306
370
|
} catch (_error) {
|
|
307
371
|
await this.openPage();
|
|
308
|
-
await this.
|
|
372
|
+
await this.tryLoginWithEHerkenning(gemachtigde);
|
|
309
373
|
}
|
|
310
374
|
});
|
|
311
375
|
await test.step("Search for client by BSN and accept cookies", async () => {
|
|
312
376
|
if (gemachtigde.bsn != null) {
|
|
313
|
-
await this.
|
|
377
|
+
await this.continueLink.click();
|
|
314
378
|
await maskedFill(this.inputBsn, gemachtigde.bsn, "bsn");
|
|
315
379
|
}
|
|
316
|
-
await this.
|
|
317
|
-
await this.
|
|
318
|
-
await this.
|
|
380
|
+
await this.searchButton.click();
|
|
381
|
+
await this.continueLink.click();
|
|
382
|
+
await this.acceptCookies();
|
|
319
383
|
});
|
|
320
384
|
if (file) await test.step("Save session state", async () => {
|
|
321
385
|
await this.page.context().storageState({ path: file });
|
|
@@ -337,13 +401,23 @@ var EHerkenningLoginHandler = class {
|
|
|
337
401
|
//#endregion
|
|
338
402
|
//#region src/auth/loginhandlers/digidGemachtigdeLoginHandler.ts
|
|
339
403
|
var DigidGemachtigdeLoginHandler = class {
|
|
404
|
+
options;
|
|
405
|
+
/**
|
|
406
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
407
|
+
*
|
|
408
|
+
* @param options the app's DigiD machtigen login button (required), and optionally where to start and the
|
|
409
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
410
|
+
*/
|
|
411
|
+
constructor(options) {
|
|
412
|
+
this.options = options;
|
|
413
|
+
}
|
|
340
414
|
/**
|
|
341
415
|
* @param page the Playwright page to perform the login on
|
|
342
416
|
* @param account login details, supplied by the consumer of this library
|
|
343
417
|
* @param file path of the storage state file to write the session to
|
|
344
418
|
*/
|
|
345
419
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
346
|
-
await new DigidLoginPage(page).loginAndCreateNewGemachtigdeSession(account, file);
|
|
420
|
+
await new DigidLoginPage(page).loginAndCreateNewGemachtigdeSession(account, file, this.options);
|
|
347
421
|
}
|
|
348
422
|
};
|
|
349
423
|
//#endregion
|
|
@@ -355,7 +429,7 @@ var EHerkenningBewindvoerderLoginHandler = class {
|
|
|
355
429
|
* @param file path of the storage state file to write the session to
|
|
356
430
|
*/
|
|
357
431
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
358
|
-
await new EHerkenningLoginPage(page).
|
|
432
|
+
await new EHerkenningLoginPage(page).loginAsProfessionalBewindvoerder(account, file);
|
|
359
433
|
}
|
|
360
434
|
};
|
|
361
435
|
//#endregion
|
|
@@ -367,24 +441,24 @@ function escapeRegExp(value) {
|
|
|
367
441
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
368
442
|
}
|
|
369
443
|
var ADLoginPage = class ADLoginPage extends BasePage {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
444
|
+
usernameInput;
|
|
445
|
+
passwordInput;
|
|
446
|
+
nextInput;
|
|
447
|
+
signInInput;
|
|
448
|
+
cannotUseAuthAppLink;
|
|
449
|
+
useVerificationCode;
|
|
376
450
|
codeInput;
|
|
377
|
-
|
|
451
|
+
verifyInput;
|
|
378
452
|
constructor(page) {
|
|
379
453
|
super(page);
|
|
380
|
-
this.
|
|
381
|
-
this.
|
|
382
|
-
this.
|
|
383
|
-
this.
|
|
384
|
-
this.
|
|
385
|
-
this.
|
|
454
|
+
this.usernameInput = page.locator("//input[@type='email']");
|
|
455
|
+
this.passwordInput = page.locator("//input[@name='passwd']");
|
|
456
|
+
this.nextInput = page.locator("//input[@type='submit']");
|
|
457
|
+
this.signInInput = page.locator("//input[@type='submit']");
|
|
458
|
+
this.cannotUseAuthAppLink = page.locator("//*[@id='signInAnotherWay']");
|
|
459
|
+
this.useVerificationCode = page.getByText(/Gebruik een verificatiecode|Use a verification code/);
|
|
386
460
|
this.codeInput = page.locator("//input[@name='otc']");
|
|
387
|
-
this.
|
|
461
|
+
this.verifyInput = page.locator("//input[@type='submit']");
|
|
388
462
|
}
|
|
389
463
|
async openPage(path) {
|
|
390
464
|
await this.page.goto(path);
|
|
@@ -427,7 +501,7 @@ var ADLoginPage = class ADLoginPage extends BasePage {
|
|
|
427
501
|
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
428
502
|
if (alreadyFullyAuthenticated) return;
|
|
429
503
|
const cachedAccountTile = this.page.getByRole("button", { name: new RegExp(escapeRegExp(account.username), "i") });
|
|
430
|
-
await cachedAccountTile.or(adLoginPage.
|
|
504
|
+
await cachedAccountTile.or(adLoginPage.usernameInput).waitFor({
|
|
431
505
|
state: "visible",
|
|
432
506
|
timeout: 1e4
|
|
433
507
|
}).catch(() => {});
|
|
@@ -436,9 +510,9 @@ var ADLoginPage = class ADLoginPage extends BasePage {
|
|
|
436
510
|
await cachedAccountTile.click();
|
|
437
511
|
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
438
512
|
} else {
|
|
439
|
-
await adLoginPage.
|
|
440
|
-
await adLoginPage.
|
|
441
|
-
await adLoginPage.
|
|
513
|
+
await adLoginPage.usernameInput.waitFor();
|
|
514
|
+
await adLoginPage.usernameInput.fill(account.username);
|
|
515
|
+
await adLoginPage.nextInput.click();
|
|
442
516
|
await this.page.getByText("Uw wachtwoord gebruiken").click();
|
|
443
517
|
}
|
|
444
518
|
});
|
|
@@ -446,18 +520,18 @@ var ADLoginPage = class ADLoginPage extends BasePage {
|
|
|
446
520
|
if (!alreadyFullyAuthenticated) {
|
|
447
521
|
await test.step("Fill AD password and submit", async () => {
|
|
448
522
|
if (!cachedAccountUsed) {
|
|
449
|
-
await maskedFill(adLoginPage.
|
|
450
|
-
await adLoginPage.
|
|
523
|
+
await maskedFill(adLoginPage.passwordInput, account.password, "password");
|
|
524
|
+
await adLoginPage.signInInput.click();
|
|
451
525
|
await this.page.waitForTimeout(1e3);
|
|
452
526
|
}
|
|
453
527
|
sessionWasStale = await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible().catch(() => false);
|
|
454
528
|
});
|
|
455
529
|
await test.step("Complete MFA via TOTP", async () => {
|
|
456
|
-
if (!sessionWasStale) await adLoginPage.
|
|
457
|
-
await adLoginPage.
|
|
530
|
+
if (!sessionWasStale) await adLoginPage.cannotUseAuthAppLink.click();
|
|
531
|
+
await adLoginPage.useVerificationCode.click();
|
|
458
532
|
const token = await TOTP.generate(`${process.env.AD_SECRET}`);
|
|
459
533
|
await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
|
|
460
|
-
await adLoginPage.
|
|
534
|
+
await adLoginPage.verifyInput.click();
|
|
461
535
|
await adLoginPage.page.waitForTimeout(5e3);
|
|
462
536
|
});
|
|
463
537
|
}
|
|
@@ -507,24 +581,47 @@ var ADLoginHandler = class {
|
|
|
507
581
|
//#endregion
|
|
508
582
|
//#region src/auth/getLoginHandler.ts
|
|
509
583
|
/**
|
|
584
|
+
* Shortcut for creating the login handler for an auth type. Creating the handler directly, e.g.
|
|
585
|
+
* `new DigidLoginHandler(options)`, checks at compile time that the required options are there;
|
|
586
|
+
* this function checks at runtime.
|
|
587
|
+
*
|
|
510
588
|
* @param authType type of login
|
|
511
|
-
* @param
|
|
512
|
-
* app behind the firewall
|
|
513
|
-
* `
|
|
589
|
+
* @param options where to start the login, supplied by the consumer of this library.
|
|
590
|
+
* - `ad-session`: `startUrl` is required - the app behind the firewall to navigate to before logging in.
|
|
591
|
+
* - `digid` / `digid_gemachtigde`: `loginButton` is required - the app's DigiD button. `startUrl` defaults
|
|
592
|
+
* to `PORTAL_BASE_URL`; `cookieButton` is optional.
|
|
593
|
+
* - other auth types: ignored.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* getLoginHandler('digid', {
|
|
597
|
+
* startUrl: 'https://openformulieren-zgw.acc.denhaag.nl/<form>/startpagina',
|
|
598
|
+
* loginButton: (page) => page.getByRole('link', { name: 'Inloggen met DigiD' }),
|
|
599
|
+
* cookieButton: (page) => page.locator('button[class*="cookie-notice__accept"]'),
|
|
600
|
+
* });
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* getLoginHandler('ad-session', { startUrl: 'https://alg-zgw.test.denhaag.nl/' });
|
|
514
604
|
*/
|
|
515
|
-
function getLoginHandler(authType,
|
|
605
|
+
function getLoginHandler(authType, options = {}) {
|
|
516
606
|
switch (authType) {
|
|
517
|
-
case "digid": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new DigidLoginHandler();
|
|
518
|
-
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler();
|
|
607
|
+
case "digid": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new DigidLoginHandler(digidOptions(authType, options));
|
|
608
|
+
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler(digidOptions(authType, options));
|
|
519
609
|
case "eherkenning": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new EHerkenningLoginHandler();
|
|
520
610
|
case "eherkenning_vestiging": return new EHerkenningLoginHandler();
|
|
521
611
|
case "eherkenning_bewindvoerder": return new EHerkenningBewindvoerderLoginHandler();
|
|
522
612
|
case "ad-session":
|
|
523
|
-
if (!
|
|
524
|
-
return new ADLoginHandler(
|
|
613
|
+
if (!options.startUrl) throw new Error("startUrl is required when authType is 'ad-session'");
|
|
614
|
+
return new ADLoginHandler(options.startUrl);
|
|
525
615
|
default: throw new Error(`Unsupported auth type: ${authType}. If needed please create a new LoginHandler and register it here in getLoginHandler().`);
|
|
526
616
|
}
|
|
527
617
|
}
|
|
618
|
+
function digidOptions(authType, options) {
|
|
619
|
+
if (!options.loginButton) throw new Error(`loginButton is required when authType is '${authType}'`);
|
|
620
|
+
return {
|
|
621
|
+
...options,
|
|
622
|
+
loginButton: options.loginButton
|
|
623
|
+
};
|
|
624
|
+
}
|
|
528
625
|
//#endregion
|
|
529
626
|
//#region src/auth/utils/sessionFileHelper.ts
|
|
530
627
|
var sessionsDir = process$2.env.SESSIONS_DIR ?? path.resolve(process$2.cwd(), "sessions");
|
|
@@ -725,13 +822,24 @@ function getApiTokenFromSession(baseTest, handler) {
|
|
|
725
822
|
//#endregion
|
|
726
823
|
//#region src/auth/getSessionHandler.ts
|
|
727
824
|
/**
|
|
728
|
-
* @param testProfile
|
|
729
|
-
* @param
|
|
730
|
-
* `
|
|
731
|
-
*
|
|
825
|
+
* @param testProfile the test user to log in
|
|
826
|
+
* @param loginHandler the login handler for the app the user logs in to, with that app's options, e.g.
|
|
827
|
+
* `new DigidLoginHandler({ loginButton, ... })` or `getLoginHandler(authType, options)`. Required for
|
|
828
|
+
* auth types that need options (`ad-session`, `digid`, `digid_gemachtigde`); left out, the handler
|
|
829
|
+
* for `testProfile.authType` is created without options.
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* // once per app
|
|
833
|
+
* export const openFormsDigid = new DigidLoginHandler({
|
|
834
|
+
* startUrl: 'https://openformulieren-zgw.acc.denhaag.nl/<form>/startpagina',
|
|
835
|
+
* loginButton: (page) => page.getByRole('link', { name: 'Inloggen met DigiD' }),
|
|
836
|
+
* cookieButton: (page) => page.locator('button[class*="cookie-notice__accept"]'),
|
|
837
|
+
* });
|
|
838
|
+
*
|
|
839
|
+
* getSessionHandler(digidUser1, openFormsDigid);
|
|
732
840
|
*/
|
|
733
|
-
function getSessionHandler(testProfile,
|
|
734
|
-
return createSessionHandler(testProfile.authType, testProfile.account, getLoginHandler(testProfile.authType
|
|
841
|
+
function getSessionHandler(testProfile, loginHandler) {
|
|
842
|
+
return createSessionHandler(testProfile.authType, testProfile.account, loginHandler ?? getLoginHandler(testProfile.authType));
|
|
735
843
|
}
|
|
736
844
|
//#endregion
|
|
737
845
|
export { ADLoginHandler, ADLoginPage, DigidGemachtigdeLoginHandler, DigidLoginHandler, DigidLoginPage, EHerkenningBewindvoerderLoginHandler, EHerkenningLoginHandler, EHerkenningLoginPage, LocalhostLoginHandler, LoginOverzichtPage, MAX_SESSION_TIME_IN_MINUTES, SessionFileHelper, createSessionHandler, getApiTokenFromSession, getLoginHandler, getSessionHandler, maskedFill };
|