dh-auth-library 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/getLoginHandler.d.ts +2 -2
- package/dist/auth/getSessionHandler.d.ts +4 -2
- package/dist/auth/loginhandlers/digidGemachtigdeLoginHandler.d.ts +1 -1
- package/dist/auth/loginhandlers/digidLoginHandler.d.ts +1 -1
- package/dist/auth/loginhandlers/eHerkenningBewindvoerderLoginHandler.d.ts +9 -0
- package/dist/auth/loginhandlers/eHerkenningLoginHandler.d.ts +9 -0
- package/dist/auth/pages/baseLoginPage.d.ts +25 -0
- package/dist/auth/pages/digidLoginPage.d.ts +3 -3
- package/dist/auth/pages/eHerkenningLoginPage.d.ts +12 -7
- package/dist/auth/pages/index.d.ts +1 -1
- package/dist/auth/sessionHandler.d.ts +1 -1
- package/dist/index.cjs.js +307 -361
- package/dist/index.es.js +308 -362
- package/package.json +1 -1
- package/dist/auth/pages/loginOverzichtPage.d.ts +0 -71
package/dist/index.cjs.js
CHANGED
|
@@ -23,122 +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
|
-
digidLoginButton;
|
|
46
|
-
digidMachtigenLoginButton;
|
|
47
|
-
eHerkenningLoginButton;
|
|
48
|
-
eHerkenningMachtigingLoginButton;
|
|
49
|
-
klantportaalCookieButton;
|
|
50
|
-
constructor(page) {
|
|
51
|
-
super(page);
|
|
52
|
-
this.digidLoginButton = page.locator("#oidc-digid");
|
|
53
|
-
this.digidMachtigenLoginButton = page.locator("#digid-machtigen");
|
|
54
|
-
this.eHerkenningLoginButton = page.locator("#oidc-eHerkenning");
|
|
55
|
-
this.eHerkenningMachtigingLoginButton = page.locator("#eherkenning-bewindvoering");
|
|
56
|
-
this.klantportaalCookieButton = page.locator("#ppms_cm_agree-to-all");
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Clicks the button that starts the login flow. Not every consumer has the login overzicht
|
|
60
|
-
* page (e.g. Open Forms), so the button to click can be supplied by the consumer.
|
|
61
|
-
*
|
|
62
|
-
* @param loginButton the button that starts the login flow
|
|
63
|
-
*/
|
|
64
|
-
async clickLoginButton(loginButton) {
|
|
65
|
-
await loginButton.waitFor();
|
|
66
|
-
await this.page.waitForTimeout(2e3);
|
|
67
|
-
await loginButton.click();
|
|
68
|
-
}
|
|
69
|
-
async clickDigidLoginOption() {
|
|
70
|
-
await this.clickLoginButton(this.digidLoginButton);
|
|
71
|
-
}
|
|
72
|
-
async clickDigidMachtigenLoginOption() {
|
|
73
|
-
await this.clickLoginButton(this.digidMachtigenLoginButton);
|
|
74
|
-
}
|
|
75
|
-
async clickEHerkenningLoginOption() {
|
|
76
|
-
await this.eHerkenningLoginButton.waitFor();
|
|
77
|
-
await this.page.waitForTimeout(2e3);
|
|
78
|
-
try {
|
|
79
|
-
await this.eHerkenningLoginButton.click();
|
|
80
|
-
} catch (_error) {
|
|
81
|
-
await this.reloadPage();
|
|
82
|
-
await this.eHerkenningLoginButton.waitFor();
|
|
83
|
-
await this.page.waitForTimeout(2e3);
|
|
84
|
-
await this.eHerkenningLoginButton.click();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async clickProfessionalBewindvoerderLoginOption() {
|
|
88
|
-
await this.eHerkenningMachtigingLoginButton.waitFor();
|
|
89
|
-
await this.page.waitForTimeout(2e3);
|
|
90
|
-
try {
|
|
91
|
-
await this.eHerkenningMachtigingLoginButton.click();
|
|
92
|
-
} catch (_error) {
|
|
93
|
-
await this.reloadPage();
|
|
94
|
-
await this.eHerkenningMachtigingLoginButton.waitFor();
|
|
95
|
-
await this.page.waitForTimeout(2e3);
|
|
96
|
-
await this.eHerkenningMachtigingLoginButton.click();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async verifyLoginOverviewIsVisible() {
|
|
100
|
-
await (0, _playwright_test.expect)(this.page.getByRole("heading", { name: "Inloggen voor mijzelf" })).toBeVisible();
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Accepts the cookie banner and waits until the consent is stored in a cookie; skipped when the
|
|
104
|
-
* banner doesn't show within 10 seconds.
|
|
105
|
-
*
|
|
106
|
-
* @param cookieButton the button that accepts the cookie banner, defaults to the klantportaal banner
|
|
107
|
-
*/
|
|
108
|
-
async acceptCookies(cookieButton = this.klantportaalCookieButton) {
|
|
109
|
-
try {
|
|
110
|
-
const cookiesBeforeAccepting = await this.cookiesAsText();
|
|
111
|
-
await cookieButton.click({ timeout: 1e4 });
|
|
112
|
-
await this.waitForCookiesToSettle(cookiesBeforeAccepting);
|
|
113
|
-
} catch (_ignore) {}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Waits until the cookies differ from `cookiesBefore` and have not changed for a second, at most 10 seconds.
|
|
117
|
-
*/
|
|
118
|
-
async waitForCookiesToSettle(cookiesBefore) {
|
|
119
|
-
const settledAfterMs = 1e3;
|
|
120
|
-
const deadline = Date.now() + 1e4;
|
|
121
|
-
let current = cookiesBefore;
|
|
122
|
-
let changedAt = Date.now();
|
|
123
|
-
while (Date.now() < deadline) {
|
|
124
|
-
await this.page.waitForTimeout(250);
|
|
125
|
-
const cookies = await this.cookiesAsText();
|
|
126
|
-
if (cookies !== current) {
|
|
127
|
-
current = cookies;
|
|
128
|
-
changedAt = Date.now();
|
|
129
|
-
} else if (current !== cookiesBefore && Date.now() - changedAt >= settledAfterMs) return;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async cookiesAsText() {
|
|
133
|
-
return (await this.page.context().cookies()).map((c) => `${c.domain}|${c.name}=${c.value}`).sort().join(";");
|
|
134
|
-
}
|
|
135
|
-
async reloadPage() {
|
|
136
|
-
try {
|
|
137
|
-
await this.page.reload();
|
|
138
|
-
} catch (_error) {}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
//#endregion
|
|
142
31
|
//#region src/auth/utils/maskedFill.ts
|
|
143
32
|
function isEnvValue(value) {
|
|
144
33
|
return value !== "" && Object.values(process.env).includes(value);
|
|
@@ -163,8 +52,219 @@ async function maskedFill(locator, value, propertyName, forceMask = false) {
|
|
|
163
52
|
});
|
|
164
53
|
}
|
|
165
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
|
|
166
266
|
//#region src/auth/pages/digidLoginPage.ts
|
|
167
|
-
var DigidLoginPage = class extends
|
|
267
|
+
var DigidLoginPage = class extends nl_portal_playwright_libraries.BasePage {
|
|
168
268
|
constructor(page) {
|
|
169
269
|
super(page);
|
|
170
270
|
}
|
|
@@ -181,11 +281,11 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
181
281
|
await this.openPage(startUrl);
|
|
182
282
|
await this.handleAnySpecialADLoginScreen();
|
|
183
283
|
try {
|
|
184
|
-
await
|
|
284
|
+
await loginButton.click();
|
|
185
285
|
} catch (_error) {
|
|
186
286
|
await this.openPage(startUrl);
|
|
187
287
|
await this.handleAnySpecialADLoginScreen();
|
|
188
|
-
await
|
|
288
|
+
await loginButton.click();
|
|
189
289
|
}
|
|
190
290
|
if (!this.page.url().match(/authn/)) {
|
|
191
291
|
await this.loginWithDigid(account);
|
|
@@ -207,10 +307,10 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
207
307
|
await this.openPage(startUrl);
|
|
208
308
|
await this.handleAnySpecialADLoginScreen();
|
|
209
309
|
try {
|
|
210
|
-
await
|
|
310
|
+
await loginButton.click();
|
|
211
311
|
} catch (_error) {
|
|
212
312
|
await this.openPage(startUrl);
|
|
213
|
-
await
|
|
313
|
+
await loginButton.click();
|
|
214
314
|
}
|
|
215
315
|
await this.loginWithDigid(account, true);
|
|
216
316
|
await this.acceptCookiesForApp(options);
|
|
@@ -221,7 +321,7 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
221
321
|
* Accepts the app's cookie banner when the consumer supplied one, so the consent is in the saved session.
|
|
222
322
|
*/
|
|
223
323
|
async acceptCookiesForApp(options) {
|
|
224
|
-
if (options.cookieButton) await
|
|
324
|
+
if (options.cookieButton) await options.cookieButton(this.page).click();
|
|
225
325
|
}
|
|
226
326
|
/**
|
|
227
327
|
* When there is already an AD session, but for another environment, a special screen asks to
|
|
@@ -258,19 +358,19 @@ var DigidLoginPage = class extends LoginOverzichtPage {
|
|
|
258
358
|
username: `${node_process.default.env.DIGID_GEMACHTIGDE_USER}`,
|
|
259
359
|
password: `${node_process.default.env.DIGID_GEMACHTIGDE_PASSWORD}`
|
|
260
360
|
};
|
|
261
|
-
await
|
|
361
|
+
await loginButton.click();
|
|
262
362
|
await this.loginWithDigid(gemachtigde, true);
|
|
263
363
|
});
|
|
264
364
|
}
|
|
265
365
|
};
|
|
266
366
|
//#endregion
|
|
267
|
-
//#region src/auth/loginhandlers/
|
|
268
|
-
var
|
|
367
|
+
//#region src/auth/loginhandlers/digidGemachtigdeLoginHandler.ts
|
|
368
|
+
var DigidGemachtigdeLoginHandler = class {
|
|
269
369
|
options;
|
|
270
370
|
/**
|
|
271
371
|
* Create one per app, so every test user that logs in to that app shares its options.
|
|
272
372
|
*
|
|
273
|
-
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
373
|
+
* @param options the app's DigiD machtigen login button (required), and optionally where to start and the
|
|
274
374
|
* app's cookie banner, supplied by the consumer of this library
|
|
275
375
|
*/
|
|
276
376
|
constructor(options) {
|
|
@@ -282,12 +382,25 @@ var DigidLoginHandler = class {
|
|
|
282
382
|
* @param file path of the storage state file to write the session to
|
|
283
383
|
*/
|
|
284
384
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
285
|
-
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();
|
|
286
399
|
}
|
|
287
400
|
};
|
|
288
401
|
//#endregion
|
|
289
402
|
//#region src/auth/pages/eHerkenningLoginPage.ts
|
|
290
|
-
var EHerkenningLoginPage = class extends
|
|
403
|
+
var EHerkenningLoginPage = class extends BaseLoginPage {
|
|
291
404
|
dropdownSelectIdentityProvider;
|
|
292
405
|
buttonConfirmIdentityProviderSelection;
|
|
293
406
|
textfieldUsername;
|
|
@@ -326,67 +439,78 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
326
439
|
/**
|
|
327
440
|
* @param fileName path of the storage state file to write the session to
|
|
328
441
|
* @param account login details, supplied by the consumer of this library
|
|
442
|
+
* @param options
|
|
329
443
|
*/
|
|
330
|
-
async loginWithEHerkenningAndCreateSession(fileName, account) {
|
|
444
|
+
async loginWithEHerkenningAndCreateSession(fileName, account, options) {
|
|
331
445
|
await _playwright_test.test.step("Login with eHerkenning and create session", async () => {
|
|
332
|
-
|
|
446
|
+
const loginButton = options.loginButton(this.page);
|
|
447
|
+
const { startUrl } = options;
|
|
448
|
+
await this.openPage(startUrl);
|
|
333
449
|
try {
|
|
334
|
-
await
|
|
450
|
+
await loginButton.click();
|
|
335
451
|
} catch (_error) {
|
|
336
452
|
await this.openPage();
|
|
337
|
-
await this.
|
|
453
|
+
await this.loginButton.click();
|
|
338
454
|
}
|
|
339
|
-
await this.loginWithEHerkenning(account);
|
|
455
|
+
await this.loginWithEHerkenning(account, options);
|
|
340
456
|
await this.page.context().storageState({ path: fileName });
|
|
341
457
|
});
|
|
342
458
|
}
|
|
343
459
|
/**
|
|
344
460
|
* @param account login details, supplied by the consumer of this library
|
|
461
|
+
* @param options
|
|
345
462
|
*/
|
|
346
|
-
async loginWithEHerkenning(account) {
|
|
463
|
+
async loginWithEHerkenning(account, options) {
|
|
347
464
|
await this.tryLoginWithEHerkenning(account);
|
|
348
465
|
await _playwright_test.test.step("Confirm eHerkenning login and accept cookies", async () => {
|
|
349
466
|
await this.page.waitForTimeout(2e3);
|
|
350
467
|
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
351
|
-
await this.
|
|
468
|
+
await this.acceptCookiesForApp(options);
|
|
352
469
|
});
|
|
353
470
|
}
|
|
354
471
|
/**
|
|
355
472
|
* @param fileName path of the storage state file to write the session to
|
|
356
473
|
* @param account login details, supplied by the consumer of this library
|
|
474
|
+
* @param options
|
|
357
475
|
*/
|
|
358
|
-
async loginWithEHerkenningVestigingAndCreateSession(fileName, account) {
|
|
476
|
+
async loginWithEHerkenningVestigingAndCreateSession(fileName, account, options) {
|
|
359
477
|
await _playwright_test.test.step("Login with eHerkenning vestiging and create session", async () => {
|
|
360
|
-
|
|
478
|
+
const loginButton = options.loginButton(this.page);
|
|
479
|
+
const { startUrl } = options;
|
|
480
|
+
await this.openPage(startUrl);
|
|
361
481
|
try {
|
|
362
|
-
await
|
|
482
|
+
await loginButton.click();
|
|
363
483
|
} catch (_error) {
|
|
364
484
|
await this.openPage();
|
|
365
|
-
await
|
|
485
|
+
await loginButton.click();
|
|
366
486
|
}
|
|
367
|
-
await this.loginWithEHerkenningVestiging(account);
|
|
487
|
+
await this.loginWithEHerkenningVestiging(account, options);
|
|
368
488
|
await this.page.context().storageState({ path: fileName });
|
|
369
489
|
});
|
|
370
490
|
}
|
|
371
491
|
/**
|
|
372
492
|
* @param account login details, supplied by the consumer of this library
|
|
493
|
+
* @param options
|
|
373
494
|
*/
|
|
374
|
-
async loginWithEHerkenningVestiging(account) {
|
|
495
|
+
async loginWithEHerkenningVestiging(account, options) {
|
|
375
496
|
await this.tryLoginWithEHerkenning(account);
|
|
376
497
|
await _playwright_test.test.step("Confirm eHerkenning vestiging login and accept cookies", async () => {
|
|
377
498
|
await this.page.waitForTimeout(2e3);
|
|
378
499
|
if (await this.continueButton.isVisible()) await this.continueButton.click();
|
|
379
|
-
await this.
|
|
500
|
+
await this.acceptCookiesForApp(options);
|
|
380
501
|
});
|
|
381
502
|
}
|
|
382
503
|
/**
|
|
383
504
|
* @param gemachtigde login details of the authorized representative (bewindvoerder), supplied by the consumer of this library
|
|
505
|
+
* @param options
|
|
384
506
|
* @param file optional path of the storage state file to write the session to
|
|
385
507
|
*/
|
|
386
|
-
async loginAsProfessionalBewindvoerder(gemachtigde, file) {
|
|
508
|
+
async loginAsProfessionalBewindvoerder(gemachtigde, options, file) {
|
|
387
509
|
await _playwright_test.test.step("Open bewindvoerder login option", async () => {
|
|
388
|
-
|
|
389
|
-
|
|
510
|
+
const loginButton = options.loginButton(this.page);
|
|
511
|
+
const { startUrl } = options;
|
|
512
|
+
await this.openPage(startUrl);
|
|
513
|
+
await loginButton.click();
|
|
390
514
|
});
|
|
391
515
|
await _playwright_test.test.step("Login with eHerkenning credentials as bewindvoerder", async () => {
|
|
392
516
|
try {
|
|
@@ -403,7 +527,7 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
403
527
|
}
|
|
404
528
|
await this.searchButton.click();
|
|
405
529
|
await this.continueLink.click();
|
|
406
|
-
await this.
|
|
530
|
+
await this.acceptCookiesForApp(options);
|
|
407
531
|
});
|
|
408
532
|
if (file) await _playwright_test.test.step("Save session state", async () => {
|
|
409
533
|
await this.page.context().storageState({ path: file });
|
|
@@ -411,25 +535,13 @@ var EHerkenningLoginPage = class extends LoginOverzichtPage {
|
|
|
411
535
|
}
|
|
412
536
|
};
|
|
413
537
|
//#endregion
|
|
414
|
-
//#region src/auth/loginhandlers/
|
|
415
|
-
var
|
|
416
|
-
/**
|
|
417
|
-
* @param page the Playwright page to perform the login on
|
|
418
|
-
* @param account login details, supplied by the consumer of this library
|
|
419
|
-
* @param file path of the storage state file to write the session to
|
|
420
|
-
*/
|
|
421
|
-
async loginAndCreateSessionStorage(page, account, file) {
|
|
422
|
-
await new EHerkenningLoginPage(page).loginWithEHerkenningVestigingAndCreateSession(file, account);
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
//#endregion
|
|
426
|
-
//#region src/auth/loginhandlers/digidGemachtigdeLoginHandler.ts
|
|
427
|
-
var DigidGemachtigdeLoginHandler = class {
|
|
538
|
+
//#region src/auth/loginhandlers/digidLoginHandler.ts
|
|
539
|
+
var DigidLoginHandler = class {
|
|
428
540
|
options;
|
|
429
541
|
/**
|
|
430
542
|
* Create one per app, so every test user that logs in to that app shares its options.
|
|
431
543
|
*
|
|
432
|
-
* @param options the app's DigiD
|
|
544
|
+
* @param options the app's DigiD login button (required), and optionally where to start and the
|
|
433
545
|
* app's cookie banner, supplied by the consumer of this library
|
|
434
546
|
*/
|
|
435
547
|
constructor(options) {
|
|
@@ -441,165 +553,63 @@ var DigidGemachtigdeLoginHandler = class {
|
|
|
441
553
|
* @param file path of the storage state file to write the session to
|
|
442
554
|
*/
|
|
443
555
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
444
|
-
await new DigidLoginPage(page).
|
|
556
|
+
await new DigidLoginPage(page).loginAndCreateNewSession(account, file, this.options);
|
|
445
557
|
}
|
|
446
558
|
};
|
|
447
559
|
//#endregion
|
|
448
560
|
//#region src/auth/loginhandlers/eHerkenningBewindvoerderLoginHandler.ts
|
|
449
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
|
+
}
|
|
450
572
|
/**
|
|
451
573
|
* @param page the Playwright page to perform the login on
|
|
452
574
|
* @param account login details, supplied by the consumer of this library
|
|
453
575
|
* @param file path of the storage state file to write the session to
|
|
454
576
|
*/
|
|
455
577
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
456
|
-
await new EHerkenningLoginPage(page).loginAsProfessionalBewindvoerder(account, file);
|
|
578
|
+
await new EHerkenningLoginPage(page).loginAsProfessionalBewindvoerder(account, this.options, file);
|
|
457
579
|
}
|
|
458
580
|
};
|
|
459
581
|
//#endregion
|
|
460
|
-
//#region src/auth/
|
|
461
|
-
var
|
|
462
|
-
|
|
463
|
-
var gzacUrlTest = "https://alg-zgw.test.denhaag.nl";
|
|
464
|
-
function escapeRegExp(value) {
|
|
465
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
466
|
-
}
|
|
467
|
-
var ADLoginPage = class ADLoginPage extends nl_portal_playwright_libraries.BasePage {
|
|
468
|
-
usernameInput;
|
|
469
|
-
passwordInput;
|
|
470
|
-
nextInput;
|
|
471
|
-
signInInput;
|
|
472
|
-
cannotUseAuthAppLink;
|
|
473
|
-
useVerificationCode;
|
|
474
|
-
codeInput;
|
|
475
|
-
verifyInput;
|
|
476
|
-
constructor(page) {
|
|
477
|
-
super(page);
|
|
478
|
-
this.usernameInput = page.locator("//input[@type='email']");
|
|
479
|
-
this.passwordInput = page.locator("//input[@name='passwd']");
|
|
480
|
-
this.nextInput = page.locator("//input[@type='submit']");
|
|
481
|
-
this.signInInput = page.locator("//input[@type='submit']");
|
|
482
|
-
this.cannotUseAuthAppLink = page.locator("//*[@id='signInAnotherWay']");
|
|
483
|
-
this.useVerificationCode = page.getByText(/Gebruik een verificatiecode|Use a verification code/);
|
|
484
|
-
this.codeInput = page.locator("//input[@name='otc']");
|
|
485
|
-
this.verifyInput = page.locator("//input[@type='submit']");
|
|
486
|
-
}
|
|
487
|
-
async openPage(path) {
|
|
488
|
-
await this.page.goto(path);
|
|
489
|
-
}
|
|
582
|
+
//#region src/auth/loginhandlers/eHerkenningLoginHandler.ts
|
|
583
|
+
var EHerkenningLoginHandler = class {
|
|
584
|
+
options;
|
|
490
585
|
/**
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
* @param account login details, supplied by the consumer of this library
|
|
494
|
-
* @param targetUrl URL to navigate to before logging in (the app behind the firewall),
|
|
495
|
-
* supplied by the consumer of this library — not every consumer has a GZAC account, so
|
|
496
|
-
* this library no longer assumes GZAC as the destination. The consumer is responsible
|
|
497
|
-
* for switching between environments (e.g. test/acc/prod) when building this URL; this
|
|
498
|
-
* library does not do that for you.
|
|
499
|
-
* @param fileName path of the storage state file to write the session to
|
|
500
|
-
*
|
|
501
|
-
* @example
|
|
502
|
-
* // consumer-side lookup, e.g. based on an `ENV` environment variable
|
|
503
|
-
* export const TARGET_URL_BY_ENVIRONMENT = {
|
|
504
|
-
* test: 'https://alg-zgw.test.denhaag.nl/',
|
|
505
|
-
* acc: 'https://alg-zgw.acc.denhaag.nl/',
|
|
506
|
-
* prod: 'https://alg-zgw.denhaag.nl/',
|
|
507
|
-
* } as const;
|
|
586
|
+
* Create one per app, so every test user that logs in to that app shares its options.
|
|
508
587
|
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
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
|
|
511
590
|
*/
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
let targetOrigin;
|
|
515
|
-
try {
|
|
516
|
-
targetOrigin = new URL(targetUrl).origin;
|
|
517
|
-
} catch {
|
|
518
|
-
throw new Error(`AD login failed: targetUrl must be an absolute URL (e.g. "https://app.denhaag.nl/..."), got "${targetUrl}"`);
|
|
519
|
-
}
|
|
520
|
-
const isOnTargetApp = async () => this.page.waitForLoadState("networkidle").then(() => this.page.url().startsWith(targetOrigin), () => false);
|
|
521
|
-
let cachedAccountUsed = false;
|
|
522
|
-
let alreadyFullyAuthenticated = false;
|
|
523
|
-
await _playwright_test.test.step("Fill AD username and submit", async () => {
|
|
524
|
-
await this.page.goto(targetUrl);
|
|
525
|
-
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
526
|
-
if (alreadyFullyAuthenticated) return;
|
|
527
|
-
const cachedAccountTile = this.page.getByRole("button", { name: new RegExp(escapeRegExp(account.username), "i") });
|
|
528
|
-
await cachedAccountTile.or(adLoginPage.usernameInput).waitFor({
|
|
529
|
-
state: "visible",
|
|
530
|
-
timeout: 1e4
|
|
531
|
-
}).catch(() => {});
|
|
532
|
-
cachedAccountUsed = await cachedAccountTile.isVisible().catch(() => false);
|
|
533
|
-
if (cachedAccountUsed) {
|
|
534
|
-
await cachedAccountTile.click();
|
|
535
|
-
alreadyFullyAuthenticated = await isOnTargetApp();
|
|
536
|
-
} else {
|
|
537
|
-
await adLoginPage.usernameInput.waitFor();
|
|
538
|
-
await adLoginPage.usernameInput.fill(account.username);
|
|
539
|
-
await adLoginPage.nextInput.click();
|
|
540
|
-
await this.page.getByText("Uw wachtwoord gebruiken").click();
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
let sessionWasStale = false;
|
|
544
|
-
if (!alreadyFullyAuthenticated) {
|
|
545
|
-
await _playwright_test.test.step("Fill AD password and submit", async () => {
|
|
546
|
-
if (!cachedAccountUsed) {
|
|
547
|
-
await maskedFill(adLoginPage.passwordInput, account.password, "password");
|
|
548
|
-
await adLoginPage.signInInput.click();
|
|
549
|
-
await this.page.waitForTimeout(1e3);
|
|
550
|
-
}
|
|
551
|
-
sessionWasStale = await this.page.getByText("Uw account is niet geverifieerd. Probeer het opnieuw").isVisible().catch(() => false);
|
|
552
|
-
});
|
|
553
|
-
await _playwright_test.test.step("Complete MFA via TOTP", async () => {
|
|
554
|
-
if (!sessionWasStale) await adLoginPage.cannotUseAuthAppLink.click();
|
|
555
|
-
await adLoginPage.useVerificationCode.click();
|
|
556
|
-
const token = await totp_generator.TOTP.generate(`${process.env.AD_SECRET}`);
|
|
557
|
-
await maskedFill(adLoginPage.codeInput, token.otp, "otp", true);
|
|
558
|
-
await adLoginPage.verifyInput.click();
|
|
559
|
-
await adLoginPage.page.waitForTimeout(5e3);
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
await _playwright_test.test.step("Save session state", async () => {
|
|
563
|
-
await adLoginPage.page.context().storageState({ path: fileName });
|
|
564
|
-
});
|
|
591
|
+
constructor(options) {
|
|
592
|
+
this.options = options;
|
|
565
593
|
}
|
|
566
594
|
/**
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* @
|
|
570
|
-
* target URL to {@link loginWithADAccountAndCreateSession} instead. Kept only so existing
|
|
571
|
-
* GZAC consumers can still derive this URL themselves during migration; will be removed in
|
|
572
|
-
* a future version.
|
|
573
|
-
*
|
|
574
|
-
* Derives the environment from `this.getBaseUrl()` (inherited from `BasePage`), which reads
|
|
575
|
-
* 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
|
|
576
598
|
*/
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (/klantportaal-zgw.denhaag.nl./.exec(baseUrl)) return gzacUrlProd;
|
|
580
|
-
if (/.acc./.exec(baseUrl)) return gzacUrlAcp;
|
|
581
|
-
if (/.test./.exec(baseUrl)) return gzacUrlTest;
|
|
582
|
-
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);
|
|
583
601
|
}
|
|
584
602
|
};
|
|
585
603
|
//#endregion
|
|
586
|
-
//#region src/auth/loginhandlers/
|
|
587
|
-
var
|
|
588
|
-
targetUrl;
|
|
589
|
-
/**
|
|
590
|
-
* @param targetUrl URL to navigate to before logging in (the app behind the firewall),
|
|
591
|
-
* supplied by the consumer of this library
|
|
592
|
-
*/
|
|
593
|
-
constructor(targetUrl) {
|
|
594
|
-
this.targetUrl = targetUrl;
|
|
595
|
-
}
|
|
604
|
+
//#region src/auth/loginhandlers/localhostLoginHandler.ts
|
|
605
|
+
var LocalhostLoginHandler = class {
|
|
596
606
|
/**
|
|
597
607
|
* @param page the Playwright page to perform the login on
|
|
598
608
|
* @param account login details, supplied by the consumer of this library
|
|
599
609
|
* @param file path of the storage state file to write the session to
|
|
600
610
|
*/
|
|
601
611
|
async loginAndCreateSessionStorage(page, account, file) {
|
|
602
|
-
await new
|
|
612
|
+
await new nl_portal_playwright_libraries.LocalLoginPage(page).loginAndCreateNewSession(account, file);
|
|
603
613
|
}
|
|
604
614
|
};
|
|
605
615
|
//#endregion
|
|
@@ -628,18 +638,18 @@ var ADLoginHandler = class {
|
|
|
628
638
|
*/
|
|
629
639
|
function getLoginHandler(authType, options = {}) {
|
|
630
640
|
switch (authType) {
|
|
631
|
-
case "digid": return (0, nl_portal_playwright_libraries.isRunningOnLocalhost)() ? new LocalhostLoginHandler() : new DigidLoginHandler(
|
|
632
|
-
case "digid_gemachtigde": return new DigidGemachtigdeLoginHandler(
|
|
633
|
-
case "eherkenning": return (0, nl_portal_playwright_libraries.isRunningOnLocalhost)() ? new LocalhostLoginHandler() : new EHerkenningLoginHandler();
|
|
634
|
-
case "eherkenning_vestiging": return new EHerkenningLoginHandler();
|
|
635
|
-
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));
|
|
636
646
|
case "ad-session":
|
|
637
647
|
if (!options.startUrl) throw new Error("startUrl is required when authType is 'ad-session'");
|
|
638
648
|
return new ADLoginHandler(options.startUrl);
|
|
639
649
|
default: throw new Error(`Unsupported auth type: ${authType}. If needed please create a new LoginHandler and register it here in getLoginHandler().`);
|
|
640
650
|
}
|
|
641
651
|
}
|
|
642
|
-
function
|
|
652
|
+
function loginOptions(authType, options) {
|
|
643
653
|
if (!options.loginButton) throw new Error(`loginButton is required when authType is '${authType}'`);
|
|
644
654
|
return {
|
|
645
655
|
...options,
|
|
@@ -647,71 +657,6 @@ function digidOptions(authType, options) {
|
|
|
647
657
|
};
|
|
648
658
|
}
|
|
649
659
|
//#endregion
|
|
650
|
-
//#region src/auth/utils/sessionFileHelper.ts
|
|
651
|
-
var sessionsDir = node_process.env.SESSIONS_DIR ?? node_path.resolve(node_process.cwd(), "sessions");
|
|
652
|
-
var environment = node_process.env.ENV ?? "test";
|
|
653
|
-
/**
|
|
654
|
-
* Easy way to create the filenames for the sessions
|
|
655
|
-
*/
|
|
656
|
-
var SessionFileHelper = class {
|
|
657
|
-
/**
|
|
658
|
-
* @param browser the browser instance the session file name is based on
|
|
659
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
660
|
-
*/
|
|
661
|
-
static getLocalhostFileName(browser, account) {
|
|
662
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* @param browser the browser instance the session file name is based on
|
|
666
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
667
|
-
*/
|
|
668
|
-
static getLocalhostFileNameBedrijf(browser, account) {
|
|
669
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* @param browser the browser instance the session file name is based on
|
|
673
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
674
|
-
*/
|
|
675
|
-
static getDigidFileName(browser, account) {
|
|
676
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-digid-${environment}-${account.username}.json`);
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* @param browser the browser instance the session file name is based on
|
|
680
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
681
|
-
*/
|
|
682
|
-
static getDigidGemachtigdeFileName(browser, account) {
|
|
683
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-digid-gemachtigde-${environment}-${account.username}.json`);
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* @param browser the browser instance the session file name is based on
|
|
687
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
688
|
-
*/
|
|
689
|
-
static getEHerkenningFileName(browser, account) {
|
|
690
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-${environment}-${account.username}.json`);
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* @param browser the browser instance the session file name is based on
|
|
694
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
695
|
-
*/
|
|
696
|
-
static getEHerkenningVestigingFileName(browser, account) {
|
|
697
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-vestiging-${environment}-${account.username}.json`);
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* @param browser the browser instance the session file name is based on
|
|
701
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
702
|
-
*/
|
|
703
|
-
static getEHerkenningBewindvoerderFileName(browser, account) {
|
|
704
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-bewindvoerder-${environment}-${account.username}.json`);
|
|
705
|
-
}
|
|
706
|
-
/**
|
|
707
|
-
* @param browser the browser instance the session file name is based on
|
|
708
|
-
* @param account login details, supplied by the consumer of this library; only `username` is used
|
|
709
|
-
*/
|
|
710
|
-
static getADFileName(browser, account) {
|
|
711
|
-
return node_path.join(sessionsDir, `${browser.browserType().name()}-ad-${environment}-${account.username}.json`);
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
//#endregion
|
|
715
660
|
//#region src/auth/sessionHandler.ts
|
|
716
661
|
var MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
717
662
|
/**
|
|
@@ -847,6 +792,7 @@ function getApiTokenFromSession(baseTest, handler) {
|
|
|
847
792
|
//#region src/auth/getSessionHandler.ts
|
|
848
793
|
/**
|
|
849
794
|
* @param testProfile the test user to log in
|
|
795
|
+
* @param loginOptionsWithButtons with the login button and the accept cookiebutton if necessary
|
|
850
796
|
* @param loginHandler the login handler for the app the user logs in to, with that app's options, e.g.
|
|
851
797
|
* `new DigidLoginHandler({ loginButton, ... })` or `getLoginHandler(authType, options)`. Required for
|
|
852
798
|
* auth types that need options (`ad-session`, `digid`, `digid_gemachtigde`); left out, the handler
|
|
@@ -862,12 +808,13 @@ function getApiTokenFromSession(baseTest, handler) {
|
|
|
862
808
|
*
|
|
863
809
|
* getSessionHandler(digidUser1, openFormsDigid);
|
|
864
810
|
*/
|
|
865
|
-
function getSessionHandler(testProfile, loginHandler) {
|
|
866
|
-
return createSessionHandler(testProfile.authType, testProfile.account, loginHandler ?? getLoginHandler(testProfile.authType));
|
|
811
|
+
function getSessionHandler(testProfile, loginOptionsWithButtons, loginHandler) {
|
|
812
|
+
return createSessionHandler(testProfile.authType, testProfile.account, loginHandler ?? getLoginHandler(testProfile.authType, loginOptionsWithButtons));
|
|
867
813
|
}
|
|
868
814
|
//#endregion
|
|
869
815
|
exports.ADLoginHandler = ADLoginHandler;
|
|
870
816
|
exports.ADLoginPage = ADLoginPage;
|
|
817
|
+
exports.BaseLoginPage = BaseLoginPage;
|
|
871
818
|
exports.DigidGemachtigdeLoginHandler = DigidGemachtigdeLoginHandler;
|
|
872
819
|
exports.DigidLoginHandler = DigidLoginHandler;
|
|
873
820
|
exports.DigidLoginPage = DigidLoginPage;
|
|
@@ -875,7 +822,6 @@ exports.EHerkenningBewindvoerderLoginHandler = EHerkenningBewindvoerderLoginHand
|
|
|
875
822
|
exports.EHerkenningLoginHandler = EHerkenningLoginHandler;
|
|
876
823
|
exports.EHerkenningLoginPage = EHerkenningLoginPage;
|
|
877
824
|
exports.LocalhostLoginHandler = LocalhostLoginHandler;
|
|
878
|
-
exports.LoginOverzichtPage = LoginOverzichtPage;
|
|
879
825
|
exports.MAX_SESSION_TIME_IN_MINUTES = MAX_SESSION_TIME_IN_MINUTES;
|
|
880
826
|
exports.SessionFileHelper = SessionFileHelper;
|
|
881
827
|
exports.createSessionHandler = createSessionHandler;
|