dh-auth-library 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -31
- package/dist/auth/getLoginHandler.d.ts +22 -5
- package/dist/auth/getSessionHandler.d.ts +19 -5
- package/dist/auth/loginhandlers/digidGemachtigdeLoginHandler.d.ts +9 -0
- package/dist/auth/loginhandlers/digidLoginHandler.d.ts +9 -0
- package/dist/auth/loginhandlers/eHerkenningBewindvoerderLoginHandler.d.ts +9 -0
- package/dist/auth/loginhandlers/eHerkenningLoginHandler.d.ts +9 -0
- package/dist/auth/pages/adLoginPage.d.ts +7 -7
- package/dist/auth/pages/baseLoginPage.d.ts +25 -0
- package/dist/auth/pages/digidLoginPage.d.ts +20 -9
- package/dist/auth/pages/eHerkenningLoginPage.d.ts +17 -12
- package/dist/auth/pages/index.d.ts +1 -1
- package/dist/index.cjs.js +414 -360
- package/dist/index.es.js +415 -361
- package/package.json +58 -57
- package/dist/auth/pages/loginOverzichtPage.d.ts +0 -16
package/dist/index.es.js
CHANGED
|
@@ -1,83 +1,9 @@
|
|
|
1
1
|
import { BasePage, LocalLoginPage, SessionManager, Url, getUrl, isRunningOnLocalhost, urls } from "nl-portal-playwright-libraries";
|
|
2
|
-
import {
|
|
2
|
+
import { test } from "@playwright/test";
|
|
3
|
+
import { TOTP } from "totp-generator";
|
|
3
4
|
import * as process$2 from "node:process";
|
|
4
5
|
import process$1 from "node:process";
|
|
5
|
-
import { TOTP } from "totp-generator";
|
|
6
6
|
import * as path from "node:path";
|
|
7
|
-
//#region src/auth/loginhandlers/localhostLoginHandler.ts
|
|
8
|
-
var LocalhostLoginHandler = class {
|
|
9
|
-
/**
|
|
10
|
-
* @param page the Playwright page to perform the login on
|
|
11
|
-
* @param account login details, supplied by the consumer of this library
|
|
12
|
-
* @param file path of the storage state file to write the session to
|
|
13
|
-
*/
|
|
14
|
-
async loginAndCreateSessionStorage(page, account, file) {
|
|
15
|
-
await new LocalLoginPage(page).loginAndCreateNewSession(account, file);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/auth/pages/loginOverzichtPage.ts
|
|
20
|
-
var LoginOverzichtPage = class extends BasePage {
|
|
21
|
-
digidLoginKnop;
|
|
22
|
-
digidMachtigenLoginKnop;
|
|
23
|
-
eHerkenningLoginKnop;
|
|
24
|
-
eHerkenningMachtigingLoginKnop;
|
|
25
|
-
constructor(page) {
|
|
26
|
-
super(page);
|
|
27
|
-
this.digidLoginKnop = page.locator("#oidc-digid");
|
|
28
|
-
this.digidMachtigenLoginKnop = page.locator("#digid-machtigen");
|
|
29
|
-
this.eHerkenningLoginKnop = page.locator("#oidc-eHerkenning");
|
|
30
|
-
this.eHerkenningMachtigingLoginKnop = page.locator("#eherkenning-bewindvoering");
|
|
31
|
-
}
|
|
32
|
-
async klikOpDigidLoginOptie() {
|
|
33
|
-
await this.digidLoginKnop.waitFor();
|
|
34
|
-
await this.page.waitForTimeout(2e3);
|
|
35
|
-
await this.digidLoginKnop.click();
|
|
36
|
-
}
|
|
37
|
-
async klikOpDigidMachtigenLoginOptie() {
|
|
38
|
-
await this.digidMachtigenLoginKnop.waitFor();
|
|
39
|
-
await this.page.waitForTimeout(2e3);
|
|
40
|
-
await this.digidMachtigenLoginKnop.click();
|
|
41
|
-
}
|
|
42
|
-
async klikOpEHerkenningLoginOptie() {
|
|
43
|
-
await this.eHerkenningLoginKnop.waitFor();
|
|
44
|
-
await this.page.waitForTimeout(2e3);
|
|
45
|
-
try {
|
|
46
|
-
await this.eHerkenningLoginKnop.click();
|
|
47
|
-
} catch (_error) {
|
|
48
|
-
await this.reloadPage();
|
|
49
|
-
await this.eHerkenningLoginKnop.waitFor();
|
|
50
|
-
await this.page.waitForTimeout(2e3);
|
|
51
|
-
await this.eHerkenningLoginKnop.click();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async klikOpProfessioneelBewindvoerderLoginOptie() {
|
|
55
|
-
await this.eHerkenningMachtigingLoginKnop.waitFor();
|
|
56
|
-
await this.page.waitForTimeout(2e3);
|
|
57
|
-
try {
|
|
58
|
-
await this.eHerkenningMachtigingLoginKnop.click();
|
|
59
|
-
} catch (_error) {
|
|
60
|
-
await this.reloadPage();
|
|
61
|
-
await this.eHerkenningMachtigingLoginKnop.waitFor();
|
|
62
|
-
await this.page.waitForTimeout(2e3);
|
|
63
|
-
await this.eHerkenningMachtigingLoginKnop.click();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async valideerDatHetLoginOverzichtZichtbaarIs() {
|
|
67
|
-
await expect(this.page.getByRole("heading", { name: "Inloggen voor mijzelf" })).toBeVisible();
|
|
68
|
-
}
|
|
69
|
-
async accepteerCookies() {
|
|
70
|
-
try {
|
|
71
|
-
await this.page.locator("#ppms_cm_agree-to-all").click();
|
|
72
|
-
} catch (_ignore) {}
|
|
73
|
-
}
|
|
74
|
-
async reloadPage() {
|
|
75
|
-
try {
|
|
76
|
-
await this.page.reload();
|
|
77
|
-
} catch (_error) {}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
//#endregion
|
|
81
7
|
//#region src/auth/utils/maskedFill.ts
|
|
82
8
|
function isEnvValue(value) {
|
|
83
9
|
return value !== "" && Object.values(process.env).includes(value);
|
|
@@ -102,29 +28,244 @@ async function maskedFill(locator, value, propertyName, forceMask = false) {
|
|
|
102
28
|
});
|
|
103
29
|
}
|
|
104
30
|
//#endregion
|
|
31
|
+
//#region src/auth/pages/adLoginPage.ts
|
|
32
|
+
var gzacUrlProd = "https://alg-zgw.denhaag.nl";
|
|
33
|
+
var gzacUrlAcp = "https://alg-zgw.acc.denhaag.nl";
|
|
34
|
+
var gzacUrlTest = "https://alg-zgw.test.denhaag.nl";
|
|
35
|
+
function escapeRegExp(value) {
|
|
36
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37
|
+
}
|
|
38
|
+
var ADLoginPage = class ADLoginPage extends BasePage {
|
|
39
|
+
usernameInput;
|
|
40
|
+
passwordInput;
|
|
41
|
+
nextInput;
|
|
42
|
+
signInInput;
|
|
43
|
+
cannotUseAuthAppLink;
|
|
44
|
+
useVerificationCode;
|
|
45
|
+
codeInput;
|
|
46
|
+
verifyInput;
|
|
47
|
+
constructor(page) {
|
|
48
|
+
super(page);
|
|
49
|
+
this.usernameInput = page.locator("//input[@type='email']");
|
|
50
|
+
this.passwordInput = page.locator("//input[@name='passwd']");
|
|
51
|
+
this.nextInput = page.locator("//input[@type='submit']");
|
|
52
|
+
this.signInInput = page.locator("//input[@type='submit']");
|
|
53
|
+
this.cannotUseAuthAppLink = page.locator("//*[@id='signInAnotherWay']");
|
|
54
|
+
this.useVerificationCode = page.getByText(/Gebruik een verificatiecode|Use a verification code/);
|
|
55
|
+
this.codeInput = page.locator("//input[@name='otc']");
|
|
56
|
+
this.verifyInput = page.locator("//input[@type='submit']");
|
|
57
|
+
}
|
|
58
|
+
async openPage(path) {
|
|
59
|
+
await this.page.goto(path);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Login with the AD account so we can get behind the firewall
|
|
63
|
+
*
|
|
64
|
+
* @param account login details, supplied by the consumer of this library
|
|
65
|
+
* @param targetUrl URL to navigate to before logging in (the app behind the firewall),
|
|
66
|
+
* supplied by the consumer of this library — not every consumer has a GZAC account, so
|
|
67
|
+
* this library no longer assumes GZAC as the destination. The consumer is responsible
|
|
68
|
+
* for switching between environments (e.g. test/acc/prod) when building this URL; this
|
|
69
|
+
* library does not do that for you.
|
|
70
|
+
* @param fileName path of the storage state file to write the session to
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // consumer-side lookup, e.g. based on an `ENV` environment variable
|
|
74
|
+
* export const TARGET_URL_BY_ENVIRONMENT = {
|
|
75
|
+
* test: 'https://alg-zgw.test.denhaag.nl/',
|
|
76
|
+
* acc: 'https://alg-zgw.acc.denhaag.nl/',
|
|
77
|
+
* prod: 'https://alg-zgw.denhaag.nl/',
|
|
78
|
+
* } as const;
|
|
79
|
+
*
|
|
80
|
+
* const env = (process.env.ENV ?? 'test') as keyof typeof TARGET_URL_BY_ENVIRONMENT;
|
|
81
|
+
* await adLoginPage.loginWithADAccountAndCreateSession(account, TARGET_URL_BY_ENVIRONMENT[env], fileName);
|
|
82
|
+
*/
|
|
83
|
+
async loginWithADAccountAndCreateSession(account, targetUrl, fileName) {
|
|
84
|
+
const adLoginPage = new ADLoginPage(this.page);
|
|
85
|
+
let targetOrigin;
|
|
86
|
+
try {
|
|
87
|
+
targetOrigin = new URL(targetUrl).origin;
|
|
88
|
+
} catch {
|
|
89
|
+
throw new Error(`AD login failed: targetUrl must be an absolute URL (e.g. "https://app.denhaag.nl/..."), got "${targetUrl}"`);
|
|
90
|
+
}
|
|
91
|
+
const isOnTargetApp = async () => this.page.waitForLoadState("networkidle").then(() => this.page.url().startsWith(targetOrigin), () => false);
|
|
92
|
+
let cachedAccountUsed = false;
|
|
93
|
+
let alreadyFullyAuthenticated = false;
|
|
94
|
+
await test.step("Fill AD username and submit", async () => {
|
|
95
|
+
await this.page.goto(targetUrl);
|
|
96
|
+
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
97
|
+
if (alreadyFullyAuthenticated) return;
|
|
98
|
+
const cachedAccountTile = this.page.getByRole("button", { name: new RegExp(escapeRegExp(account.username), "i") });
|
|
99
|
+
await cachedAccountTile.or(adLoginPage.usernameInput).waitFor({
|
|
100
|
+
state: "visible",
|
|
101
|
+
timeout: 1e4
|
|
102
|
+
}).catch(() => {});
|
|
103
|
+
cachedAccountUsed = await cachedAccountTile.isVisible().catch(() => false);
|
|
104
|
+
if (cachedAccountUsed) {
|
|
105
|
+
await cachedAccountTile.click();
|
|
106
|
+
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
107
|
+
} else {
|
|
108
|
+
await adLoginPage.usernameInput.waitFor();
|
|
109
|
+
await adLoginPage.usernameInput.fill(account.username);
|
|
110
|
+
await adLoginPage.nextInput.click();
|
|
111
|
+
await this.page.getByText("Uw wachtwoord gebruiken").click();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
let sessionWasStale = false;
|
|
115
|
+
if (!alreadyFullyAuthenticated) {
|
|
116
|
+
await test.step("Fill AD password and submit", async () => {
|
|
117
|
+
if (!cachedAccountUsed) {
|
|
118
|
+
await maskedFill(adLoginPage.passwordInput, account.password, "password");
|
|
119
|
+
await adLoginPage.signInInput.click();
|
|
120
|
+
await this.page.waitForTimeout(1e3);
|
|
121
|
+
}
|
|
122
|
+
sessionWasStale = await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible().catch(() => false);
|
|
123
|
+
});
|
|
124
|
+
await test.step("Complete MFA via TOTP", async () => {
|
|
125
|
+
if (!sessionWasStale) await adLoginPage.cannotUseAuthAppLink.click();
|
|
126
|
+
await adLoginPage.useVerificationCode.click();
|
|
127
|
+
const token = await TOTP.generate(`${process.env.AD_SECRET}`);
|
|
128
|
+
await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
|
|
129
|
+
await adLoginPage.verifyInput.click();
|
|
130
|
+
await adLoginPage.page.waitForTimeout(5e3);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
await test.step("Save session state", async () => {
|
|
134
|
+
await adLoginPage.page.context().storageState({ path: fileName });
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Determines the GZAC URL to log in against, based on the current environment.
|
|
139
|
+
*
|
|
140
|
+
* @deprecated GZAC-specific and no longer called internally by this library — pass your own
|
|
141
|
+
* target URL to {@link loginWithADAccountAndCreateSession} instead. Kept only so existing
|
|
142
|
+
* GZAC consumers can still derive this URL themselves during migration; will be removed in
|
|
143
|
+
* a future version.
|
|
144
|
+
*
|
|
145
|
+
* Derives the environment from `this.getBaseUrl()` (inherited from `BasePage`), which reads
|
|
146
|
+
* the `PORTAL_BASE_URL` environment variable.
|
|
147
|
+
*/
|
|
148
|
+
getGzacUrl() {
|
|
149
|
+
const baseUrl = this.getBaseUrl();
|
|
150
|
+
if (/klantportaal-zgw.denhaag.nl./.exec(baseUrl)) return gzacUrlProd;
|
|
151
|
+
if (/.acc./.exec(baseUrl)) return gzacUrlAcp;
|
|
152
|
+
if (/.test./.exec(baseUrl)) return gzacUrlTest;
|
|
153
|
+
else throw new Error("Cannot find current environment for baseUrl: " + baseUrl);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/auth/loginhandlers/adLoginHandler.ts
|
|
158
|
+
var ADLoginHandler = class {
|
|
159
|
+
targetUrl;
|
|
160
|
+
/**
|
|
161
|
+
* @param targetUrl URL to navigate to before logging in (the app behind the firewall),
|
|
162
|
+
* supplied by the consumer of this library
|
|
163
|
+
*/
|
|
164
|
+
constructor(targetUrl) {
|
|
165
|
+
this.targetUrl = targetUrl;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @param page the Playwright page to perform the login on
|
|
169
|
+
* @param account login details, supplied by the consumer of this library
|
|
170
|
+
* @param file path of the storage state file to write the session to
|
|
171
|
+
*/
|
|
172
|
+
async loginAndCreateSessionStorage(page, account, file) {
|
|
173
|
+
await new ADLoginPage(page).loginWithADAccountAndCreateSession(account, this.targetUrl, file);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/auth/utils/sessionFileHelper.ts
|
|
178
|
+
var sessionsDir = process$2.env.SESSIONS_DIR ?? path.resolve(process$2.cwd(), "sessions");
|
|
179
|
+
var environment = process$2.env.ENV ?? "test";
|
|
180
|
+
/**
|
|
181
|
+
* Easy way to create the filenames for the sessions
|
|
182
|
+
*/
|
|
183
|
+
var SessionFileHelper = class {
|
|
184
|
+
/**
|
|
185
|
+
* @param browser the browser instance the session file name is based on
|
|
186
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
187
|
+
*/
|
|
188
|
+
static getLocalhostFileName(browser, account) {
|
|
189
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @param browser the browser instance the session file name is based on
|
|
193
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
194
|
+
*/
|
|
195
|
+
static getLocalhostFileNameBedrijf(browser, account) {
|
|
196
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @param browser the browser instance the session file name is based on
|
|
200
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
201
|
+
*/
|
|
202
|
+
static getDigidFileName(browser, account) {
|
|
203
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-digid-${environment}-${account.username}.json`);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @param browser the browser instance the session file name is based on
|
|
207
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
208
|
+
*/
|
|
209
|
+
static getDigidGemachtigdeFileName(browser, account) {
|
|
210
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-digid-gemachtigde-${environment}-${account.username}.json`);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @param browser the browser instance the session file name is based on
|
|
214
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
215
|
+
*/
|
|
216
|
+
static getEHerkenningFileName(browser, account) {
|
|
217
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-${environment}-${account.username}.json`);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* @param browser the browser instance the session file name is based on
|
|
221
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
222
|
+
*/
|
|
223
|
+
static getEHerkenningVestigingFileName(browser, account) {
|
|
224
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-vestiging-${environment}-${account.username}.json`);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @param browser the browser instance the session file name is based on
|
|
228
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
229
|
+
*/
|
|
230
|
+
static getEHerkenningBewindvoerderFileName(browser, account) {
|
|
231
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-bewindvoerder-${environment}-${account.username}.json`);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @param browser the browser instance the session file name is based on
|
|
235
|
+
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
236
|
+
*/
|
|
237
|
+
static getADFileName(browser, account) {
|
|
238
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-ad-${environment}-${account.username}.json`);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
//#endregion
|
|
105
242
|
//#region src/auth/pages/digidLoginPage.ts
|
|
106
|
-
var DigidLoginPage = class extends
|
|
243
|
+
var DigidLoginPage = class extends BasePage {
|
|
107
244
|
constructor(page) {
|
|
108
245
|
super(page);
|
|
109
246
|
}
|
|
110
247
|
/**
|
|
111
248
|
* @param account login details, supplied by the consumer of this library
|
|
112
249
|
* @param fileName path of the storage state file to write the session to
|
|
250
|
+
* @param options the app's DigiD login button, and optionally where to start and its cookie
|
|
251
|
+
* banner, supplied by the consumer of this library
|
|
113
252
|
*/
|
|
114
|
-
async loginAndCreateNewSession(account, fileName) {
|
|
253
|
+
async loginAndCreateNewSession(account, fileName, options) {
|
|
254
|
+
const loginButton = options.loginButton(this.page);
|
|
255
|
+
const { startUrl } = options;
|
|
115
256
|
await test.step("Login with DigiD and create session", async () => {
|
|
116
|
-
await this.openPage();
|
|
257
|
+
await this.openPage(startUrl);
|
|
117
258
|
await this.handleAnySpecialADLoginScreen();
|
|
118
259
|
try {
|
|
119
|
-
await
|
|
260
|
+
await loginButton.click();
|
|
120
261
|
} catch (_error) {
|
|
121
|
-
await this.openPage();
|
|
262
|
+
await this.openPage(startUrl);
|
|
122
263
|
await this.handleAnySpecialADLoginScreen();
|
|
123
|
-
await
|
|
264
|
+
await loginButton.click();
|
|
124
265
|
}
|
|
125
266
|
if (!this.page.url().match(/authn/)) {
|
|
126
267
|
await this.loginWithDigid(account);
|
|
127
|
-
await this.
|
|
268
|
+
await this.acceptCookiesForApp(options);
|
|
128
269
|
}
|
|
129
270
|
await this.page.context().storageState({ path: fileName });
|
|
130
271
|
});
|
|
@@ -132,25 +273,35 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
132
273
|
/**
|
|
133
274
|
* @param account login details, supplied by the consumer of this library
|
|
134
275
|
* @param fileName path of the storage state file to write the session to
|
|
276
|
+
* @param options the app's DigiD machtigen login button, and optionally where to start and its cookie
|
|
277
|
+
* banner, supplied by the consumer of this library
|
|
135
278
|
*/
|
|
136
|
-
async loginAndCreateNewGemachtigdeSession(account, fileName) {
|
|
279
|
+
async loginAndCreateNewGemachtigdeSession(account, fileName, options) {
|
|
280
|
+
const loginButton = options.loginButton(this.page);
|
|
281
|
+
const { startUrl } = options;
|
|
137
282
|
await test.step("Login with DigiD as gemachtigde and create session", async () => {
|
|
138
|
-
await this.openPage();
|
|
283
|
+
await this.openPage(startUrl);
|
|
139
284
|
await this.handleAnySpecialADLoginScreen();
|
|
140
285
|
try {
|
|
141
|
-
await
|
|
286
|
+
await loginButton.click();
|
|
142
287
|
} catch (_error) {
|
|
143
|
-
await this.openPage();
|
|
144
|
-
await
|
|
288
|
+
await this.openPage(startUrl);
|
|
289
|
+
await loginButton.click();
|
|
145
290
|
}
|
|
146
291
|
await this.loginWithDigid(account, true);
|
|
147
|
-
await this.
|
|
292
|
+
await this.acceptCookiesForApp(options);
|
|
148
293
|
await this.page.context().storageState({ path: fileName });
|
|
149
294
|
});
|
|
150
295
|
}
|
|
151
296
|
/**
|
|
152
|
-
*
|
|
153
|
-
|
|
297
|
+
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
298
|
+
*/
|
|
299
|
+
async acceptCookiesForApp(options) {
|
|
300
|
+
if (options.cookieButton) await options.cookieButton(this.page).click();
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* When there is already an AD session, but for another environment, a special screen asks to
|
|
304
|
+
* confirm the account before you can continue.
|
|
154
305
|
*/
|
|
155
306
|
async handleAnySpecialADLoginScreen() {
|
|
156
307
|
try {
|
|
@@ -167,155 +318,192 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
167
318
|
await this.page.getByLabel("Inlogoptie 5 van 5: Inloggen").click();
|
|
168
319
|
await this.page.getByLabel("Testen betrouwbaarheidsniveau").selectOption("25");
|
|
169
320
|
await this.page.getByLabel("DigiD gebruikersnaam").fill(account.username);
|
|
170
|
-
await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "
|
|
321
|
+
await maskedFill(this.page.getByLabel("Wachtwoord", { exact: true }), account.password, "password");
|
|
171
322
|
const responsePromise = this.page.waitForResponse(/callback/, { timeout: 6e4 });
|
|
172
323
|
await this.page.getByRole("button", { name: "Inloggen" }).click();
|
|
173
324
|
if (gemachtigde) await this.page.getByRole("button", { name: "Kies" }).click();
|
|
174
325
|
return await responsePromise;
|
|
175
326
|
});
|
|
176
327
|
}
|
|
177
|
-
|
|
328
|
+
/**
|
|
329
|
+
* @param loginButton button that starts the DigiD machtigen login, supplied by the consumer of this library
|
|
330
|
+
*/
|
|
331
|
+
async loginAsDigidGemachtigde(loginButton) {
|
|
178
332
|
await test.step("Login as DigiD gemachtigde", async () => {
|
|
179
333
|
const gemachtigde = {
|
|
180
334
|
username: `${process$1.env.DIGID_GEMACHTIGDE_USER}`,
|
|
181
335
|
password: `${process$1.env.DIGID_GEMACHTIGDE_PASSWORD}`
|
|
182
336
|
};
|
|
183
|
-
await
|
|
337
|
+
await loginButton.click();
|
|
184
338
|
await this.loginWithDigid(gemachtigde, true);
|
|
185
339
|
});
|
|
186
340
|
}
|
|
187
341
|
};
|
|
188
342
|
//#endregion
|
|
189
|
-
//#region src/auth/loginhandlers/
|
|
190
|
-
var
|
|
343
|
+
//#region src/auth/loginhandlers/digidGemachtigdeLoginHandler.ts
|
|
344
|
+
var DigidGemachtigdeLoginHandler = class {
|
|
345
|
+
options;
|
|
346
|
+
/**
|
|
347
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
348
|
+
*
|
|
349
|
+
* @param options the app's DigiD machtigen login button (required), and optionally where to start and the
|
|
350
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
351
|
+
*/
|
|
352
|
+
constructor(options) {
|
|
353
|
+
this.options = options;
|
|
354
|
+
}
|
|
191
355
|
/**
|
|
192
356
|
* @param page the Playwright page to perform the login on
|
|
193
357
|
* @param account login details, supplied by the consumer of this library
|
|
194
358
|
* @param file path of the storage state file to write the session to
|
|
195
359
|
*/
|
|
196
360
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
197
|
-
await new DigidLoginPage(page).
|
|
361
|
+
await new DigidLoginPage(page).loginAndCreateNewGemachtigdeSession(account, file, this.options);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/auth/pages/baseLoginPage.ts
|
|
366
|
+
var BaseLoginPage = class extends BasePage {
|
|
367
|
+
constructor(page) {
|
|
368
|
+
super(page);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
372
|
+
*/
|
|
373
|
+
async acceptCookiesForApp(options) {
|
|
374
|
+
if (options.cookieButton) await options.cookieButton(this.page).click();
|
|
198
375
|
}
|
|
199
376
|
};
|
|
200
377
|
//#endregion
|
|
201
378
|
//#region src/auth/pages/eHerkenningLoginPage.ts
|
|
202
|
-
var EHerkenningLoginPage = class extends
|
|
379
|
+
var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
203
380
|
dropdownSelectIdentityProvider;
|
|
204
381
|
buttonConfirmIdentityProviderSelection;
|
|
205
382
|
textfieldUsername;
|
|
206
383
|
textfieldPassword;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
384
|
+
loginButton;
|
|
385
|
+
continueButton;
|
|
386
|
+
continueLink;
|
|
210
387
|
inputBsn;
|
|
211
|
-
|
|
388
|
+
searchButton;
|
|
212
389
|
constructor(page) {
|
|
213
390
|
super(page);
|
|
214
391
|
this.dropdownSelectIdentityProvider = page.locator("#identity_provider");
|
|
215
392
|
this.buttonConfirmIdentityProviderSelection = page.locator("//*[@name='commit']");
|
|
216
393
|
this.textfieldUsername = page.locator("#account_username");
|
|
217
394
|
this.textfieldPassword = page.locator("#account_password");
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
395
|
+
this.loginButton = page.getByRole("button", { name: /Inloggen|Log in/ });
|
|
396
|
+
this.continueButton = page.getByRole("button", { name: /Verder|Continue|Ga verder/ });
|
|
220
397
|
this.inputBsn = page.locator("#bsn-input");
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
398
|
+
this.searchButton = page.locator("#search-submit");
|
|
399
|
+
this.continueLink = page.getByRole("link", { name: /Verder|Continue|Ga verder/ });
|
|
223
400
|
}
|
|
224
401
|
/**
|
|
225
402
|
* @param account login details, supplied by the consumer of this library
|
|
226
403
|
*/
|
|
227
|
-
async
|
|
404
|
+
async tryLoginWithEHerkenning(account) {
|
|
228
405
|
await test.step("Fill eHerkenning credentials and submit", async () => {
|
|
229
406
|
await this.dropdownSelectIdentityProvider.selectOption("Digidentity AD 1.13 (preproduction)");
|
|
230
407
|
await this.page.locator("#remember").click();
|
|
231
408
|
await this.buttonConfirmIdentityProviderSelection.click();
|
|
232
409
|
await this.textfieldUsername.fill(account.username);
|
|
233
|
-
await this.
|
|
234
|
-
await maskedFill(this.textfieldPassword, account.password, "
|
|
235
|
-
await this.
|
|
410
|
+
await this.continueButton.click();
|
|
411
|
+
await maskedFill(this.textfieldPassword, account.password, "password");
|
|
412
|
+
await this.loginButton.click();
|
|
236
413
|
});
|
|
237
414
|
}
|
|
238
415
|
/**
|
|
239
416
|
* @param fileName path of the storage state file to write the session to
|
|
240
417
|
* @param account login details, supplied by the consumer of this library
|
|
418
|
+
* @param options
|
|
241
419
|
*/
|
|
242
|
-
async loginWithEHerkenningAndCreateSession(fileName, account) {
|
|
420
|
+
async loginWithEHerkenningAndCreateSession(fileName, account, options) {
|
|
243
421
|
await test.step("Login with eHerkenning and create session", async () => {
|
|
244
|
-
|
|
422
|
+
const loginButton = options.loginButton(this.page);
|
|
423
|
+
const { startUrl } = options;
|
|
424
|
+
await this.openPage(startUrl);
|
|
245
425
|
try {
|
|
246
|
-
await
|
|
426
|
+
await loginButton.click();
|
|
247
427
|
} catch (_error) {
|
|
248
428
|
await this.openPage();
|
|
249
|
-
await this.
|
|
429
|
+
await this.loginButton.click();
|
|
250
430
|
}
|
|
251
|
-
await this.loginWithEHerkenning(account);
|
|
431
|
+
await this.loginWithEHerkenning(account, options);
|
|
252
432
|
await this.page.context().storageState({ path: fileName });
|
|
253
433
|
});
|
|
254
434
|
}
|
|
255
435
|
/**
|
|
256
436
|
* @param account login details, supplied by the consumer of this library
|
|
437
|
+
* @param options
|
|
257
438
|
*/
|
|
258
|
-
async loginWithEHerkenning(account) {
|
|
259
|
-
await this.
|
|
439
|
+
async loginWithEHerkenning(account, options) {
|
|
440
|
+
await this.tryLoginWithEHerkenning(account);
|
|
260
441
|
await test.step("Confirm eHerkenning login and accept cookies", async () => {
|
|
261
442
|
await this.page.waitForTimeout(2e3);
|
|
262
|
-
if (await this.
|
|
263
|
-
await this.
|
|
443
|
+
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
444
|
+
await this.acceptCookiesForApp(options);
|
|
264
445
|
});
|
|
265
446
|
}
|
|
266
447
|
/**
|
|
267
448
|
* @param fileName path of the storage state file to write the session to
|
|
268
449
|
* @param account login details, supplied by the consumer of this library
|
|
450
|
+
* @param options
|
|
269
451
|
*/
|
|
270
|
-
async loginWithEHerkenningVestigingAndCreateSession(fileName, account) {
|
|
452
|
+
async loginWithEHerkenningVestigingAndCreateSession(fileName, account, options) {
|
|
271
453
|
await test.step("Login with eHerkenning vestiging and create session", async () => {
|
|
272
|
-
|
|
454
|
+
const loginButton = options.loginButton(this.page);
|
|
455
|
+
const { startUrl } = options;
|
|
456
|
+
await this.openPage(startUrl);
|
|
273
457
|
try {
|
|
274
|
-
await
|
|
458
|
+
await loginButton.click();
|
|
275
459
|
} catch (_error) {
|
|
276
460
|
await this.openPage();
|
|
277
|
-
await
|
|
461
|
+
await loginButton.click();
|
|
278
462
|
}
|
|
279
|
-
await this.loginWithEHerkenningVestiging(account);
|
|
463
|
+
await this.loginWithEHerkenningVestiging(account, options);
|
|
280
464
|
await this.page.context().storageState({ path: fileName });
|
|
281
465
|
});
|
|
282
466
|
}
|
|
283
467
|
/**
|
|
284
468
|
* @param account login details, supplied by the consumer of this library
|
|
469
|
+
* @param options
|
|
285
470
|
*/
|
|
286
|
-
async loginWithEHerkenningVestiging(account) {
|
|
287
|
-
await this.
|
|
471
|
+
async loginWithEHerkenningVestiging(account, options) {
|
|
472
|
+
await this.tryLoginWithEHerkenning(account);
|
|
288
473
|
await test.step("Confirm eHerkenning vestiging login and accept cookies", async () => {
|
|
289
474
|
await this.page.waitForTimeout(2e3);
|
|
290
|
-
if (await this.
|
|
291
|
-
await this.
|
|
475
|
+
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
476
|
+
await this.acceptCookiesForApp(options);
|
|
292
477
|
});
|
|
293
478
|
}
|
|
294
479
|
/**
|
|
295
480
|
* @param gemachtigde login details of the authorized representative (bewindvoerder), supplied by the consumer of this library
|
|
481
|
+
* @param options
|
|
296
482
|
* @param file optional path of the storage state file to write the session to
|
|
297
483
|
*/
|
|
298
|
-
async
|
|
484
|
+
async loginAsProfessionalBewindvoerder(gemachtigde, options, file) {
|
|
299
485
|
await test.step("Open bewindvoerder login option", async () => {
|
|
300
|
-
|
|
301
|
-
|
|
486
|
+
const loginButton = options.loginButton(this.page);
|
|
487
|
+
const { startUrl } = options;
|
|
488
|
+
await this.openPage(startUrl);
|
|
489
|
+
await loginButton.click();
|
|
302
490
|
});
|
|
303
491
|
await test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
304
492
|
try {
|
|
305
|
-
await this.
|
|
493
|
+
await this.tryLoginWithEHerkenning(gemachtigde);
|
|
306
494
|
} catch (_error) {
|
|
307
495
|
await this.openPage();
|
|
308
|
-
await this.
|
|
496
|
+
await this.tryLoginWithEHerkenning(gemachtigde);
|
|
309
497
|
}
|
|
310
498
|
});
|
|
311
499
|
await test.step("Search for client by BSN and accept cookies", async () => {
|
|
312
500
|
if (gemachtigde.bsn != null) {
|
|
313
|
-
await this.
|
|
501
|
+
await this.continueLink.click();
|
|
314
502
|
await maskedFill(this.inputBsn, gemachtigde.bsn, "bsn");
|
|
315
503
|
}
|
|
316
|
-
await this.
|
|
317
|
-
await this.
|
|
318
|
-
await this.
|
|
504
|
+
await this.searchButton.click();
|
|
505
|
+
await this.continueLink.click();
|
|
506
|
+
await this.acceptCookiesForApp(options);
|
|
319
507
|
});
|
|
320
508
|
if (file) await test.step("Save session state", async () => {
|
|
321
509
|
await this.page.context().storageState({ path: file });
|
|
@@ -323,273 +511,127 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
323
511
|
}
|
|
324
512
|
};
|
|
325
513
|
//#endregion
|
|
326
|
-
//#region src/auth/loginhandlers/
|
|
327
|
-
var
|
|
514
|
+
//#region src/auth/loginhandlers/digidLoginHandler.ts
|
|
515
|
+
var DigidLoginHandler = class {
|
|
516
|
+
options;
|
|
328
517
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
* @param
|
|
518
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
519
|
+
*
|
|
520
|
+
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
521
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
332
522
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
523
|
+
constructor(options) {
|
|
524
|
+
this.options = options;
|
|
335
525
|
}
|
|
336
|
-
};
|
|
337
|
-
//#endregion
|
|
338
|
-
//#region src/auth/loginhandlers/digidGemachtigdeLoginHandler.ts
|
|
339
|
-
var DigidGemachtigdeLoginHandler = class {
|
|
340
526
|
/**
|
|
341
527
|
* @param page the Playwright page to perform the login on
|
|
342
528
|
* @param account login details, supplied by the consumer of this library
|
|
343
529
|
* @param file path of the storage state file to write the session to
|
|
344
530
|
*/
|
|
345
531
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
346
|
-
await new DigidLoginPage(page).
|
|
532
|
+
await new DigidLoginPage(page).loginAndCreateNewSession(account, file, this.options);
|
|
347
533
|
}
|
|
348
534
|
};
|
|
349
535
|
//#endregion
|
|
350
536
|
//#region src/auth/loginhandlers/eHerkenningBewindvoerderLoginHandler.ts
|
|
351
537
|
var EHerkenningBewindvoerderLoginHandler = class {
|
|
538
|
+
options;
|
|
539
|
+
/**
|
|
540
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
541
|
+
*
|
|
542
|
+
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
543
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
544
|
+
*/
|
|
545
|
+
constructor(options) {
|
|
546
|
+
this.options = options;
|
|
547
|
+
}
|
|
352
548
|
/**
|
|
353
549
|
* @param page the Playwright page to perform the login on
|
|
354
550
|
* @param account login details, supplied by the consumer of this library
|
|
355
551
|
* @param file path of the storage state file to write the session to
|
|
356
552
|
*/
|
|
357
553
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
358
|
-
await new EHerkenningLoginPage(page).
|
|
554
|
+
await new EHerkenningLoginPage(page).loginAsProfessionalBewindvoerder(account, this.options, file);
|
|
359
555
|
}
|
|
360
556
|
};
|
|
361
557
|
//#endregion
|
|
362
|
-
//#region src/auth/
|
|
363
|
-
var
|
|
364
|
-
|
|
365
|
-
var gzacUrlTest = "https://alg-zgw.test.denhaag.nl";
|
|
366
|
-
function escapeRegExp(value) {
|
|
367
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
368
|
-
}
|
|
369
|
-
var ADLoginPage = class ADLoginPage extends BasePage {
|
|
370
|
-
gebruikersnaamInput;
|
|
371
|
-
wachtwoordInput;
|
|
372
|
-
volgendeInput;
|
|
373
|
-
aanmeldenInput;
|
|
374
|
-
kanAuthAppNietGebruikenLink;
|
|
375
|
-
gebruikVerificatieCode;
|
|
376
|
-
codeInput;
|
|
377
|
-
verifierenInput;
|
|
378
|
-
constructor(page) {
|
|
379
|
-
super(page);
|
|
380
|
-
this.gebruikersnaamInput = page.locator("//input[@type='email']");
|
|
381
|
-
this.wachtwoordInput = page.locator("//input[@name='passwd']");
|
|
382
|
-
this.volgendeInput = page.locator("//input[@type='submit']");
|
|
383
|
-
this.aanmeldenInput = page.locator("//input[@type='submit']");
|
|
384
|
-
this.kanAuthAppNietGebruikenLink = page.locator("//*[@id='signInAnotherWay']");
|
|
385
|
-
this.gebruikVerificatieCode = page.getByText(/Gebruik een verificatiecode|Use a verification code/);
|
|
386
|
-
this.codeInput = page.locator("//input[@name='otc']");
|
|
387
|
-
this.verifierenInput = page.locator("//input[@type='submit']");
|
|
388
|
-
}
|
|
389
|
-
async openPage(path) {
|
|
390
|
-
await this.page.goto(path);
|
|
391
|
-
}
|
|
558
|
+
//#region src/auth/loginhandlers/eHerkenningLoginHandler.ts
|
|
559
|
+
var EHerkenningLoginHandler = class {
|
|
560
|
+
options;
|
|
392
561
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
* @param account login details, supplied by the consumer of this library
|
|
396
|
-
* @param targetUrl URL to navigate to before logging in (the app behind the firewall),
|
|
397
|
-
* supplied by the consumer of this library — not every consumer has a GZAC account, so
|
|
398
|
-
* this library no longer assumes GZAC as the destination. The consumer is responsible
|
|
399
|
-
* for switching between environments (e.g. test/acc/prod) when building this URL; this
|
|
400
|
-
* library does not do that for you.
|
|
401
|
-
* @param fileName path of the storage state file to write the session to
|
|
402
|
-
*
|
|
403
|
-
* @example
|
|
404
|
-
* // consumer-side lookup, e.g. based on an `ENV` environment variable
|
|
405
|
-
* export const TARGET_URL_BY_ENVIRONMENT = {
|
|
406
|
-
* test: 'https://alg-zgw.test.denhaag.nl/',
|
|
407
|
-
* acc: 'https://alg-zgw.acc.denhaag.nl/',
|
|
408
|
-
* prod: 'https://alg-zgw.denhaag.nl/',
|
|
409
|
-
* } as const;
|
|
562
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
410
563
|
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
564
|
+
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
565
|
+
* app's cookie banner, supplied by the consumer of this library
|
|
413
566
|
*/
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
let targetOrigin;
|
|
417
|
-
try {
|
|
418
|
-
targetOrigin = new URL(targetUrl).origin;
|
|
419
|
-
} catch {
|
|
420
|
-
throw new Error(`AD login failed: targetUrl must be an absolute URL (e.g. "https://app.denhaag.nl/..."), got "${targetUrl}"`);
|
|
421
|
-
}
|
|
422
|
-
const isOnTargetApp = async () => this.page.waitForLoadState("networkidle").then(() => this.page.url().startsWith(targetOrigin), () => false);
|
|
423
|
-
let cachedAccountUsed = false;
|
|
424
|
-
let alreadyFullyAuthenticated = false;
|
|
425
|
-
await test.step("Fill AD username and submit", async () => {
|
|
426
|
-
await this.page.goto(targetUrl);
|
|
427
|
-
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
428
|
-
if (alreadyFullyAuthenticated) return;
|
|
429
|
-
const cachedAccountTile = this.page.getByRole("button", { name: new RegExp(escapeRegExp(account.username), "i") });
|
|
430
|
-
await cachedAccountTile.or(adLoginPage.gebruikersnaamInput).waitFor({
|
|
431
|
-
state: "visible",
|
|
432
|
-
timeout: 1e4
|
|
433
|
-
}).catch(() => {});
|
|
434
|
-
cachedAccountUsed = await cachedAccountTile.isVisible().catch(() => false);
|
|
435
|
-
if (cachedAccountUsed) {
|
|
436
|
-
await cachedAccountTile.click();
|
|
437
|
-
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
438
|
-
} else {
|
|
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
|
-
});
|
|
445
|
-
let sessionWasStale = false;
|
|
446
|
-
if (!alreadyFullyAuthenticated) {
|
|
447
|
-
await test.step("Fill AD password and submit", async () => {
|
|
448
|
-
if (!cachedAccountUsed) {
|
|
449
|
-
await maskedFill(adLoginPage.wachtwoordInput, account.password, "wachtwoord");
|
|
450
|
-
await adLoginPage.aanmeldenInput.click();
|
|
451
|
-
await this.page.waitForTimeout(1e3);
|
|
452
|
-
}
|
|
453
|
-
sessionWasStale = await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible().catch(() => false);
|
|
454
|
-
});
|
|
455
|
-
await test.step("Complete MFA via TOTP", async () => {
|
|
456
|
-
if (!sessionWasStale) await adLoginPage.kanAuthAppNietGebruikenLink.click();
|
|
457
|
-
await adLoginPage.gebruikVerificatieCode.click();
|
|
458
|
-
const token = await TOTP.generate(`${process.env.AD_SECRET}`);
|
|
459
|
-
await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
|
|
460
|
-
await adLoginPage.verifierenInput.click();
|
|
461
|
-
await adLoginPage.page.waitForTimeout(5e3);
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
await test.step("Save session state", async () => {
|
|
465
|
-
await adLoginPage.page.context().storageState({ path: fileName });
|
|
466
|
-
});
|
|
567
|
+
constructor(options) {
|
|
568
|
+
this.options = options;
|
|
467
569
|
}
|
|
468
570
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
* @
|
|
472
|
-
* target URL to {@link loginWithADAccountAndCreateSession} instead. Kept only so existing
|
|
473
|
-
* GZAC consumers can still derive this URL themselves during migration; will be removed in
|
|
474
|
-
* a future version.
|
|
475
|
-
*
|
|
476
|
-
* Derives the environment from `this.getBaseUrl()` (inherited from `BasePage`), which reads
|
|
477
|
-
* the `PORTAL_BASE_URL` environment variable.
|
|
571
|
+
* @param page the Playwright page to perform the login on
|
|
572
|
+
* @param account login details, supplied by the consumer of this library
|
|
573
|
+
* @param file path of the storage state file to write the session to
|
|
478
574
|
*/
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if (/klantportaal-zgw.denhaag.nl./.exec(baseUrl)) return gzacUrlProd;
|
|
482
|
-
if (/.acc./.exec(baseUrl)) return gzacUrlAcp;
|
|
483
|
-
if (/.test./.exec(baseUrl)) return gzacUrlTest;
|
|
484
|
-
else throw new Error("Cannot find current environment for baseUrl: " + baseUrl);
|
|
575
|
+
async loginAndCreateSessionStorage(page, account, file) {
|
|
576
|
+
await new EHerkenningLoginPage(page).loginWithEHerkenningVestigingAndCreateSession(file, account, this.options);
|
|
485
577
|
}
|
|
486
578
|
};
|
|
487
579
|
//#endregion
|
|
488
|
-
//#region src/auth/loginhandlers/
|
|
489
|
-
var
|
|
490
|
-
targetUrl;
|
|
491
|
-
/**
|
|
492
|
-
* @param targetUrl URL to navigate to before logging in (the app behind the firewall),
|
|
493
|
-
* supplied by the consumer of this library
|
|
494
|
-
*/
|
|
495
|
-
constructor(targetUrl) {
|
|
496
|
-
this.targetUrl = targetUrl;
|
|
497
|
-
}
|
|
580
|
+
//#region src/auth/loginhandlers/localhostLoginHandler.ts
|
|
581
|
+
var LocalhostLoginHandler = class {
|
|
498
582
|
/**
|
|
499
583
|
* @param page the Playwright page to perform the login on
|
|
500
584
|
* @param account login details, supplied by the consumer of this library
|
|
501
585
|
* @param file path of the storage state file to write the session to
|
|
502
586
|
*/
|
|
503
587
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
504
|
-
await new
|
|
588
|
+
await new LocalLoginPage(page).loginAndCreateNewSession(account, file);
|
|
505
589
|
}
|
|
506
590
|
};
|
|
507
591
|
//#endregion
|
|
508
592
|
//#region src/auth/getLoginHandler.ts
|
|
509
593
|
/**
|
|
594
|
+
* Shortcut for creating the login handler for an auth type. Creating the handler directly, e.g.
|
|
595
|
+
* `new DigidLoginHandler(options)`, checks at compile time that the required options are there;
|
|
596
|
+
* this function checks at runtime.
|
|
597
|
+
*
|
|
510
598
|
* @param authType type of login
|
|
511
|
-
* @param
|
|
512
|
-
* app behind the firewall
|
|
513
|
-
* `
|
|
599
|
+
* @param options where to start the login, supplied by the consumer of this library.
|
|
600
|
+
* - `ad-session`: `startUrl` is required - the app behind the firewall to navigate to before logging in.
|
|
601
|
+
* - `digid` / `digid_gemachtigde`: `loginButton` is required - the app's DigiD button. `startUrl` defaults
|
|
602
|
+
* to `PORTAL_BASE_URL`; `cookieButton` is optional.
|
|
603
|
+
* - other auth types: ignored.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* getLoginHandler('digid', {
|
|
607
|
+
* startUrl: 'https://openformulieren-zgw.acc.denhaag.nl/<form>/startpagina',
|
|
608
|
+
* loginButton: (page) => page.getByRole('link', { name: 'Inloggen met DigiD' }),
|
|
609
|
+
* cookieButton: (page) => page.locator('button[class*="cookie-notice__accept"]'),
|
|
610
|
+
* });
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* getLoginHandler('ad-session', { startUrl: 'https://alg-zgw.test.denhaag.nl/' });
|
|
514
614
|
*/
|
|
515
|
-
function getLoginHandler(authType,
|
|
615
|
+
function getLoginHandler(authType, options = {}) {
|
|
516
616
|
switch (authType) {
|
|
517
|
-
case "digid": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new DigidLoginHandler();
|
|
518
|
-
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler();
|
|
519
|
-
case "eherkenning": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new EHerkenningLoginHandler();
|
|
520
|
-
case "eherkenning_vestiging": return new EHerkenningLoginHandler();
|
|
521
|
-
case "eherkenning_bewindvoerder": return new EHerkenningBewindvoerderLoginHandler();
|
|
617
|
+
case "digid": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new DigidLoginHandler(loginOptions(authType, options));
|
|
618
|
+
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler(loginOptions(authType, options));
|
|
619
|
+
case "eherkenning": return isRunningOnLocalhost() ? new LocalhostLoginHandler() : new EHerkenningLoginHandler(loginOptions(authType, options));
|
|
620
|
+
case "eherkenning_vestiging": return new EHerkenningLoginHandler(loginOptions(authType, options));
|
|
621
|
+
case "eherkenning_bewindvoerder": return new EHerkenningBewindvoerderLoginHandler(loginOptions(authType, options));
|
|
522
622
|
case "ad-session":
|
|
523
|
-
if (!
|
|
524
|
-
return new ADLoginHandler(
|
|
623
|
+
if (!options.startUrl) throw new Error("startUrl is required when authType is 'ad-session'");
|
|
624
|
+
return new ADLoginHandler(options.startUrl);
|
|
525
625
|
default: throw new Error(`Unsupported auth type: ${authType}. If needed please create a new LoginHandler and register it here in getLoginHandler().`);
|
|
526
626
|
}
|
|
527
627
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
var SessionFileHelper = class {
|
|
536
|
-
/**
|
|
537
|
-
* @param browser the browser instance the session file name is based on
|
|
538
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
539
|
-
*/
|
|
540
|
-
static getLocalhostFileName(browser, account) {
|
|
541
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* @param browser the browser instance the session file name is based on
|
|
545
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
546
|
-
*/
|
|
547
|
-
static getLocalhostFileNameBedrijf(browser, account) {
|
|
548
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* @param browser the browser instance the session file name is based on
|
|
552
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
553
|
-
*/
|
|
554
|
-
static getDigidFileName(browser, account) {
|
|
555
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-digid-${environment}-${account.username}.json`);
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* @param browser the browser instance the session file name is based on
|
|
559
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
560
|
-
*/
|
|
561
|
-
static getDigidGemachtigdeFileName(browser, account) {
|
|
562
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-digid-gemachtigde-${environment}-${account.username}.json`);
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* @param browser the browser instance the session file name is based on
|
|
566
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
567
|
-
*/
|
|
568
|
-
static getEHerkenningFileName(browser, account) {
|
|
569
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-${environment}-${account.username}.json`);
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* @param browser the browser instance the session file name is based on
|
|
573
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
574
|
-
*/
|
|
575
|
-
static getEHerkenningVestigingFileName(browser, account) {
|
|
576
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-vestiging-${environment}-${account.username}.json`);
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* @param browser the browser instance the session file name is based on
|
|
580
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
581
|
-
*/
|
|
582
|
-
static getEHerkenningBewindvoerderFileName(browser, account) {
|
|
583
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-bewindvoerder-${environment}-${account.username}.json`);
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* @param browser the browser instance the session file name is based on
|
|
587
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
588
|
-
*/
|
|
589
|
-
static getADFileName(browser, account) {
|
|
590
|
-
return path.join(sessionsDir, `${browser.browserType().name()}-ad-${environment}-${account.username}.json`);
|
|
591
|
-
}
|
|
592
|
-
};
|
|
628
|
+
function loginOptions(authType, options) {
|
|
629
|
+
if (!options.loginButton) throw new Error(`loginButton is required when authType is '${authType}'`);
|
|
630
|
+
return {
|
|
631
|
+
...options,
|
|
632
|
+
loginButton: options.loginButton
|
|
633
|
+
};
|
|
634
|
+
}
|
|
593
635
|
//#endregion
|
|
594
636
|
//#region src/auth/sessionHandler.ts
|
|
595
637
|
var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
@@ -725,13 +767,25 @@ function getApiTokenFromSession(baseTest, handler) {
|
|
|
725
767
|
//#endregion
|
|
726
768
|
//#region src/auth/getSessionHandler.ts
|
|
727
769
|
/**
|
|
728
|
-
* @param testProfile
|
|
729
|
-
* @param
|
|
730
|
-
*
|
|
731
|
-
*
|
|
770
|
+
* @param testProfile the test user to log in
|
|
771
|
+
* @param loginOptionsWithButtons with the login button and the accept cookiebutton if necessary
|
|
772
|
+
* @param loginHandler the login handler for the app the user logs in to, with that app's options, e.g.
|
|
773
|
+
* `new DigidLoginHandler({ loginButton, ... })` or `getLoginHandler(authType, options)`. Required for
|
|
774
|
+
* auth types that need options (`ad-session`, `digid`, `digid_gemachtigde`); left out, the handler
|
|
775
|
+
* for `testProfile.authType` is created without options.
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* // once per app
|
|
779
|
+
* export const openFormsDigid = new DigidLoginHandler({
|
|
780
|
+
* startUrl: 'https://openformulieren-zgw.acc.denhaag.nl/<form>/startpagina',
|
|
781
|
+
* loginButton: (page) => page.getByRole('link', { name: 'Inloggen met DigiD' }),
|
|
782
|
+
* cookieButton: (page) => page.locator('button[class*="cookie-notice__accept"]'),
|
|
783
|
+
* });
|
|
784
|
+
*
|
|
785
|
+
* getSessionHandler(digidUser1, openFormsDigid);
|
|
732
786
|
*/
|
|
733
|
-
function getSessionHandler(testProfile,
|
|
734
|
-
return createSessionHandler(testProfile.authType, testProfile.account, getLoginHandler(testProfile.authType,
|
|
787
|
+
function getSessionHandler(testProfile, loginOptionsWithButtons, loginHandler) {
|
|
788
|
+
return createSessionHandler(testProfile.authType, testProfile.account, loginHandler ?? getLoginHandler(testProfile.authType, loginOptionsWithButtons));
|
|
735
789
|
}
|
|
736
790
|
//#endregion
|
|
737
|
-
export { ADLoginHandler, ADLoginPage, DigidGemachtigdeLoginHandler, DigidLoginHandler, DigidLoginPage, EHerkenningBewindvoerderLoginHandler, EHerkenningLoginHandler, EHerkenningLoginPage, LocalhostLoginHandler,
|
|
791
|
+
export { ADLoginHandler, ADLoginPage, BaseLoginPage, DigidGemachtigdeLoginHandler, DigidLoginHandler, DigidLoginPage, EHerkenningBewindvoerderLoginHandler, EHerkenningLoginHandler, EHerkenningLoginPage, LocalhostLoginHandler, MAX_SESSION_TIME_IN_MINUTES, SessionFileHelper, createSessionHandler, getApiTokenFromSession, getLoginHandler, getSessionHandler, maskedFill };
|