kinde-testkit 0.7.0 → 0.8.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/CHANGELOG.md +15 -0
- package/README.md +97 -9
- package/dist/chunk-BPPG4G52.js +427 -0
- package/dist/chunk-BPPG4G52.js.map +1 -0
- package/dist/{chunk-JTAB2S44.js → chunk-CY75AADD.js} +175 -454
- package/dist/chunk-CY75AADD.js.map +1 -0
- package/dist/chunk-EZUKOKNO.js +48 -0
- package/dist/chunk-EZUKOKNO.js.map +1 -0
- package/dist/{chunk-2QJ7DTNL.js → chunk-YJPE5HAM.js} +5 -3
- package/dist/{chunk-2QJ7DTNL.js.map → chunk-YJPE5HAM.js.map} +1 -1
- package/dist/cli.js +8 -2
- package/dist/cli.js.map +1 -1
- package/dist/cypress-support.d.ts +142 -0
- package/dist/cypress-support.js +21 -6
- package/dist/cypress-support.js.map +1 -1
- package/dist/cypress.cjs +142 -14
- package/dist/cypress.d.cts +1 -1
- package/dist/cypress.d.ts +3 -2
- package/dist/cypress.js +2 -1
- package/dist/cypress.js.map +1 -1
- package/dist/{handle-estfqypp.d.cts → handle-DRPxm36j.d.cts} +1 -1
- package/dist/{handle-E_BhdHx8.d.ts → handle-Pjt9fSUq.d.ts} +3 -2
- package/dist/index.cjs +145 -14
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +8 -26
- package/dist/index.js +27 -51
- package/dist/index.js.map +1 -1
- package/dist/jest.cjs +142 -14
- package/dist/jest.d.cts +3 -3
- package/dist/jest.d.ts +5 -4
- package/dist/jest.js +3 -2
- package/dist/jest.js.map +1 -1
- package/dist/playwright.d.ts +12 -3
- package/dist/playwright.js +30 -0
- package/dist/playwright.js.map +1 -1
- package/dist/react.d.ts +43 -0
- package/dist/react.js +110 -0
- package/dist/react.js.map +1 -0
- package/dist/{server-CTBJXMac.d.cts → server-CLRn67qI.d.cts} +26 -0
- package/dist/{server-B9fBcnyQ.d.ts → server-CuHAHsaN.d.ts} +3 -56
- package/dist/sign-in-flow-DNrDXSLI.d.ts +35 -0
- package/dist/testkit-BvCAFsSj.d.ts +156 -0
- package/dist/vitest.d.ts +5 -4
- package/dist/vitest.js +3 -2
- package/dist/vitest.js.map +1 -1
- package/dist/{webhooks-DJyCsbdF.d.ts → webhooks-CiK9_pVw.d.ts} +82 -155
- package/package.json +30 -3
- package/dist/chunk-JTAB2S44.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1835,6 +1835,25 @@ function layout(title, body) {
|
|
|
1835
1835
|
function displayName(user) {
|
|
1836
1836
|
return [user.givenName, user.familyName].filter(Boolean).join(" ") || user.email || user.id;
|
|
1837
1837
|
}
|
|
1838
|
+
var SOCIAL_CONNECTIONS = ["google", "github", "microsoft", "apple", "facebook", "gitlab", "linkedin", "slack", "x"];
|
|
1839
|
+
function select(id, label, options) {
|
|
1840
|
+
return `<label for="${id}">${label}</label><select id="${id}" name="${id}" style="width:100%;height:38px;padding:0 10px;border-radius:8px;border:1px solid var(--line);background:transparent;color:var(--ink);font:inherit">${options.map(([value, text]) => `<option value="${value}">${escapeHtml(text)}</option>`).join("")}</select>`;
|
|
1841
|
+
}
|
|
1842
|
+
function testOptions() {
|
|
1843
|
+
return `<h2>Test options</h2>${select("connection", "Sign in with", [
|
|
1844
|
+
["email", "Email"],
|
|
1845
|
+
...SOCIAL_CONNECTIONS.map((c) => [c, c === "x" ? "X" : c[0].toUpperCase() + c.slice(1)])
|
|
1846
|
+
])}${select("provider_result", "Provider result", [
|
|
1847
|
+
["success", "Signed in"],
|
|
1848
|
+
["cancelled", "User cancelled"],
|
|
1849
|
+
["error", "Provider error"]
|
|
1850
|
+
])}${select("mfa", "Multi-factor authentication", [
|
|
1851
|
+
["none", "Not required"],
|
|
1852
|
+
["passed", "Passed"],
|
|
1853
|
+
["failed", "Wrong code"],
|
|
1854
|
+
["cancelled", "Cancelled"]
|
|
1855
|
+
])}`;
|
|
1856
|
+
}
|
|
1838
1857
|
function renderSignIn(options) {
|
|
1839
1858
|
const users = options.users.map(({ user, organizations }) => {
|
|
1840
1859
|
const value = escapeHtml(user.email ?? user.id);
|
|
@@ -1846,16 +1865,17 @@ function renderSignIn(options) {
|
|
|
1846
1865
|
const orgNote = options.requiredOrganization ? `<p class="note">The app asked to sign in to <strong>${escapeHtml(options.requiredOrganization)}</strong>.</p>` : "";
|
|
1847
1866
|
return layout(
|
|
1848
1867
|
"Sign in",
|
|
1849
|
-
`<h1>Sign in</h1><p>Test sign-in. Tokens are signed with a local key and are only valid for this issuer.</p>${orgNote}${options.error ? `<div class="error" role="alert">${escapeHtml(options.error)}</div>` : ""}<form method="post" action="/oauth2/auth/login"><input type="hidden" name="request" value="${escapeHtml(options.request)}"><label for="email">Email</label><input id="email" name="email" type="email" autocomplete="off" value="${escapeHtml(options.loginHint ?? "")}" placeholder="name@example.test"><button class="primary" type="submit">Continue</button>${users ? `<h2>Seeded users</h2><div class="list">${users}</div>` : ""}</form>`
|
|
1868
|
+
`<h1>Sign in</h1><p>Test sign-in. Tokens are signed with a local key and are only valid for this issuer.</p>${orgNote}${options.error ? `<div class="error" role="alert">${escapeHtml(options.error)}</div>` : ""}<form method="post" action="/oauth2/auth/login"><input type="hidden" name="request" value="${escapeHtml(options.request)}"><label for="email">Email</label><input id="email" name="email" type="email" autocomplete="off" value="${escapeHtml(options.loginHint ?? "")}" placeholder="name@example.test"><button class="primary" type="submit">Continue</button>${users ? `<h2>Seeded users</h2><div class="list">${users}</div>` : ""}${testOptions()}</form>`
|
|
1850
1869
|
);
|
|
1851
1870
|
}
|
|
1852
1871
|
function renderOrganizationPicker(options) {
|
|
1872
|
+
const carried = Object.entries(options.carry ?? {}).map(([name, value]) => `<input type="hidden" name="${escapeHtml(name)}" value="${escapeHtml(value)}">`).join("");
|
|
1853
1873
|
const choices = options.organizations.map(
|
|
1854
1874
|
(org) => `<button class="option" type="submit" name="org" value="${escapeHtml(org.code)}"><span><strong>${escapeHtml(org.name)}</strong><small>${escapeHtml(org.code)}</small></span></button>`
|
|
1855
1875
|
).join("");
|
|
1856
1876
|
return layout(
|
|
1857
1877
|
"Choose an organization",
|
|
1858
|
-
`<h1>Choose an organization</h1><p>${escapeHtml(options.user.email ?? options.user.id)} belongs to more than one organization.</p><form method="post" action="/oauth2/auth/login"><input type="hidden" name="request" value="${escapeHtml(options.request)}"><input type="hidden" name="user" value="${escapeHtml(options.user.email ?? options.user.id)}"
|
|
1878
|
+
`<h1>Choose an organization</h1><p>${escapeHtml(options.user.email ?? options.user.id)} belongs to more than one organization.</p><form method="post" action="/oauth2/auth/login"><input type="hidden" name="request" value="${escapeHtml(options.request)}"><input type="hidden" name="user" value="${escapeHtml(options.user.email ?? options.user.id)}">${carried}<div class="list" style="margin-top:20px">${choices}</div></form>`
|
|
1859
1879
|
);
|
|
1860
1880
|
}
|
|
1861
1881
|
function renderMessage(title, message2) {
|
|
@@ -2296,6 +2316,17 @@ var AuthorizationServer = class {
|
|
|
2296
2316
|
return sendHtml(res, 400, renderMessage("Sign-in request rejected", "The sign-in form is missing its request. Start again from the app."));
|
|
2297
2317
|
}
|
|
2298
2318
|
const encoded = encodeRequest(request);
|
|
2319
|
+
const connection = (form2.connection || "email").trim().toLowerCase();
|
|
2320
|
+
const providerResult = form2.provider_result || "success";
|
|
2321
|
+
const mfa = form2.mfa || "none";
|
|
2322
|
+
if (!/^[a-z0-9_-]{1,40}$/.test(connection) || !["success", "cancelled", "error"].includes(providerResult) || !["none", "passed", "failed", "cancelled"].includes(mfa)) {
|
|
2323
|
+
return sendHtml(res, 400, renderSignIn({ request: encoded, users: this.loginPageUsers(), requiredOrganization: request.orgCode ?? void 0, error: "The test options on the sign-in form are not valid." }));
|
|
2324
|
+
}
|
|
2325
|
+
if (connection !== "email" && providerResult !== "success") {
|
|
2326
|
+
this.observe("session.sign-in-refused");
|
|
2327
|
+
return providerResult === "cancelled" ? redirectWithError(res, request, "access_denied", `The user cancelled sign-in with ${connection}.`) : redirectWithError(res, request, "server_error", `${connection} returned an error during sign-in.`);
|
|
2328
|
+
}
|
|
2329
|
+
const carry = { connection, provider_result: providerResult, mfa };
|
|
2299
2330
|
const ref = (form2.user || form2.email || "").trim();
|
|
2300
2331
|
if (!ref) {
|
|
2301
2332
|
return sendHtml(res, 400, renderSignIn({ request: encoded, users: this.loginPageUsers(), requiredOrganization: request.orgCode ?? void 0, error: "Enter an email address or pick a seeded user." }));
|
|
@@ -2317,6 +2348,21 @@ var AuthorizationServer = class {
|
|
|
2317
2348
|
})
|
|
2318
2349
|
);
|
|
2319
2350
|
}
|
|
2351
|
+
if (mfa === "failed") {
|
|
2352
|
+
this.observe("session.sign-in-refused");
|
|
2353
|
+
return sendHtml(
|
|
2354
|
+
res,
|
|
2355
|
+
401,
|
|
2356
|
+
renderSignIn({ request: encoded, users: this.loginPageUsers(), requiredOrganization: request.orgCode ?? void 0, error: "The verification code is not correct." })
|
|
2357
|
+
);
|
|
2358
|
+
}
|
|
2359
|
+
if (mfa === "cancelled") {
|
|
2360
|
+
this.observe("session.sign-in-refused");
|
|
2361
|
+
return redirectWithError(res, request, "access_denied", "The user cancelled multi-factor authentication.");
|
|
2362
|
+
}
|
|
2363
|
+
if (connection !== "email") this.observe("identity.social");
|
|
2364
|
+
if (mfa === "passed") this.observe("identity.mfa");
|
|
2365
|
+
const authMethods = [connection, ...mfa === "passed" ? ["mfa"] : []];
|
|
2320
2366
|
const memberships = this.seed.memberships.filter((m) => m.userId === user.id);
|
|
2321
2367
|
const wanted = request.orgCode ?? form2.org ?? null;
|
|
2322
2368
|
let organizationCode = null;
|
|
@@ -2344,7 +2390,8 @@ var AuthorizationServer = class {
|
|
|
2344
2390
|
renderOrganizationPicker({
|
|
2345
2391
|
request: encoded,
|
|
2346
2392
|
user,
|
|
2347
|
-
organizations: memberships.map((m) => this.organization(m.organizationCode)).filter((org) => org !== null)
|
|
2393
|
+
organizations: memberships.map((m) => this.organization(m.organizationCode)).filter((org) => org !== null),
|
|
2394
|
+
carry
|
|
2348
2395
|
})
|
|
2349
2396
|
);
|
|
2350
2397
|
}
|
|
@@ -2366,6 +2413,7 @@ var AuthorizationServer = class {
|
|
|
2366
2413
|
audience: request.audience,
|
|
2367
2414
|
nonce: request.nonce,
|
|
2368
2415
|
authTime: Math.floor(Date.now() / 1e3),
|
|
2416
|
+
authMethods,
|
|
2369
2417
|
codeChallenge: request.codeChallenge,
|
|
2370
2418
|
codeChallengeMethod: request.codeChallengeMethod,
|
|
2371
2419
|
expiresAt: Date.now() + CODE_LIFETIME_MS
|
|
@@ -2677,6 +2725,7 @@ var AuthorizationServer = class {
|
|
|
2677
2725
|
clientId: grant.clientId,
|
|
2678
2726
|
audience: grant.audience.length > 0 ? grant.audience : void 0,
|
|
2679
2727
|
authTime: grant.authTime,
|
|
2728
|
+
authMethods: grant.authMethods,
|
|
2680
2729
|
featureFlags: featureFlagsFor(this.seed, scenario2.organization?.code ?? null)
|
|
2681
2730
|
}),
|
|
2682
2731
|
expires_in: this.testkit.accessTokenLifetime,
|
|
@@ -2687,7 +2736,8 @@ var AuthorizationServer = class {
|
|
|
2687
2736
|
body.id_token = await this.testkit.idTokenFor(scenario2, {
|
|
2688
2737
|
clientId: grant.clientId,
|
|
2689
2738
|
nonce: grant.nonce ?? void 0,
|
|
2690
|
-
authTime: grant.authTime
|
|
2739
|
+
authTime: grant.authTime,
|
|
2740
|
+
authMethods: grant.authMethods
|
|
2691
2741
|
});
|
|
2692
2742
|
}
|
|
2693
2743
|
if (grant.scope.includes("offline")) {
|
|
@@ -3035,7 +3085,8 @@ var Directory = class {
|
|
|
3035
3085
|
isPasswordResetRequested: false,
|
|
3036
3086
|
createdOn: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3037
3087
|
totalSignIns: 0,
|
|
3038
|
-
lastSignedIn: null
|
|
3088
|
+
lastSignedIn: null,
|
|
3089
|
+
lastOrganizationSignIns: {}
|
|
3039
3090
|
};
|
|
3040
3091
|
this.userMeta.set(user.id, meta);
|
|
3041
3092
|
}
|
|
@@ -3048,7 +3099,7 @@ var Directory = class {
|
|
|
3048
3099
|
const meta = this.meta(user);
|
|
3049
3100
|
meta.totalSignIns += 1;
|
|
3050
3101
|
meta.lastSignedIn = (/* @__PURE__ */ new Date()).toISOString();
|
|
3051
|
-
|
|
3102
|
+
if (organizationCode) meta.lastOrganizationSignIns[organizationCode] = meta.lastSignedIn;
|
|
3052
3103
|
}
|
|
3053
3104
|
createUser(input) {
|
|
3054
3105
|
const user = createKindeUser({
|
|
@@ -3118,6 +3169,34 @@ var Directory = class {
|
|
|
3118
3169
|
for (const key of permissions) this.ensurePermission(key);
|
|
3119
3170
|
return membership;
|
|
3120
3171
|
}
|
|
3172
|
+
/**
|
|
3173
|
+
* Makes sure a user exists with exactly these roles and permissions in the organization, creating
|
|
3174
|
+
* the user, organization and membership when they are missing. Used by authenticateAs() in browser
|
|
3175
|
+
* tests, so a test can sign in as any identity without adding it to the seed. reset() removes it.
|
|
3176
|
+
*/
|
|
3177
|
+
ensureIdentity(input) {
|
|
3178
|
+
const email = input.email.trim().toLowerCase();
|
|
3179
|
+
let user = findUser(this.seed.users, email);
|
|
3180
|
+
if (!user) {
|
|
3181
|
+
user = createKindeUser({ email, givenName: input.givenName ?? null, familyName: input.familyName ?? null });
|
|
3182
|
+
this.seed.users.push(user);
|
|
3183
|
+
}
|
|
3184
|
+
if (!input.organization) return { user, organization: null };
|
|
3185
|
+
let organization = this.organization(input.organization);
|
|
3186
|
+
if (!organization) {
|
|
3187
|
+
organization = createKindeOrganization({ code: input.organization, name: input.organizationName ?? input.organization });
|
|
3188
|
+
this.seed.organizations.push(organization);
|
|
3189
|
+
}
|
|
3190
|
+
const roles = input.roles ?? [];
|
|
3191
|
+
const permissions = input.permissions ?? [];
|
|
3192
|
+
const index = this.seed.memberships.findIndex((m) => m.userId === user.id && m.organizationCode === organization.code);
|
|
3193
|
+
const membership = createMembership({ userId: user.id, organizationCode: organization.code, roles, permissions });
|
|
3194
|
+
if (index >= 0) this.seed.memberships[index] = membership;
|
|
3195
|
+
else this.seed.memberships.push(membership);
|
|
3196
|
+
for (const key of roles) this.ensureRole(key);
|
|
3197
|
+
for (const key of permissions) this.ensurePermission(key);
|
|
3198
|
+
return { user, organization };
|
|
3199
|
+
}
|
|
3121
3200
|
removeMembership(userId, organizationCode) {
|
|
3122
3201
|
const index = this.seed.memberships.findIndex((m) => m.userId === userId && m.organizationCode === organizationCode);
|
|
3123
3202
|
if (index < 0) return false;
|
|
@@ -3495,12 +3574,14 @@ var ManagementApi = class {
|
|
|
3495
3574
|
username: null,
|
|
3496
3575
|
last_name: user.familyName,
|
|
3497
3576
|
first_name: user.givenName,
|
|
3577
|
+
full_name: [user.givenName, user.familyName].filter(Boolean).join(" ") || null,
|
|
3498
3578
|
is_suspended: meta.isSuspended,
|
|
3499
3579
|
picture: user.picture,
|
|
3500
3580
|
total_sign_ins: meta.totalSignIns,
|
|
3501
3581
|
failed_sign_ins: 0,
|
|
3502
3582
|
last_signed_in: meta.lastSignedIn,
|
|
3503
3583
|
created_on: meta.createdOn,
|
|
3584
|
+
last_organization_sign_ins: Object.entries(meta.lastOrganizationSignIns).map(([org_code, last_signed_in]) => ({ org_code, last_signed_in })),
|
|
3504
3585
|
organizations: this.organizationsOf(user),
|
|
3505
3586
|
identities: user.email ? [{ type: "email", identity: user.email }] : []
|
|
3506
3587
|
};
|
|
@@ -3520,7 +3601,8 @@ var ManagementApi = class {
|
|
|
3520
3601
|
handle: meta.handle,
|
|
3521
3602
|
is_default: false,
|
|
3522
3603
|
external_id: meta.externalId,
|
|
3523
|
-
is_auto_membership_enabled: false
|
|
3604
|
+
is_auto_membership_enabled: false,
|
|
3605
|
+
created_on: meta.createdOn
|
|
3524
3606
|
};
|
|
3525
3607
|
}
|
|
3526
3608
|
organizationEvent(org) {
|
|
@@ -3531,7 +3613,7 @@ var ManagementApi = class {
|
|
|
3531
3613
|
return { id: role.id, key: role.key, name: role.name, description: role.description, is_default_role: role.isDefault };
|
|
3532
3614
|
}
|
|
3533
3615
|
permissionItem(permission) {
|
|
3534
|
-
return { id: permission.id, key: permission.key, name: permission.name, description: permission.description };
|
|
3616
|
+
return { id: permission.id, key: permission.key, name: permission.name, description: permission.description, is_organization_role_assignable: false };
|
|
3535
3617
|
}
|
|
3536
3618
|
};
|
|
3537
3619
|
function paginate(items, query) {
|
|
@@ -3560,6 +3642,7 @@ function sendJson3(res, status, body) {
|
|
|
3560
3642
|
}
|
|
3561
3643
|
|
|
3562
3644
|
// src/failures.ts
|
|
3645
|
+
var MALFORMED_KINDS = ["invalid-json", "empty", "html", "unexpected-json"];
|
|
3563
3646
|
var MAX_DELAY_MS = 6e4;
|
|
3564
3647
|
var FailureInjector = class {
|
|
3565
3648
|
rules = [];
|
|
@@ -3578,6 +3661,7 @@ var FailureInjector = class {
|
|
|
3578
3661
|
hang: rule.hang ?? false,
|
|
3579
3662
|
remaining: rule.times ?? null,
|
|
3580
3663
|
retryAfter: rule.retryAfter ?? 1,
|
|
3664
|
+
malformed: rule.malformed ?? null,
|
|
3581
3665
|
hits: 0
|
|
3582
3666
|
};
|
|
3583
3667
|
this.rules.push(active);
|
|
@@ -3609,6 +3693,18 @@ function failureBody(status) {
|
|
|
3609
3693
|
const error = status === 429 ? "rate_limited" : status === 503 ? "temporarily_unavailable" : status >= 500 ? "server_error" : "injected_failure";
|
|
3610
3694
|
return { error, error_description: `kinde-testkit injected a ${status} response.` };
|
|
3611
3695
|
}
|
|
3696
|
+
function malformedBody(kind) {
|
|
3697
|
+
switch (kind) {
|
|
3698
|
+
case "invalid-json":
|
|
3699
|
+
return { contentType: "application/json", body: '{"access_token":"eyJhbGciOiJSUzI1NiJ9.' };
|
|
3700
|
+
case "empty":
|
|
3701
|
+
return { contentType: "application/json", body: "" };
|
|
3702
|
+
case "html":
|
|
3703
|
+
return { contentType: "text/html; charset=utf-8", body: "<!doctype html><html><body><h1>Bad gateway</h1></body></html>" };
|
|
3704
|
+
case "unexpected-json":
|
|
3705
|
+
return { contentType: "application/json", body: JSON.stringify({ message: "kinde-testkit sent a JSON body in a shape your client does not expect." }) };
|
|
3706
|
+
}
|
|
3707
|
+
}
|
|
3612
3708
|
function matches(rule, method, path) {
|
|
3613
3709
|
if (rule.method && rule.method !== method.toUpperCase()) return false;
|
|
3614
3710
|
if (rule.path.endsWith("*")) return path.startsWith(rule.path.slice(0, -1));
|
|
@@ -3621,8 +3717,12 @@ function validate(rule) {
|
|
|
3621
3717
|
} else if (rule.path.startsWith("/testkit/")) {
|
|
3622
3718
|
problems.push("Failures cannot target /testkit/ control endpoints.");
|
|
3623
3719
|
}
|
|
3624
|
-
if (rule.
|
|
3625
|
-
problems.push(
|
|
3720
|
+
if (rule.malformed !== void 0 && !MALFORMED_KINDS.includes(rule.malformed)) {
|
|
3721
|
+
problems.push(`"malformed" must be one of ${MALFORMED_KINDS.join(", ")}.`);
|
|
3722
|
+
}
|
|
3723
|
+
const lowest = rule.malformed ? 200 : 400;
|
|
3724
|
+
if (rule.status !== void 0 && (!Number.isInteger(rule.status) || rule.status < lowest || rule.status > 599)) {
|
|
3725
|
+
problems.push(rule.malformed ? '"status" must be between 200 and 599.' : '"status" must be an HTTP error status between 400 and 599.');
|
|
3626
3726
|
}
|
|
3627
3727
|
if (rule.delayMs !== void 0 && (!Number.isFinite(rule.delayMs) || rule.delayMs < 0 || rule.delayMs > MAX_DELAY_MS)) {
|
|
3628
3728
|
problems.push(`"delayMs" must be between 0 and ${MAX_DELAY_MS}.`);
|
|
@@ -3633,8 +3733,8 @@ function validate(rule) {
|
|
|
3633
3733
|
if (rule.retryAfter !== void 0 && (!Number.isInteger(rule.retryAfter) || rule.retryAfter < 0)) {
|
|
3634
3734
|
problems.push('"retryAfter" must be a whole number of seconds.');
|
|
3635
3735
|
}
|
|
3636
|
-
if (rule.status === void 0 && !rule.delayMs && !rule.hang) {
|
|
3637
|
-
problems.push('Set at least one of "status", "delayMs" or "
|
|
3736
|
+
if (rule.status === void 0 && !rule.delayMs && !rule.hang && !rule.malformed) {
|
|
3737
|
+
problems.push('Set at least one of "status", "delayMs", "hang" or "malformed".');
|
|
3638
3738
|
}
|
|
3639
3739
|
return problems;
|
|
3640
3740
|
}
|
|
@@ -3990,7 +4090,9 @@ var COVERAGE_GROUPS = [
|
|
|
3990
4090
|
{ id: "identity.no-organization", label: "User with no organization", hint: "Mint a valid user token without org_code." },
|
|
3991
4091
|
{ id: "identity.unseeded", label: "User not in the seed", hint: "Sign in with an email that is not seeded." },
|
|
3992
4092
|
{ id: "identity.id-token", label: "ID token", hint: "Sign in through the sign-in page so the app gets an ID token." },
|
|
3993
|
-
{ id: "identity.suspended", label: "Suspended user refused", hint: "Suspend a user with the Management API, then sign them in." }
|
|
4093
|
+
{ id: "identity.suspended", label: "Suspended user refused", hint: "Suspend a user with the Management API, then sign them in." },
|
|
4094
|
+
{ id: "identity.social", label: "Social sign-in", hint: 'Sign in with a social connection, such as signInAs(email, { connection: "google" }).' },
|
|
4095
|
+
{ id: "identity.mfa", label: "Multi-factor sign-in", hint: 'Sign in with { mfa: "passed" }.' }
|
|
3994
4096
|
]
|
|
3995
4097
|
},
|
|
3996
4098
|
{
|
|
@@ -4027,6 +4129,7 @@ var COVERAGE_GROUPS = [
|
|
|
4027
4129
|
{ id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
|
|
4028
4130
|
{ id: "session.revoke", label: "Refresh token revoked", hint: "Call /oauth2/revoke, as some SDKs do on sign-out." },
|
|
4029
4131
|
{ id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." },
|
|
4132
|
+
{ id: "session.sign-in-refused", label: "Sign-in cancelled or failed", hint: `Sign in with { providerResult: "cancelled" } or { mfa: "failed" } and check the app's error handling.` },
|
|
4030
4133
|
{ id: "session.device-approved", label: "Device sign-in", hint: "Run the device authorization flow and approve it with POST /testkit/device." }
|
|
4031
4134
|
]
|
|
4032
4135
|
},
|
|
@@ -4064,7 +4167,8 @@ var COVERAGE_GROUPS = [
|
|
|
4064
4167
|
{ id: "outage.error", label: "Kinde answers with an error", hint: "Inject a 500 or 503 on an endpoint the app calls." },
|
|
4065
4168
|
{ id: "outage.rate-limit", label: "Rate limit", hint: "Inject a 429." },
|
|
4066
4169
|
{ id: "outage.slow", label: "Slow answer", hint: "Inject a delay." },
|
|
4067
|
-
{ id: "outage.timeout", label: "No answer", hint: "Inject a hang so the client hits its timeout." }
|
|
4170
|
+
{ id: "outage.timeout", label: "No answer", hint: "Inject a hang so the client hits its timeout." },
|
|
4171
|
+
{ id: "outage.malformed", label: "Malformed answer", hint: "Inject a malformed response, such as invalid JSON from the token endpoint." }
|
|
4068
4172
|
]
|
|
4069
4173
|
}
|
|
4070
4174
|
];
|
|
@@ -4555,6 +4659,13 @@ async function handle(req, res, context) {
|
|
|
4555
4659
|
if (failure.delayMs > 0) coverage.hit("outage.slow");
|
|
4556
4660
|
if (failure.hang) return;
|
|
4557
4661
|
if (failure.delayMs > 0) await new Promise((resolve4) => setTimeout(resolve4, failure.delayMs));
|
|
4662
|
+
if (failure.malformed) {
|
|
4663
|
+
coverage.hit("outage.malformed");
|
|
4664
|
+
const { contentType, body } = malformedBody(failure.malformed);
|
|
4665
|
+
res.writeHead(failure.status ?? 200, { "content-type": contentType, "cache-control": "no-store" });
|
|
4666
|
+
res.end(body);
|
|
4667
|
+
return;
|
|
4668
|
+
}
|
|
4558
4669
|
if (failure.status !== null) {
|
|
4559
4670
|
const headers = {};
|
|
4560
4671
|
if (failure.status === 429 || failure.status === 503) headers["retry-after"] = String(failure.retryAfter);
|
|
@@ -4622,6 +4733,23 @@ async function handle(req, res, context) {
|
|
|
4622
4733
|
const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
|
|
4623
4734
|
return sendJson4(res, removed ? 200 : 404, { ok: removed });
|
|
4624
4735
|
}
|
|
4736
|
+
if (method === "POST" && pathname === "/testkit/identities") {
|
|
4737
|
+
const input = await readJson(req);
|
|
4738
|
+
if (typeof input.email !== "string" || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(input.email)) {
|
|
4739
|
+
throw new TestkitError("INVALID_REQUEST", "An identity needs an email address.");
|
|
4740
|
+
}
|
|
4741
|
+
const strings2 = (value) => Array.isArray(value) ? value.filter((v) => typeof v === "string") : void 0;
|
|
4742
|
+
const { user, organization } = context.directory.ensureIdentity({
|
|
4743
|
+
email: input.email,
|
|
4744
|
+
givenName: typeof input.givenName === "string" ? input.givenName : null,
|
|
4745
|
+
familyName: typeof input.familyName === "string" ? input.familyName : null,
|
|
4746
|
+
organization: typeof input.organization === "string" ? input.organization : null,
|
|
4747
|
+
organizationName: typeof input.organizationName === "string" ? input.organizationName : void 0,
|
|
4748
|
+
roles: strings2(input.roles),
|
|
4749
|
+
permissions: strings2(input.permissions)
|
|
4750
|
+
});
|
|
4751
|
+
return sendJson4(res, 200, { user: { id: user.id, email: user.email }, organization: organization?.code ?? null });
|
|
4752
|
+
}
|
|
4625
4753
|
if (method === "POST" && pathname === "/testkit/device") {
|
|
4626
4754
|
const input = await readJson(req);
|
|
4627
4755
|
try {
|
|
@@ -5115,6 +5243,9 @@ function readSignInRequest(html) {
|
|
|
5115
5243
|
function signInForm(request, options) {
|
|
5116
5244
|
const form2 = { request, email: options.user };
|
|
5117
5245
|
if (options.org) form2.org = options.org;
|
|
5246
|
+
if (options.connection) form2.connection = options.connection;
|
|
5247
|
+
if (options.providerResult) form2.provider_result = options.providerResult;
|
|
5248
|
+
if (options.mfa) form2.mfa = options.mfa;
|
|
5118
5249
|
return form2;
|
|
5119
5250
|
}
|
|
5120
5251
|
function signInFailure(status, html, options) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, d as Scenario, T as TestkitSeed } from './server-
|
|
2
|
-
export { e as ActiveFailure, f as ActivityLog, B as BILLING_EVENT_TYPES, C as COVERAGE_GROUPS, g as CoverageGroup, h as CoverageGroupResult, i as CoverageItem, j as CoverageRecorder, k as CoverageReport, l as CoverageSnapshot, D as DEFAULT_AUTH_METHODS, m as DEFAULT_CLIENT_ID, n as DEFAULT_COVERAGE_DIRECTORY, o as DEFAULT_ISSUER, p as DEFAULT_M2M_CLIENT_ID, q as DEFAULT_SCOPES, r as DeviceFlowOptions, s as Directory, t as Duration, F as FailureInjector, u as FailureRule, I as INVALID_TOKEN_KINDS, v as IdTokenOptions, w as InvalidTokenKind, x as KindeApplication, y as KindePrincipal, z as KindeTestkit, E as KindeTestkitOptions, G as KindeTokenOptions, M as M2MTokenOptions, R as RequestEntry, H as ResolvedSeed, J as RunningKindeTestkit, L as ScenarioTokenOverrides, N as SendWebhookOptions, S as StartKindeTestkitOptions, O as TokenEntry, P as TokenObserver, W as WEBHOOK_EVENT_TYPES, Q as WebhookAttempt, V as WebhookDelivery, X as WebhookDispatcher, Y as WebhookEndpoint, Z as WebhookEndpointInput, _ as WebhookInvalidKind, $ as WebhookOptions, a0 as WebhookSource, a1 as buildReport, a2 as clearCoverageDirectory, a3 as createKindeToken, a4 as formatCoverageReport, a5 as getDefaultTestkit, a6 as mergeSnapshots, a7 as principalFromClaims, a8 as readCoverageDirectory, a9 as resolveSeed, aa as seedScenario, ab as startKindeTestkit } from './server-
|
|
1
|
+
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, d as Scenario, T as TestkitSeed } from './server-CLRn67qI.cjs';
|
|
2
|
+
export { e as ActiveFailure, f as ActivityLog, B as BILLING_EVENT_TYPES, C as COVERAGE_GROUPS, g as CoverageGroup, h as CoverageGroupResult, i as CoverageItem, j as CoverageRecorder, k as CoverageReport, l as CoverageSnapshot, D as DEFAULT_AUTH_METHODS, m as DEFAULT_CLIENT_ID, n as DEFAULT_COVERAGE_DIRECTORY, o as DEFAULT_ISSUER, p as DEFAULT_M2M_CLIENT_ID, q as DEFAULT_SCOPES, r as DeviceFlowOptions, s as Directory, t as Duration, F as FailureInjector, u as FailureRule, I as INVALID_TOKEN_KINDS, v as IdTokenOptions, w as InvalidTokenKind, x as KindeApplication, y as KindePrincipal, z as KindeTestkit, E as KindeTestkitOptions, G as KindeTokenOptions, M as M2MTokenOptions, R as RequestEntry, H as ResolvedSeed, J as RunningKindeTestkit, L as ScenarioTokenOverrides, N as SendWebhookOptions, S as StartKindeTestkitOptions, O as TokenEntry, P as TokenObserver, W as WEBHOOK_EVENT_TYPES, Q as WebhookAttempt, V as WebhookDelivery, X as WebhookDispatcher, Y as WebhookEndpoint, Z as WebhookEndpointInput, _ as WebhookInvalidKind, $ as WebhookOptions, a0 as WebhookSource, a1 as buildReport, a2 as clearCoverageDirectory, a3 as createKindeToken, a4 as formatCoverageReport, a5 as getDefaultTestkit, a6 as mergeSnapshots, a7 as principalFromClaims, a8 as readCoverageDirectory, a9 as resolveSeed, aa as seedScenario, ab as startKindeTestkit } from './server-CLRn67qI.cjs';
|
|
3
3
|
import { ProtectedHeaderParameters, JWTPayload } from 'jose';
|
|
4
|
-
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-
|
|
4
|
+
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-DRPxm36j.cjs';
|
|
5
5
|
|
|
6
6
|
interface CreateKindeUserOptions {
|
|
7
7
|
id?: string;
|
|
@@ -113,7 +113,20 @@ declare function loadSeedFile(path: string): Promise<TestkitSeed>;
|
|
|
113
113
|
* Steps for signing in through the testkit with plain HTTP requests instead of a browser page.
|
|
114
114
|
* The Cypress commands use these. No Node APIs here, because Cypress bundles this file for the browser.
|
|
115
115
|
*/
|
|
116
|
-
|
|
116
|
+
/** What the social provider does when the user picks it on the sign-in page. */
|
|
117
|
+
type ProviderResult = "success" | "cancelled" | "error";
|
|
118
|
+
/** What happens at the multi-factor authentication step. */
|
|
119
|
+
type MfaOutcome = "none" | "passed" | "failed" | "cancelled";
|
|
120
|
+
/** How the user signs in on the testkit page. */
|
|
121
|
+
interface SignInMethodOptions {
|
|
122
|
+
/** "email" (the default), or a social provider such as "google", "github" or "microsoft". */
|
|
123
|
+
connection?: string;
|
|
124
|
+
/** For a social provider: "success" (the default), "cancelled" by the user, or a provider "error". */
|
|
125
|
+
providerResult?: ProviderResult;
|
|
126
|
+
/** Multi-factor authentication: "none" (the default), "passed", "failed" with a wrong code, or "cancelled". */
|
|
127
|
+
mfa?: MfaOutcome;
|
|
128
|
+
}
|
|
129
|
+
interface RequestSignInOptions extends SignInMethodOptions {
|
|
117
130
|
/** Email address or ID of the user. */
|
|
118
131
|
user: string;
|
|
119
132
|
/** Active organization, for users in more than one. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, S as Scenario
|
|
2
|
-
export {
|
|
3
|
-
export { A as ActivityLog, C as COVERAGE_GROUPS, a as CoverageGroup, b as CoverageGroupResult, c as CoverageItem, d as CoverageRecorder, e as CoverageReport, f as CoverageSnapshot, D as DEFAULT_COVERAGE_DIRECTORY, g as DeviceFlowOptions,
|
|
1
|
+
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, S as Scenario } from './testkit-BvCAFsSj.js';
|
|
2
|
+
export { D as DEFAULT_AUTH_METHODS, d as DEFAULT_CLIENT_ID, e as DEFAULT_ISSUER, f as DEFAULT_M2M_CLIENT_ID, g as DEFAULT_SCOPES, h as Duration, I as INVALID_TOKEN_KINDS, i as IdTokenOptions, j as InvalidTokenKind, k as KindeApplication, l as KindePrincipal, m as KindeTestkit, n as KindeTestkitOptions, o as KindeTokenOptions, M as M2MTokenOptions, p as ScenarioTokenOverrides, T as TokenObserver, q as createKindeToken, r as getDefaultTestkit, s as principalFromClaims } from './testkit-BvCAFsSj.js';
|
|
3
|
+
export { A as ActivityLog, C as COVERAGE_GROUPS, a as CoverageGroup, b as CoverageGroupResult, c as CoverageItem, d as CoverageRecorder, e as CoverageReport, f as CoverageSnapshot, D as DEFAULT_COVERAGE_DIRECTORY, g as DeviceFlowOptions, R as RequestEntry, h as RunningKindeTestkit, S as StartKindeTestkitOptions, T as TokenEntry, i as buildReport, j as clearCoverageDirectory, k as formatCoverageReport, m as mergeSnapshots, r as readCoverageDirectory, s as startKindeTestkit } from './server-CuHAHsaN.js';
|
|
4
|
+
import { T as TestkitSeed } from './webhooks-CiK9_pVw.js';
|
|
5
|
+
export { A as ActiveFailure, B as BILLING_EVENT_TYPES, D as Directory, F as FailureInjector, a as FailureRule, R as ResolvedSeed, S as SendWebhookOptions, W as WEBHOOK_EVENT_TYPES, b as WebhookAttempt, c as WebhookDelivery, d as WebhookDispatcher, e as WebhookEndpoint, f as WebhookEndpointInput, g as WebhookInvalidKind, h as WebhookOptions, i as WebhookSource, r as resolveSeed, s as seedScenario } from './webhooks-CiK9_pVw.js';
|
|
4
6
|
import { ProtectedHeaderParameters, JWTPayload } from 'jose';
|
|
5
|
-
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-
|
|
7
|
+
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-Pjt9fSUq.js';
|
|
8
|
+
export { R as RequestSignInOptions, a as appLoginUrl, r as readSignInRequest, b as resolveLocation, s as signInFailure, c as signInForm } from './sign-in-flow-DNrDXSLI.js';
|
|
6
9
|
|
|
7
10
|
interface CreateKindeUserOptions {
|
|
8
11
|
id?: string;
|
|
@@ -110,25 +113,4 @@ declare function findSeedFile(directory?: string): string | undefined;
|
|
|
110
113
|
*/
|
|
111
114
|
declare function loadSeedFile(path: string): Promise<TestkitSeed>;
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
* Steps for signing in through the testkit with plain HTTP requests instead of a browser page.
|
|
115
|
-
* The Cypress commands use these. No Node APIs here, because Cypress bundles this file for the browser.
|
|
116
|
-
*/
|
|
117
|
-
interface RequestSignInOptions {
|
|
118
|
-
/** Email address or ID of the user. */
|
|
119
|
-
user: string;
|
|
120
|
-
/** Active organization, for users in more than one. */
|
|
121
|
-
org?: string;
|
|
122
|
-
}
|
|
123
|
-
/** The app's login route, with the hints the testkit sign-in page reads. */
|
|
124
|
-
declare function appLoginUrl(loginPath: string, options: RequestSignInOptions): string;
|
|
125
|
-
/** Reads the hidden request field from the testkit sign-in page. */
|
|
126
|
-
declare function readSignInRequest(html: string): string;
|
|
127
|
-
/** The form the sign-in page posts to /oauth2/auth/login. */
|
|
128
|
-
declare function signInForm(request: string, options: RequestSignInOptions): Record<string, string>;
|
|
129
|
-
/** Explains why the testkit did not redirect back to the app after the form was posted. */
|
|
130
|
-
declare function signInFailure(status: number, html: string, options: RequestSignInOptions): Error;
|
|
131
|
-
/** Resolves a Location header, which can be relative, against the URL that sent it. */
|
|
132
|
-
declare function resolveLocation(location: string, from: string): string;
|
|
133
|
-
|
|
134
|
-
export { AuthenticatedScenario, type Check, type CheckStatus, type CreateKindeOrganizationOptions, type CreateKindeUserOptions, type CreateMembershipOptions, DEFAULT_SEED_FILES, type DoctorReport, KindeMembership, KindeOrganization, KindeRole, KindeUser, type LocalCertificate, type RequestSignInOptions, Scenario, ScenarioBuilder, TestkitError, type TestkitErrorCode, TestkitSeed, type TokenInspection, UnauthenticatedScenario, appLoginUrl, createKindeOrganization, createKindeUser, createLocalCertificate, createMembership, ensureLocalCertificate, findSeedFile, inspectToken, isAuthenticated, loadSeedFile, parseEnvFile, readSignInRequest, resetFactories, resolveLocation, runDoctor, scenario, signInFailure, signInForm, toKindeRole };
|
|
116
|
+
export { AuthenticatedScenario, type Check, type CheckStatus, type CreateKindeOrganizationOptions, type CreateKindeUserOptions, type CreateMembershipOptions, DEFAULT_SEED_FILES, type DoctorReport, KindeMembership, KindeOrganization, KindeRole, KindeUser, type LocalCertificate, Scenario, ScenarioBuilder, TestkitError, type TestkitErrorCode, TestkitSeed, type TokenInspection, UnauthenticatedScenario, createKindeOrganization, createKindeUser, createLocalCertificate, createMembership, ensureLocalCertificate, findSeedFile, inspectToken, isAuthenticated, loadSeedFile, parseEnvFile, resetFactories, runDoctor, scenario, toKindeRole };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
kindeTest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YJPE5HAM.js";
|
|
4
|
+
import {
|
|
5
|
+
appLoginUrl,
|
|
6
|
+
readSignInRequest,
|
|
7
|
+
resolveLocation,
|
|
8
|
+
signInFailure,
|
|
9
|
+
signInForm
|
|
10
|
+
} from "./chunk-EZUKOKNO.js";
|
|
4
11
|
import {
|
|
5
12
|
inspectToken,
|
|
6
13
|
parseEnvFile,
|
|
@@ -11,41 +18,43 @@ import {
|
|
|
11
18
|
BILLING_EVENT_TYPES,
|
|
12
19
|
COVERAGE_GROUPS,
|
|
13
20
|
CoverageRecorder,
|
|
14
|
-
DEFAULT_AUTH_METHODS,
|
|
15
|
-
DEFAULT_CLIENT_ID,
|
|
16
21
|
DEFAULT_COVERAGE_DIRECTORY,
|
|
17
|
-
DEFAULT_ISSUER,
|
|
18
|
-
DEFAULT_M2M_CLIENT_ID,
|
|
19
|
-
DEFAULT_SCOPES,
|
|
20
22
|
DEFAULT_SEED_FILES,
|
|
21
23
|
Directory,
|
|
22
24
|
FailureInjector,
|
|
23
|
-
INVALID_TOKEN_KINDS,
|
|
24
|
-
KindeTestkit,
|
|
25
|
-
TestkitError,
|
|
26
25
|
WEBHOOK_EVENT_TYPES,
|
|
27
26
|
WebhookDispatcher,
|
|
28
27
|
buildReport,
|
|
29
28
|
clearCoverageDirectory,
|
|
30
|
-
createKindeOrganization,
|
|
31
|
-
createKindeToken,
|
|
32
|
-
createKindeUser,
|
|
33
29
|
createLocalCertificate,
|
|
34
|
-
createMembership,
|
|
35
30
|
ensureLocalCertificate,
|
|
36
31
|
findSeedFile,
|
|
37
32
|
formatCoverageReport,
|
|
38
|
-
getDefaultTestkit,
|
|
39
33
|
loadSeedFile,
|
|
40
34
|
mergeSnapshots,
|
|
41
|
-
principalFromClaims,
|
|
42
35
|
readCoverageDirectory,
|
|
43
|
-
resetFactories,
|
|
44
36
|
resolveSeed,
|
|
45
37
|
seedScenario,
|
|
46
|
-
startKindeTestkit
|
|
38
|
+
startKindeTestkit
|
|
39
|
+
} from "./chunk-CY75AADD.js";
|
|
40
|
+
import {
|
|
41
|
+
DEFAULT_AUTH_METHODS,
|
|
42
|
+
DEFAULT_CLIENT_ID,
|
|
43
|
+
DEFAULT_ISSUER,
|
|
44
|
+
DEFAULT_M2M_CLIENT_ID,
|
|
45
|
+
DEFAULT_SCOPES,
|
|
46
|
+
INVALID_TOKEN_KINDS,
|
|
47
|
+
KindeTestkit,
|
|
48
|
+
TestkitError,
|
|
49
|
+
createKindeOrganization,
|
|
50
|
+
createKindeToken,
|
|
51
|
+
createKindeUser,
|
|
52
|
+
createMembership,
|
|
53
|
+
getDefaultTestkit,
|
|
54
|
+
principalFromClaims,
|
|
55
|
+
resetFactories,
|
|
47
56
|
toKindeRole
|
|
48
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-BPPG4G52.js";
|
|
49
58
|
|
|
50
59
|
// src/scenario.ts
|
|
51
60
|
var ScenarioBuilder = class {
|
|
@@ -103,39 +112,6 @@ function scenario() {
|
|
|
103
112
|
function isAuthenticated(value) {
|
|
104
113
|
return value.kind === "authenticated";
|
|
105
114
|
}
|
|
106
|
-
|
|
107
|
-
// src/sign-in-flow.ts
|
|
108
|
-
function appLoginUrl(loginPath, options) {
|
|
109
|
-
const params = new URLSearchParams({ login_hint: options.user });
|
|
110
|
-
if (options.org) params.set("org_code", options.org);
|
|
111
|
-
return `${loginPath}${loginPath.includes("?") ? "&" : "?"}${params}`;
|
|
112
|
-
}
|
|
113
|
-
function readSignInRequest(html) {
|
|
114
|
-
const match = /name="request" value="([^"]+)"/.exec(html);
|
|
115
|
-
if (!match) {
|
|
116
|
-
throw new Error("The page is not the kinde-testkit sign-in page. Check that the app's KINDE_ISSUER_URL points at the testkit.");
|
|
117
|
-
}
|
|
118
|
-
return decodeEntities(match[1]);
|
|
119
|
-
}
|
|
120
|
-
function signInForm(request, options) {
|
|
121
|
-
const form = { request, email: options.user };
|
|
122
|
-
if (options.org) form.org = options.org;
|
|
123
|
-
return form;
|
|
124
|
-
}
|
|
125
|
-
function signInFailure(status, html, options) {
|
|
126
|
-
if (status === 200 && html.includes("Choose an organization")) {
|
|
127
|
-
return new Error(`${options.user} belongs to more than one organization. Pass one with { org: "org_..." }.`);
|
|
128
|
-
}
|
|
129
|
-
const alert = /role="alert"[^>]*>([\s\S]*?)<\//.exec(html)?.[1];
|
|
130
|
-
const text = alert ? decodeEntities(alert.replace(/<[^>]+>/g, "")).trim() : `the sign-in page answered ${status}`;
|
|
131
|
-
return new Error(`kinde-testkit refused the sign-in: ${text}`);
|
|
132
|
-
}
|
|
133
|
-
function resolveLocation(location, from) {
|
|
134
|
-
return new URL(location, from).toString();
|
|
135
|
-
}
|
|
136
|
-
function decodeEntities(value) {
|
|
137
|
-
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
138
|
-
}
|
|
139
115
|
export {
|
|
140
116
|
ActivityLog,
|
|
141
117
|
BILLING_EVENT_TYPES,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scenario.ts"
|
|
1
|
+
{"version":3,"sources":["../src/scenario.ts"],"sourcesContent":["import type {\n AuthenticatedScenario,\n KindeOrganization,\n KindeUser,\n Scenario,\n UnauthenticatedScenario,\n} from \"./types.js\";\nimport {\n createKindeOrganization,\n createKindeUser,\n type CreateKindeOrganizationOptions,\n type CreateKindeUserOptions,\n} from \"./factories.js\";\n\nexport class ScenarioBuilder {\n private userValue: KindeUser | null = null;\n private organizationValue: KindeOrganization | null = null;\n private rolesValue: string[] = [];\n private permissionsValue: string[] = [];\n private claimsValue: Record<string, unknown> = {};\n\n user(user: CreateKindeUserOptions | KindeUser = {}): this {\n this.userValue = createKindeUser(user);\n return this;\n }\n\n organization(organization: string | CreateKindeOrganizationOptions | KindeOrganization): this {\n this.organizationValue = createKindeOrganization(\n typeof organization === \"string\" ? { code: organization } : organization,\n );\n return this;\n }\n\n withoutOrganization(): this {\n this.organizationValue = null;\n return this;\n }\n\n role(...roles: string[]): this {\n return this.roles(roles);\n }\n\n roles(roles: string[]): this {\n this.rolesValue = [...new Set([...this.rolesValue, ...roles])];\n return this;\n }\n\n permissions(permissions: string[]): this {\n this.permissionsValue = [...new Set([...this.permissionsValue, ...permissions])];\n return this;\n }\n\n claims(claims: Record<string, unknown>): this {\n this.claimsValue = { ...this.claimsValue, ...claims };\n return this;\n }\n\n authenticated(): AuthenticatedScenario {\n return {\n kind: \"authenticated\",\n user: this.userValue ?? createKindeUser(),\n organization: this.organizationValue,\n roles: [...this.rolesValue],\n permissions: [...this.permissionsValue],\n claims: { ...this.claimsValue },\n };\n }\n\n unauthenticated(): UnauthenticatedScenario {\n return { kind: \"unauthenticated\" };\n }\n}\n\nexport function scenario(): ScenarioBuilder {\n return new ScenarioBuilder();\n}\n\nexport function isAuthenticated(value: Scenario): value is AuthenticatedScenario {\n return value.kind === \"authenticated\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,IAAM,kBAAN,MAAsB;AAAA,EACnB,YAA8B;AAAA,EAC9B,oBAA8C;AAAA,EAC9C,aAAuB,CAAC;AAAA,EACxB,mBAA6B,CAAC;AAAA,EAC9B,cAAuC,CAAC;AAAA,EAEhD,KAAK,OAA2C,CAAC,GAAS;AACxD,SAAK,YAAY,gBAAgB,IAAI;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,cAAiF;AAC5F,SAAK,oBAAoB;AAAA,MACvB,OAAO,iBAAiB,WAAW,EAAE,MAAM,aAAa,IAAI;AAAA,IAC9D;AACA,WAAO;AAAA,EACT;AAAA,EAEA,sBAA4B;AAC1B,SAAK,oBAAoB;AACzB,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,OAAuB;AAC7B,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEA,MAAM,OAAuB;AAC3B,SAAK,aAAa,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,KAAK,YAAY,GAAG,KAAK,CAAC,CAAC;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,aAA6B;AACvC,SAAK,mBAAmB,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,KAAK,kBAAkB,GAAG,WAAW,CAAC,CAAC;AAC/E,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,QAAuC;AAC5C,SAAK,cAAc,EAAE,GAAG,KAAK,aAAa,GAAG,OAAO;AACpD,WAAO;AAAA,EACT;AAAA,EAEA,gBAAuC;AACrC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM,KAAK,aAAa,gBAAgB;AAAA,MACxC,cAAc,KAAK;AAAA,MACnB,OAAO,CAAC,GAAG,KAAK,UAAU;AAAA,MAC1B,aAAa,CAAC,GAAG,KAAK,gBAAgB;AAAA,MACtC,QAAQ,EAAE,GAAG,KAAK,YAAY;AAAA,IAChC;AAAA,EACF;AAAA,EAEA,kBAA2C;AACzC,WAAO,EAAE,MAAM,kBAAkB;AAAA,EACnC;AACF;AAEO,SAAS,WAA4B;AAC1C,SAAO,IAAI,gBAAgB;AAC7B;AAEO,SAAS,gBAAgB,OAAiD;AAC/E,SAAO,MAAM,SAAS;AACxB;","names":[]}
|