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