@jskit-ai/auth-web 0.2.11 → 0.2.13
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 +9 -0
- package/fixtures/sign-in/main.js +3 -2
- package/locales/en.json +13 -3
- package/package.json +10 -9
- package/src/client/composables/loginView/confirmationLink.js +38 -0
- package/src/client/composables/loginView/useLoginViewActions.js +84 -7
- package/src/client/composables/loginView/useLoginViewState.js +20 -1
- package/src/client/composables/loginView/useLoginViewValidation.js +3 -0
- package/src/client/runtime/useLoginView.js +8 -0
- package/src/client/views/AuthProfileWidget.vue +2 -8
- package/src/client/views/DefaultLoginView.vue +102 -41
- package/src/client/views/DefaultResetPasswordView.vue +2 -3
- package/src/client/views/DefaultSignOutView.vue +5 -6
- package/src/server/AuthWebFeature.js +4 -2
- package/src/server/authRateLimits.js +59 -0
- package/src/server/authWeb.js +5 -2
- package/src/server/constants/authActionIds.js +1 -0
- package/src/server/controllers/AuthController.js +18 -1
- package/src/server/routes/authRoutes.js +38 -46
- package/src/server/services/AuthWebService.js +7 -0
- package/test/authRateLimits.test.js +92 -0
- package/test/clientSurface.test.js +7 -3
- package/test/loginViewActions.test.js +45 -0
- package/test/providerRuntime.test.js +64 -0
- package/test/signIn.browser.test.js +128 -5
|
@@ -34,6 +34,13 @@ class AuthWebService {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
async confirmRegistration(request, payload) {
|
|
38
|
+
return request.executeAction({
|
|
39
|
+
actionId: AUTH_ACTION_IDS.REGISTER_CONFIRM,
|
|
40
|
+
input: payload
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
async login(request, payload) {
|
|
38
45
|
return request.executeAction({
|
|
39
46
|
actionId: AUTH_ACTION_IDS.LOGIN_PASSWORD,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import Fastify from "fastify";
|
|
4
|
+
import { ActionProvider } from "@jskit-ai/kernel/server/actions";
|
|
5
|
+
import { HttpProvider } from "@jskit-ai/kernel/server/http";
|
|
6
|
+
import { AppError, EventProvider } from "@jskit-ai/kernel/server/runtime";
|
|
7
|
+
import { silentLogger } from "@jskit-ai/kernel/server/runtime/logger";
|
|
8
|
+
import { createCapabilityRuntime } from "@jskit-ai/kernel/shared/capabilities";
|
|
9
|
+
import { AuthFeature } from "@jskit-ai/auth-core/server/providers/AuthFeature";
|
|
10
|
+
import { AuthWebFeature } from "../src/server/AuthWebFeature.js";
|
|
11
|
+
import { DEFAULT_AUTH_RATE_LIMITS, resolveAuthRateLimits } from "../src/server/authRateLimits.js";
|
|
12
|
+
|
|
13
|
+
/** An auth service whose every sign-in is a wrong password. */
|
|
14
|
+
function createRefusingAuthService() {
|
|
15
|
+
return {
|
|
16
|
+
async login() {
|
|
17
|
+
throw new AppError(401, "Invalid email or password.", { code: "auth.login.invalidCredentials" });
|
|
18
|
+
},
|
|
19
|
+
async authenticateRequest() {
|
|
20
|
+
return { authenticated: false };
|
|
21
|
+
},
|
|
22
|
+
getCapabilities() {
|
|
23
|
+
return { provider: { id: "local", label: "Local" }, features: {} };
|
|
24
|
+
},
|
|
25
|
+
writeSessionCookies() {},
|
|
26
|
+
clearSessionCookies() {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function startAuthWeb(t, config = {}) {
|
|
31
|
+
const app = Fastify();
|
|
32
|
+
const runtime = createCapabilityRuntime({
|
|
33
|
+
inputs: {
|
|
34
|
+
"auth.service": createRefusingAuthService(),
|
|
35
|
+
"runtime.config": config,
|
|
36
|
+
"runtime.env": { NODE_ENV: "test" },
|
|
37
|
+
"runtime.fastify": app,
|
|
38
|
+
"runtime.logger": silentLogger
|
|
39
|
+
},
|
|
40
|
+
providers: [EventProvider, ActionProvider, HttpProvider, AuthFeature, AuthWebFeature]
|
|
41
|
+
});
|
|
42
|
+
await runtime.start();
|
|
43
|
+
t.after(async () => {
|
|
44
|
+
await runtime.shutdown();
|
|
45
|
+
await app.close();
|
|
46
|
+
});
|
|
47
|
+
return app;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function signInAttempts(app, count, remoteAddress = "203.0.113.7") {
|
|
51
|
+
const statuses = [];
|
|
52
|
+
let lastResponse = null;
|
|
53
|
+
for (let attempt = 0; attempt < count; attempt += 1) {
|
|
54
|
+
lastResponse = await app.inject({
|
|
55
|
+
method: "POST",
|
|
56
|
+
url: "/api/login",
|
|
57
|
+
remoteAddress,
|
|
58
|
+
payload: { email: "ada@example.com", password: `guess number ${attempt}` }
|
|
59
|
+
});
|
|
60
|
+
statuses.push(lastResponse.statusCode);
|
|
61
|
+
}
|
|
62
|
+
return { statuses, lastResponse };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test("25 rapid wrong-password sign-ins from one address are refused after the login limit", async (t) => {
|
|
66
|
+
const app = await startAuthWeb(t);
|
|
67
|
+
const { statuses, lastResponse } = await signInAttempts(app, 25);
|
|
68
|
+
|
|
69
|
+
const allowed = DEFAULT_AUTH_RATE_LIMITS.login.max;
|
|
70
|
+
assert.deepEqual(statuses.slice(0, allowed), Array(allowed).fill(401));
|
|
71
|
+
assert.deepEqual(statuses.slice(allowed), Array(25 - allowed).fill(429));
|
|
72
|
+
assert.equal(lastResponse.json().code, "kernel.http.rateLimited");
|
|
73
|
+
assert.ok(Number(lastResponse.headers["retry-after"]) > 0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("config.auth.rateLimits changes a route's limit, and false removes it", async (t) => {
|
|
77
|
+
const tighter = await startAuthWeb(t, { auth: { rateLimits: { login: { max: 3 } } } });
|
|
78
|
+
assert.deepEqual((await signInAttempts(tighter, 5)).statuses, [401, 401, 401, 429, 429]);
|
|
79
|
+
|
|
80
|
+
const unlimited = await startAuthWeb(t, { auth: { rateLimits: { login: false } } });
|
|
81
|
+
assert.deepEqual((await signInAttempts(unlimited, 15)).statuses, Array(15).fill(401));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("a misspelt or malformed rate limit override stops startup", () => {
|
|
85
|
+
assert.throws(() => resolveAuthRateLimits({ auth: { rateLimits: { signIn: { max: 3 } } } }),
|
|
86
|
+
/config\.auth\.rateLimits\.signIn names no auth route/u);
|
|
87
|
+
assert.throws(() => resolveAuthRateLimits({ auth: { rateLimits: { login: 3 } } }),
|
|
88
|
+
/config\.auth\.rateLimits\.login must be \{ max, timeWindow \} or false/u);
|
|
89
|
+
assert.throws(() => resolveAuthRateLimits({ auth: { rateLimits: [] } }),
|
|
90
|
+
/config\.auth\.rateLimits must be an object/u);
|
|
91
|
+
assert.equal(resolveAuthRateLimits({}).login, DEFAULT_AUTH_RATE_LIMITS.login);
|
|
92
|
+
});
|
|
@@ -70,12 +70,15 @@ test("auth-web client capability includes mobile callback completion", () => {
|
|
|
70
70
|
assert.match(authClientSource, /completeOAuthCallbackFromUrl/);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
test("auth profile activator
|
|
73
|
+
test("auth profile activator keeps Material 3's 48dp touch target without a fixed height", () => {
|
|
74
74
|
const widgetPath = fileURLToPath(new URL("../src/client/views/AuthProfileWidget.vue", import.meta.url));
|
|
75
75
|
const widgetSource = readFileSync(widgetPath, "utf8");
|
|
76
76
|
|
|
77
77
|
assert.match(widgetSource, /class="auth-profile-widget__activator text-none pl-1 pr-2"/);
|
|
78
|
-
|
|
78
|
+
// material-web gives every default-size button a 48dp touch target around its 40dp body; a fixed height would
|
|
79
|
+
// make the button itself taller than Material 3 draws it.
|
|
80
|
+
assert.doesNotMatch(widgetSource, /min-height/u);
|
|
81
|
+
assert.doesNotMatch(widgetSource, /<v-btn[^>]*auth-profile-widget__activator[^>]*\ssize=/u);
|
|
79
82
|
});
|
|
80
83
|
|
|
81
84
|
test("default login view owns the viewport and becomes a full-screen mobile screen", () => {
|
|
@@ -90,7 +93,8 @@ test("default login view owns the viewport and becomes a full-screen mobile scre
|
|
|
90
93
|
assert.match(viewSource, /auth-card--mobile/);
|
|
91
94
|
assert.match(viewSource, /auth-content--mobile/);
|
|
92
95
|
assert.match(viewSource, /:elevation="isMobileViewport \? 0 : 1"/);
|
|
93
|
-
|
|
96
|
+
// An elevated Material 3 card on wide windows, the whole screen on phones; never an outlined one.
|
|
97
|
+
assert.doesNotMatch(viewSource, /:border=|\sborder(?=[\s>])/);
|
|
94
98
|
assert.match(viewSource, /\.login-screen\s*\{[\s\S]*position:\s*fixed;/);
|
|
95
99
|
// The full-viewport screen starts below shell banners shown on this bar-less surface.
|
|
96
100
|
assert.match(viewSource, /\.login-screen\s*\{[\s\S]*inset:\s*var\(--shell-error-banners-inline-height, 0px\) 0 0;/);
|
|
@@ -36,6 +36,11 @@ function createMinimalLoginViewState(requestedReturnTo = "/") {
|
|
|
36
36
|
otpRequestPending: { value: false },
|
|
37
37
|
registerConfirmationResendPending: { value: false },
|
|
38
38
|
pendingEmailConfirmationAddress: { value: "" },
|
|
39
|
+
isEmailConfirmationPending: { value: false },
|
|
40
|
+
registrationConfirmPending: { value: false },
|
|
41
|
+
confirmationUrl: { value: "" },
|
|
42
|
+
confirmationCode: { value: "" },
|
|
43
|
+
setupCode: { value: "" },
|
|
39
44
|
invitationToken: { value: "" },
|
|
40
45
|
rememberAccountOnDevice: { value: true },
|
|
41
46
|
oauthProviders: { value: [] },
|
|
@@ -342,3 +347,43 @@ test("OAuth buttons name their provider in the sign-in sentence", () => {
|
|
|
342
347
|
state.isRegister.value = true;
|
|
343
348
|
assert.equal(actions.oauthProviderButtonLabel(github), "Register with GitHub");
|
|
344
349
|
});
|
|
350
|
+
|
|
351
|
+
for (const refusal of [
|
|
352
|
+
{
|
|
353
|
+
name: "the route's rate limit",
|
|
354
|
+
payload: { error: "Too many requests. Try again in 42 seconds.", code: "kernel.http.rateLimited", params: { count: 42 } }
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: "the account's failed sign-ins",
|
|
358
|
+
payload: {
|
|
359
|
+
error: "Too many failed sign-ins for this account. Try again in 2 minutes.",
|
|
360
|
+
code: "auth.local.login.locked",
|
|
361
|
+
params: { count: 2, retryAfterSeconds: 90 }
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
]) {
|
|
365
|
+
test(`a sign-in refused by ${refusal.name} says how long to wait`, async (t) => {
|
|
366
|
+
clearAuthCsrfTokenCache();
|
|
367
|
+
t.after(clearAuthCsrfTokenCache);
|
|
368
|
+
const state = createMinimalLoginViewState("/");
|
|
369
|
+
const reports = [];
|
|
370
|
+
t.mock.method(globalThis, "fetch", async (url, options = {}) => {
|
|
371
|
+
if (url === "/api/session") {
|
|
372
|
+
return createJsonResponse({ authenticated: false, csrfToken: "csrf-a" });
|
|
373
|
+
}
|
|
374
|
+
assert.equal(`${options.method} ${url}`, "POST /api/login");
|
|
375
|
+
return createJsonResponse(refusal.payload, { status: 429 });
|
|
376
|
+
});
|
|
377
|
+
const actions = useLoginViewActions({
|
|
378
|
+
state,
|
|
379
|
+
validation: { canSubmit: { value: true } },
|
|
380
|
+
queryClient: { fetchQuery: ({ queryFn }) => queryFn() },
|
|
381
|
+
errorRuntime: { report: (entry) => reports.push(entry) }
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
await actions.submitAuth();
|
|
385
|
+
|
|
386
|
+
assert.equal(state.errorMessage.value, refusal.payload.error);
|
|
387
|
+
assert.equal(reports[0]?.message, refusal.payload.error);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
@@ -16,6 +16,7 @@ function createFastifyStub() {
|
|
|
16
16
|
addHook(name, handler) {
|
|
17
17
|
this.hooks.push({ name, handler });
|
|
18
18
|
},
|
|
19
|
+
async register() {},
|
|
19
20
|
route(definition) {
|
|
20
21
|
this.routes.push(definition);
|
|
21
22
|
},
|
|
@@ -108,6 +109,7 @@ async function startAuthWeb({ env = {}, authService = null } = {}) {
|
|
|
108
109
|
inputs: {
|
|
109
110
|
"runtime.logger": silentLogger,
|
|
110
111
|
"auth.service": authService || createAuthService(),
|
|
112
|
+
"runtime.config": {},
|
|
111
113
|
"runtime.env": { NODE_ENV: "test", ...env },
|
|
112
114
|
"runtime.fastify": fastify
|
|
113
115
|
},
|
|
@@ -157,3 +159,65 @@ test("auth session route returns provider capabilities", async () => {
|
|
|
157
159
|
assert.equal(reply.payload.authCapabilities.provider.id, "local");
|
|
158
160
|
assert.equal(reply.payload.authCapabilities.features.password.register, true);
|
|
159
161
|
});
|
|
162
|
+
|
|
163
|
+
test("registration confirmation: the register answer carries the development link, and confirming signs the person in", async () => {
|
|
164
|
+
const events = [];
|
|
165
|
+
const authService = {
|
|
166
|
+
...createAuthService(events),
|
|
167
|
+
async register(input) {
|
|
168
|
+
return {
|
|
169
|
+
actor: null,
|
|
170
|
+
session: null,
|
|
171
|
+
requiresEmailConfirmation: true,
|
|
172
|
+
email: input.email,
|
|
173
|
+
confirmationUrl: "http://localhost:5173/auth/login?confirmation_token=dev-token"
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
async confirmRegistration(input) {
|
|
177
|
+
events.push({ type: "confirm", token: input.token });
|
|
178
|
+
return {
|
|
179
|
+
actor: { displayName: "Ada", email: "ada@example.com" },
|
|
180
|
+
session: { access_token: "confirm-a", refresh_token: "confirm-r" }
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const { fastify } = await startAuthWeb({ authService });
|
|
185
|
+
const route = (url) => fastify.routes.find((entry) => entry.method === "POST" && entry.url === url);
|
|
186
|
+
|
|
187
|
+
const registerReply = createReplyStub();
|
|
188
|
+
await route("/api/register").handler(
|
|
189
|
+
{ body: { email: "ada@example.com", password: "correct horse battery staple" } },
|
|
190
|
+
registerReply
|
|
191
|
+
);
|
|
192
|
+
assert.equal(registerReply.statusCode, 201);
|
|
193
|
+
assert.deepEqual(registerReply.payload, {
|
|
194
|
+
ok: true,
|
|
195
|
+
requiresEmailConfirmation: true,
|
|
196
|
+
message: "Check your email to confirm the account before logging in.",
|
|
197
|
+
messageCode: "auth.register.confirmEmail",
|
|
198
|
+
messageParams: {},
|
|
199
|
+
confirmationUrl: "http://localhost:5173/auth/login?confirmation_token=dev-token"
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const confirmRoute = route("/api/register/confirm");
|
|
203
|
+
assert.deepEqual(confirmRoute.config.rateLimit, { max: 10, timeWindow: 60_000 });
|
|
204
|
+
const confirmReply = createReplyStub();
|
|
205
|
+
await confirmRoute.handler({ body: { token: "dev-token" } }, confirmReply);
|
|
206
|
+
assert.equal(confirmReply.statusCode, 200);
|
|
207
|
+
assert.deepEqual(confirmReply.payload, {
|
|
208
|
+
ok: true,
|
|
209
|
+
email: "ada@example.com",
|
|
210
|
+
username: "Ada",
|
|
211
|
+
message: "Your email is confirmed.",
|
|
212
|
+
messageCode: "auth.register.confirmed",
|
|
213
|
+
messageParams: {}
|
|
214
|
+
});
|
|
215
|
+
// Registering wrote no session; confirming wrote the new one.
|
|
216
|
+
assert.deepEqual(
|
|
217
|
+
events.filter((entry) => entry.type === "confirm" || (entry.type === "writeSession" && entry.session)),
|
|
218
|
+
[
|
|
219
|
+
{ type: "confirm", token: "dev-token" },
|
|
220
|
+
{ type: "writeSession", session: { access_token: "confirm-a", refresh_token: "confirm-r" } }
|
|
221
|
+
]
|
|
222
|
+
);
|
|
223
|
+
});
|
|
@@ -53,7 +53,7 @@ async function openApp({ session = SIGNED_OUT, routes = {}, viewport = { width:
|
|
|
53
53
|
const page = await browser.newPage({ baseURL: runtime.baseURL, viewport });
|
|
54
54
|
page.setDefaultTimeout(15_000);
|
|
55
55
|
page.setDefaultNavigationTimeout(60_000);
|
|
56
|
-
const api = { session, requests: [], unexpected: [], errors: [], page };
|
|
56
|
+
const api = { session, routes, requests: [], unexpected: [], errors: [], page };
|
|
57
57
|
page.on("pageerror", (error) => api.errors.push(error.message));
|
|
58
58
|
await page.route("**/api/**", async (route) => {
|
|
59
59
|
const request = route.request();
|
|
@@ -64,12 +64,13 @@ async function openApp({ session = SIGNED_OUT, routes = {}, viewport = { width:
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
api.requests.push({ key, search, body: request.postDataJSON(), csrf: request.headers()["csrf-token"] });
|
|
67
|
-
|
|
67
|
+
const answerFor = api.routes[key];
|
|
68
|
+
if (!answerFor) {
|
|
68
69
|
api.unexpected.push(key);
|
|
69
70
|
await route.fulfill({ status: 500, json: { error: `unexpected ${key}` } });
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
|
-
const answer = typeof
|
|
73
|
+
const answer = typeof answerFor === "function" ? answerFor(request.postDataJSON()) : answerFor;
|
|
73
74
|
await route.fulfill(answer);
|
|
74
75
|
});
|
|
75
76
|
return api;
|
|
@@ -85,6 +86,11 @@ function reports(page) {
|
|
|
85
86
|
return page.evaluate(() => window.authFixture.reports);
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
// The page itself, not a sign-in page whose returnTo=/home also ends the address.
|
|
90
|
+
function waitForHome(page) {
|
|
91
|
+
return page.waitForURL((url) => url.pathname === "/home");
|
|
92
|
+
}
|
|
93
|
+
|
|
88
94
|
async function signIn(page, email, password) {
|
|
89
95
|
await page.getByLabel("Email").fill(email);
|
|
90
96
|
await page.getByLabel("Password", { exact: true }).fill(password);
|
|
@@ -175,7 +181,7 @@ test("a signed-in visitor leaves the sign-in page, on opening it and when a sess
|
|
|
175
181
|
await expect(page.getByTestId("auth-submit")).toBeVisible();
|
|
176
182
|
api.session = SIGNED_IN;
|
|
177
183
|
await page.evaluate(() => window.dispatchEvent(new Event("focus")));
|
|
178
|
-
await page
|
|
184
|
+
await waitForHome(page);
|
|
179
185
|
await finish(api);
|
|
180
186
|
});
|
|
181
187
|
|
|
@@ -259,7 +265,124 @@ test("register waits for email confirmation, and the other modes reach their req
|
|
|
259
265
|
assert.deepEqual(api.requests.at(-1).body, { email: "ada@example.com", returnTo: "/home" });
|
|
260
266
|
await page.getByLabel("One-time code").fill("123456");
|
|
261
267
|
await page.getByTestId("auth-submit").click();
|
|
262
|
-
await page
|
|
268
|
+
await waitForHome(page);
|
|
269
|
+
await finish(api);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("email confirmation: the development link, a pasted link after an unconfirmed sign-in, and the emailed link", options, async () => {
|
|
273
|
+
const session = {
|
|
274
|
+
...SIGNED_OUT,
|
|
275
|
+
authCapabilities: { ...CAPABILITIES, features: { ...CAPABILITIES.features, emailConfirmationCode: true } }
|
|
276
|
+
};
|
|
277
|
+
const confirmations = [];
|
|
278
|
+
async function openConfirmingApp() {
|
|
279
|
+
const api = await openApp({ session });
|
|
280
|
+
Object.assign(api.routes, {
|
|
281
|
+
"POST /api/register": {
|
|
282
|
+
status: 201,
|
|
283
|
+
json: {
|
|
284
|
+
ok: true,
|
|
285
|
+
requiresEmailConfirmation: true,
|
|
286
|
+
message: "Check your email to confirm the account before logging in.",
|
|
287
|
+
messageCode: "auth.register.confirmEmail",
|
|
288
|
+
messageParams: {},
|
|
289
|
+
confirmationUrl: "http://localhost:5173/auth/login?confirmation_token=dev-token-1"
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
"POST /api/register/confirm": (body) => {
|
|
293
|
+
confirmations.push(body.token);
|
|
294
|
+
if (body.token === "expired-token") {
|
|
295
|
+
return {
|
|
296
|
+
status: 400,
|
|
297
|
+
json: {
|
|
298
|
+
error: "This confirmation link is invalid or has expired. Register again to get a new one.",
|
|
299
|
+
code: "auth.local.register.confirmationInvalid"
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
api.session = SIGNED_IN;
|
|
304
|
+
return { json: { ok: true, email: "ada@example.com", username: "Ada", message: "Your email is confirmed." } };
|
|
305
|
+
},
|
|
306
|
+
"POST /api/login": {
|
|
307
|
+
status: 403,
|
|
308
|
+
json: {
|
|
309
|
+
error: "Confirm your email address before signing in: open the link we emailed you, or ask for a new one.",
|
|
310
|
+
code: "auth.login.emailUnconfirmed"
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return api;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Registering in development shows the link, and its button confirms and signs in.
|
|
318
|
+
const registering = await openConfirmingApp();
|
|
319
|
+
await registering.page.goto("/auth/login?mode=register&returnTo=/home");
|
|
320
|
+
await registering.page.getByLabel("Email").fill("ada@example.com");
|
|
321
|
+
await registering.page.getByLabel("Password", { exact: true }).fill("Correct-horse-1");
|
|
322
|
+
await registering.page.getByLabel("Confirm password", { exact: true }).fill("Correct-horse-1");
|
|
323
|
+
await registering.page.getByTestId("auth-submit").click();
|
|
324
|
+
await expect(registering.page.getByTestId("auth-confirmation-dev-link")).toContainText("confirmation_token=dev-token-1");
|
|
325
|
+
await registering.page.getByTestId("auth-confirmation-dev-confirm").click();
|
|
326
|
+
await waitForHome(registering.page);
|
|
327
|
+
assert.deepEqual(confirmations, ["dev-token-1"]);
|
|
328
|
+
await finish(registering);
|
|
329
|
+
|
|
330
|
+
// Signing in before confirming opens "Confirm your email", where a pasted link confirms.
|
|
331
|
+
const signingIn = await openConfirmingApp();
|
|
332
|
+
await signingIn.page.goto("/auth/login?returnTo=/home");
|
|
333
|
+
await signIn(signingIn.page, "ada@example.com", "Correct-horse-1");
|
|
334
|
+
await expect(signingIn.page.getByText("Confirm your email", { exact: true })).toBeVisible();
|
|
335
|
+
await expect(signingIn.page.getByText("Confirm your email address before signing in")).toBeVisible();
|
|
336
|
+
await signingIn.page.getByLabel("Confirmation link or code").fill(
|
|
337
|
+
"http://localhost:5173/auth/login?confirmation_token=pasted-token-2"
|
|
338
|
+
);
|
|
339
|
+
await signingIn.page.getByLabel("Confirmation link or code").press("Enter");
|
|
340
|
+
await waitForHome(signingIn.page);
|
|
341
|
+
assert.deepEqual(confirmations.at(-1), "pasted-token-2");
|
|
342
|
+
await finish(signingIn);
|
|
343
|
+
|
|
344
|
+
// An emailed link confirms on opening; one that expired says so, and its code leaves the address.
|
|
345
|
+
const expired = await openConfirmingApp();
|
|
346
|
+
await expired.page.goto("/auth/login?confirmation_token=expired-token&returnTo=/home");
|
|
347
|
+
await expect.poll(async () => (await reports(expired.page)).at(-1)?.message)
|
|
348
|
+
.toBe("This confirmation link is invalid or has expired. Register again to get a new one.");
|
|
349
|
+
assert.equal(new URL(expired.page.url()).search, "?returnTo=%2Fhome");
|
|
350
|
+
await finish(expired);
|
|
351
|
+
const emailed = await openConfirmingApp();
|
|
352
|
+
await emailed.page.goto("/auth/login?confirmation_token=emailed-token-3&returnTo=/home");
|
|
353
|
+
await waitForHome(emailed.page);
|
|
354
|
+
assert.deepEqual(confirmations.slice(-2), ["expired-token", "emailed-token-3"]);
|
|
355
|
+
await finish(emailed);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test("while the app has no account, registering asks for the setup code and sends it", options, async () => {
|
|
359
|
+
const api = await openApp({
|
|
360
|
+
session: {
|
|
361
|
+
...SIGNED_OUT,
|
|
362
|
+
authCapabilities: { ...CAPABILITIES, features: { ...CAPABILITIES.features, firstAccountSetupCode: true } }
|
|
363
|
+
},
|
|
364
|
+
routes: {
|
|
365
|
+
"POST /api/register": () => {
|
|
366
|
+
api.session = SIGNED_IN;
|
|
367
|
+
return { status: 201, json: { ok: true, requiresEmailConfirmation: false, username: "Ada" } };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
const { page } = api;
|
|
372
|
+
await page.goto("/auth/login?mode=register&returnTo=/home");
|
|
373
|
+
await expect(page.getByTestId("auth-first-account-setup")).toContainText("This app has no account yet.");
|
|
374
|
+
await page.getByLabel("Email").fill("ada@example.com");
|
|
375
|
+
await page.getByLabel("Password", { exact: true }).fill("Correct-horse-1");
|
|
376
|
+
await page.getByLabel("Confirm password", { exact: true }).fill("Correct-horse-1");
|
|
377
|
+
await expect(page.getByTestId("auth-submit")).toBeDisabled();
|
|
378
|
+
await page.getByLabel("Setup code").fill("ABCDE-FGHJK-MNPQR-STVWX");
|
|
379
|
+
await page.getByTestId("auth-submit").click();
|
|
380
|
+
await waitForHome(page);
|
|
381
|
+
assert.deepEqual(api.requests.at(-1).body, {
|
|
382
|
+
email: "ada@example.com",
|
|
383
|
+
password: "Correct-horse-1",
|
|
384
|
+
setupCode: "ABCDE-FGHJK-MNPQR-STVWX"
|
|
385
|
+
});
|
|
263
386
|
await finish(api);
|
|
264
387
|
});
|
|
265
388
|
|