@jskit-ai/auth-web 0.2.43 → 0.2.45
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 +4 -0
- package/locales/en.json +7 -0
- package/package.json +31 -7
- package/patterns/auth-surface/PATTERN.md +10 -8
- package/patterns/auth-surface/example/src/pages/auth/email-change.vue +17 -0
- package/patterns/auth-surface/example/src/views/auth/EmailChangeView.vue +12 -0
- package/src/client/composables/loginView/useLoginViewState.js +1 -1
- package/src/client/composables/useDefaultEmailChangeView.js +28 -0
- package/src/client/index.js +4 -1
- package/src/client/runtime/emailChangeLink.js +36 -0
- package/src/client/views/AuthProfileWidget.vue +3 -2
- package/src/client/views/DefaultEmailChangeView.vue +53 -0
- package/src/server/AuthWebFeature.js +2 -0
- package/src/server/authRateLimits.js +3 -1
- package/src/server/routes/emailChangeRoutes.js +54 -0
- package/src/server/routes/passSignInRoutes.js +1 -1
- package/src/server/services/AuthWebService.js +3 -2
- package/test/authRateLimits.test.js +1 -1
- package/test/clientSurface.test.js +10 -1
- package/test/emailChangeClient.test.js +28 -0
- package/test/emailChangeRoutes.test.js +104 -0
- package/test/managedPreviewIdentity.test.js +6 -3
- package/test/passSignIn.browser.test.js +1 -1
- package/test/passSignInRoutes.test.js +13 -9
- package/test/providerRuntime.test.js +2 -2
- package/test/sameSiteStrict.browser.test.js +1 -1
- package/test/secondFactorRoutes.test.js +1 -1
- package/test/signIn.browser.test.js +36 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Up to medium width, the account control's avatar is hidden from assistive technology (`aria-hidden="true"`). That round button is named by the person's name, and the initials it shows ("AN" for ana.ferreira) were not in its name, which WCAG 2.5.3 Label in Name asks (axe `label-content-name-mismatch`); it now shows assistive technology no text beyond its name. On wider windows the control's name is the name it shows, as before.
|
|
6
|
+
- Email change over HTTP: `POST /api/email-change` (signed in, `{ email, password }`) asks for it and `POST /api/email-change/confirm` (public, `{ token }`) uses the link, each limited per address by `config.auth.rateLimits.emailChange` (5 a minute) and `emailChangeConfirm` (10 a minute). The page the link opens is `DefaultEmailChangeView` (`./client/views/DefaultEmailChangeView`, route component `auth-email-change`, the `auth.email-change` route at `/auth/email-change`, public, registered by an application's own page as the sign-in, reset and sign-out pages are): it confirms the link once, takes the token out of the address, and says the new email or why the link was refused (`jskit.auth.emailChange.*`).
|
|
7
|
+
- `POST /api/login/pass` hands `signInWithPass` the request that posted the pass, so local auth keeps the session's address and browser.
|
|
8
|
+
- Its tests name `APP_ENV`, which the auth providers now read in place of `NODE_ENV`; the setup-code field is asked for by a staging or production server.
|
|
5
9
|
- `POST /api/login/pass` reads its settings with `resolvePassSignInFromEnv` from `@jskit-ai/auth-pass/server`, a new dependency, instead of auth-core's removed `./server/passSignIn`. The route behaves as before.
|
|
6
10
|
|
|
7
11
|
- `POST /api/login/pass`, registered only while `AUTH_PASS_PUBLIC_KEY` is set: an issuer's page posts a one-time pass as the form field `pass`, and a pass that signs in sets the session cookies and answers 303 to `/`; a refused one answers 303 to `/auth/login` with `error=sign_in_unavailable`, `error_description` and `error_code`, which the sign-in page shows. It takes form bodies in a Fastify scope of its own, registered at boot, so the feature now requires `runtime.fastify`; it is public, takes no CSRF token (the pass authenticates it) and answers `Cache-Control: no-store`. Its rate limit is `config.auth.rateLimits.passSignIn` (20 a minute per address); one that no route limiter would enforce stops startup.
|
package/locales/en.json
CHANGED
|
@@ -112,6 +112,13 @@
|
|
|
112
112
|
"recoveryInvalid": "Recovery link is invalid or expired.",
|
|
113
113
|
"updateFailed": "Unable to update password."
|
|
114
114
|
},
|
|
115
|
+
"emailChange": {
|
|
116
|
+
"title": "Confirm your new email",
|
|
117
|
+
"done": "Your email is now {email}.",
|
|
118
|
+
"linkMissing": "Open this page from the link in the email.",
|
|
119
|
+
"failed": "Unable to change your email.",
|
|
120
|
+
"continue": "Continue"
|
|
121
|
+
},
|
|
115
122
|
"signOut": {
|
|
116
123
|
"title": "Signing you out",
|
|
117
124
|
"pending": "Please wait while we end your session.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.45",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"./client/types": "./src/client/types.js",
|
|
17
17
|
"./client/views/DefaultLoginView": "./src/client/views/DefaultLoginView.vue",
|
|
18
18
|
"./client/views/DefaultResetPasswordView": "./src/client/views/DefaultResetPasswordView.vue",
|
|
19
|
+
"./client/views/DefaultEmailChangeView": "./src/client/views/DefaultEmailChangeView.vue",
|
|
19
20
|
"./client/views/DefaultSignOutView": "./src/client/views/DefaultSignOutView.vue",
|
|
20
21
|
"./client/views/SecondFactorDialog": "./src/client/views/SecondFactorDialog.vue",
|
|
21
22
|
"./client/views/SecondFactorPrompt": "./src/client/views/SecondFactorPrompt.vue",
|
|
@@ -28,14 +29,14 @@
|
|
|
28
29
|
"./locales/en.json": "./locales/en.json"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@jskit-ai/auth-pass": "0.1.
|
|
32
|
+
"@jskit-ai/auth-pass": "0.1.1",
|
|
32
33
|
"uqr": "0.1.3"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"@jskit-ai/auth-core": "0.2.
|
|
36
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
37
|
-
"@jskit-ai/kernel": "0.2.
|
|
38
|
-
"@jskit-ai/shell-web": "0.2.
|
|
36
|
+
"@jskit-ai/auth-core": "0.2.31",
|
|
37
|
+
"@jskit-ai/http-runtime": "0.2.27",
|
|
38
|
+
"@jskit-ai/kernel": "0.2.27",
|
|
39
|
+
"@jskit-ai/shell-web": "0.2.39",
|
|
39
40
|
"@tanstack/vue-query": "^5.90.5",
|
|
40
41
|
"pinia": "^4.0.3",
|
|
41
42
|
"vue": "^3.5.44",
|
|
@@ -114,6 +115,16 @@
|
|
|
114
115
|
},
|
|
115
116
|
"server": {
|
|
116
117
|
"routes": [
|
|
118
|
+
{
|
|
119
|
+
"method": "POST",
|
|
120
|
+
"path": "/api/email-change",
|
|
121
|
+
"summary": "Ask to change the signed-in account's email: a link goes to the new address"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"method": "POST",
|
|
125
|
+
"path": "/api/email-change/confirm",
|
|
126
|
+
"summary": "Confirm an email change with the link sent to the new address"
|
|
127
|
+
},
|
|
117
128
|
{
|
|
118
129
|
"method": "POST",
|
|
119
130
|
"path": "/api/login",
|
|
@@ -247,6 +258,19 @@
|
|
|
247
258
|
},
|
|
248
259
|
"purpose": "Public password reset screen for recovery links."
|
|
249
260
|
},
|
|
261
|
+
{
|
|
262
|
+
"id": "auth.email-change",
|
|
263
|
+
"path": "/auth/email-change",
|
|
264
|
+
"scope": "surface",
|
|
265
|
+
"surface": "auth",
|
|
266
|
+
"name": "auth-email-change",
|
|
267
|
+
"componentKey": "auth-email-change",
|
|
268
|
+
"autoRegister": false,
|
|
269
|
+
"guard": {
|
|
270
|
+
"policy": "public"
|
|
271
|
+
},
|
|
272
|
+
"purpose": "Public screen that confirms an email change from the link sent to the new address."
|
|
273
|
+
},
|
|
250
274
|
{
|
|
251
275
|
"id": "auth.default-login",
|
|
252
276
|
"path": "/auth/default-login",
|
|
@@ -347,6 +371,6 @@
|
|
|
347
371
|
}
|
|
348
372
|
},
|
|
349
373
|
"devDependencies": {
|
|
350
|
-
"@jskit-ai/material-web": "0.1.
|
|
374
|
+
"@jskit-ai/material-web": "0.1.9"
|
|
351
375
|
}
|
|
352
376
|
}
|
|
@@ -27,8 +27,8 @@ Those choices must be known before adapting the example.
|
|
|
27
27
|
## Framework APIs
|
|
28
28
|
|
|
29
29
|
Use the views, auth guard, HTTP client integration, sign-out runtime, providers,
|
|
30
|
-
and Playwright auth helper exported by `@jskit-ai/auth-web`. The sign-in, reset
|
|
31
|
-
and sign-out screens show the app's identity: the pages render the app's view
|
|
30
|
+
and Playwright auth helper exported by `@jskit-ai/auth-web`. The sign-in, reset,
|
|
31
|
+
email change and sign-out screens show the app's identity: the pages render the app's view
|
|
32
32
|
wrappers (`src/views/auth/`), and each wrapper fills the default view's `brand`
|
|
33
33
|
slot (given `{ compact }`) with `src/components/AppBrand.vue`, the app's name
|
|
34
34
|
as `index.html`'s `<title>` spells it. JSKIT lays the slot out as a pane beside
|
|
@@ -107,9 +107,10 @@ a user as a side effect.
|
|
|
107
107
|
exercised.
|
|
108
108
|
- Public auth routes do not require an existing session.
|
|
109
109
|
- Protected routes use the framework auth policy rather than page-local checks.
|
|
110
|
-
- Login, sign-out, and
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
- Login, sign-out, reset and email change views use the public auth
|
|
111
|
+
components/composables.
|
|
112
|
+
- The sign-in, reset, email change and sign-out pages render the app's view
|
|
113
|
+
wrappers, which fill the `brand` slot with the app's identity (`AppBrand.vue`): a person
|
|
113
114
|
always sees which app they are signing in to. Renaming the app renames
|
|
114
115
|
`AppBrand.vue` with `index.html`'s `<title>`; the brand adds no heading.
|
|
115
116
|
- A custom login view must preserve the default view's initial session check:
|
|
@@ -152,9 +153,10 @@ placements, and post-auth destinations while retaining the runtime contracts.
|
|
|
152
153
|
|
|
153
154
|
## Verification
|
|
154
155
|
|
|
155
|
-
Check that the sign-in, reset and sign-out screens show the
|
|
156
|
-
pane on a wide window and in the row on a phone. Exercise
|
|
157
|
-
login, sign-out, reset,
|
|
156
|
+
Check that the sign-in, reset, email change and sign-out screens show the
|
|
157
|
+
app's name, in the pane on a wide window and in the row on a phone. Exercise
|
|
158
|
+
failed and successful login, sign-out, reset, an email change link, protected
|
|
159
|
+
navigation,
|
|
158
160
|
keyboard interaction, warm-cache return navigation, and browser refresh.
|
|
159
161
|
Open the login route with an existing authenticated session and confirm it
|
|
160
162
|
returns to the requested screen; repeat signed out and confirm the form remains.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<route lang="json">
|
|
2
|
+
{
|
|
3
|
+
"meta": {
|
|
4
|
+
"guard": {
|
|
5
|
+
"policy": "public"
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
</route>
|
|
10
|
+
|
|
11
|
+
<script setup>
|
|
12
|
+
import EmailChangeView from "@/views/auth/EmailChangeView.vue";
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<EmailChangeView />
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import DefaultEmailChangeView from "@jskit-ai/auth-web/client/views/DefaultEmailChangeView";
|
|
3
|
+
import AppBrand from "@/components/AppBrand.vue";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<DefaultEmailChangeView>
|
|
8
|
+
<template #brand="{ compact }">
|
|
9
|
+
<AppBrand :compact="compact" />
|
|
10
|
+
</template>
|
|
11
|
+
</DefaultEmailChangeView>
|
|
12
|
+
</template>
|
|
@@ -45,7 +45,7 @@ export function useLoginViewState({ placementContext }) {
|
|
|
45
45
|
const password = ref("");
|
|
46
46
|
const confirmPassword = ref("");
|
|
47
47
|
const otpCode = ref("");
|
|
48
|
-
// The first account's setup code, asked for while a production server has no account.
|
|
48
|
+
// The first account's setup code, asked for while a staging or production server has no account.
|
|
49
49
|
const setupCode = ref("");
|
|
50
50
|
const showPassword = ref(false);
|
|
51
51
|
const showConfirmPassword = ref(false);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { onMounted, ref } from "vue";
|
|
2
|
+
import { confirmEmailChangeLink } from "../runtime/emailChangeLink.js";
|
|
3
|
+
import { useJskitText } from "../i18n.js";
|
|
4
|
+
|
|
5
|
+
/** The email change page: it confirms the link it was opened with once, then says what happened. */
|
|
6
|
+
export function useDefaultEmailChangeView() {
|
|
7
|
+
const { serverMessage, t } = useJskitText();
|
|
8
|
+
const status = ref("checking");
|
|
9
|
+
const message = ref("");
|
|
10
|
+
|
|
11
|
+
async function confirmLink() {
|
|
12
|
+
const result = await confirmEmailChangeLink(window.location.href);
|
|
13
|
+
// The link works once: it leaves the address bar and the history.
|
|
14
|
+
window.history.replaceState(window.history.state, "", window.location.pathname);
|
|
15
|
+
status.value = result.status === "done" ? "done" : "error";
|
|
16
|
+
if (result.status === "done") {
|
|
17
|
+
message.value = t("jskit.auth.emailChange.done", { email: result.email });
|
|
18
|
+
} else if (result.status === "missing") {
|
|
19
|
+
message.value = t("jskit.auth.emailChange.linkMissing");
|
|
20
|
+
} else {
|
|
21
|
+
message.value = serverMessage(result.error, t("jskit.auth.emailChange.failed"));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onMounted(confirmLink);
|
|
26
|
+
|
|
27
|
+
return { status, message };
|
|
28
|
+
}
|
package/src/client/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import DefaultLoginView from "./views/DefaultLoginView.vue";
|
|
2
2
|
import DefaultSignOutView from "./views/DefaultSignOutView.vue";
|
|
3
3
|
import DefaultResetPasswordView from "./views/DefaultResetPasswordView.vue";
|
|
4
|
+
import DefaultEmailChangeView from "./views/DefaultEmailChangeView.vue";
|
|
4
5
|
|
|
5
6
|
export { AuthWebClientProvider } from "./providers/AuthWebClientProvider.js";
|
|
6
7
|
export { default as DefaultLoginView } from "./views/DefaultLoginView.vue";
|
|
7
8
|
export { default as DefaultSignOutView } from "./views/DefaultSignOutView.vue";
|
|
8
9
|
export { default as DefaultResetPasswordView } from "./views/DefaultResetPasswordView.vue";
|
|
10
|
+
export { default as DefaultEmailChangeView } from "./views/DefaultEmailChangeView.vue";
|
|
9
11
|
export { default as AuthProfileWidget } from "./views/AuthProfileWidget.vue";
|
|
10
12
|
export { default as AuthProfileMenuLinkItem } from "./views/AuthProfileMenuLinkItem.vue";
|
|
11
13
|
export { useSecondFactorStepUp } from "./composables/secondFactor/useSecondFactorStepUp.js";
|
|
@@ -25,7 +27,8 @@ const routeComponents = Object.freeze({
|
|
|
25
27
|
"auth-login": DefaultLoginView,
|
|
26
28
|
"auth-signout": DefaultSignOutView,
|
|
27
29
|
"auth-default-login": DefaultLoginView,
|
|
28
|
-
"auth-reset-password": DefaultResetPasswordView
|
|
30
|
+
"auth-reset-password": DefaultResetPasswordView,
|
|
31
|
+
"auth-email-change": DefaultEmailChangeView
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
export { routeComponents };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
2
|
+
import { authHttpRequest } from "./authHttpClient.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The token of an email change link from a page's address: "" when it has none.
|
|
6
|
+
* @param {string} href
|
|
7
|
+
*/
|
|
8
|
+
function readEmailChangeToken(href) {
|
|
9
|
+
try {
|
|
10
|
+
return new URL(href).searchParams.get("token") || "";
|
|
11
|
+
} catch {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Confirms the email change a page's link names: `done` with the account's new email, `error` with the refusal, or
|
|
18
|
+
* `missing` when the address has no link, without asking the server.
|
|
19
|
+
* @param {string} href The page's address.
|
|
20
|
+
* @param {typeof authHttpRequest} [request]
|
|
21
|
+
* @returns {Promise<{ status: "done" | "error" | "missing", email: string, error: unknown }>}
|
|
22
|
+
*/
|
|
23
|
+
async function confirmEmailChangeLink(href, request = authHttpRequest) {
|
|
24
|
+
const token = readEmailChangeToken(href);
|
|
25
|
+
if (!token) {
|
|
26
|
+
return { status: "missing", email: "", error: null };
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const answer = await request(AUTH_PATHS.EMAIL_CHANGE_CONFIRM, { method: "POST", body: { token } });
|
|
30
|
+
return { status: "done", email: String(answer?.email || ""), error: null };
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return { status: "error", email: "", error };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { confirmEmailChangeLink, readEmailChangeToken };
|
|
@@ -11,7 +11,8 @@ const { t } = useJskitText();
|
|
|
11
11
|
const { context: shellPlacementContext } = useWebPlacementContext();
|
|
12
12
|
// On expanded windows the activator is a pill with the name beside the avatar, the name ending in an ellipsis past
|
|
13
13
|
// 12rem; on medium and compact windows, where the app bar's title and actions need the room, it is a round icon
|
|
14
|
-
// button around the avatar, named by its aria-label.
|
|
14
|
+
// button around the avatar, named by its aria-label. That avatar is hidden from assistive technology: its initials
|
|
15
|
+
// are not in the name, and a control's name holds the text it shows (WCAG 2.5.3 Label in Name).
|
|
15
16
|
const { isExpanded, isLarge } = useShellWindowSizeClass();
|
|
16
17
|
const showsName = computed(() => isExpanded.value || isLarge.value);
|
|
17
18
|
|
|
@@ -84,7 +85,7 @@ const placementContext = computed(() => {
|
|
|
84
85
|
<span class="auth-profile-widget__name ml-2 text-body-medium">{{ displayName }}</span>
|
|
85
86
|
</v-btn>
|
|
86
87
|
<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="displayName">
|
|
87
|
-
<v-avatar size="32" color="primary" variant="tonal">
|
|
88
|
+
<v-avatar size="32" color="primary" variant="tonal" aria-hidden="true">
|
|
88
89
|
<v-img v-if="avatarUrl" :src="avatarUrl" cover />
|
|
89
90
|
<span v-else class="text-body-small font-weight-medium">{{ initials }}</span>
|
|
90
91
|
</v-avatar>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AuthScreen class="email-change-screen">
|
|
3
|
+
<template v-if="$slots.brand" #brand="brand">
|
|
4
|
+
<slot name="brand" v-bind="brand" />
|
|
5
|
+
</template>
|
|
6
|
+
<v-card
|
|
7
|
+
class="email-change-card"
|
|
8
|
+
:class="{ 'email-change-card--mobile': isMobileViewport }"
|
|
9
|
+
variant="flat"
|
|
10
|
+
:rounded="isMobileViewport ? false : undefined"
|
|
11
|
+
>
|
|
12
|
+
<v-card-text class="email-change-content">
|
|
13
|
+
<h1 class="text-headline-medium mb-5">{{ t("jskit.auth.emailChange.title") }}</h1>
|
|
14
|
+
<v-progress-linear v-if="status === 'checking'" indeterminate color="primary" />
|
|
15
|
+
<v-alert v-else :type="status === 'done' ? 'success' : 'error'" variant="tonal">
|
|
16
|
+
{{ message }}
|
|
17
|
+
</v-alert>
|
|
18
|
+
<div v-if="status !== 'checking'" class="mt-4 d-flex justify-end">
|
|
19
|
+
<v-btn variant="text" color="secondary" href="/">
|
|
20
|
+
{{ t("jskit.auth.emailChange.continue") }}
|
|
21
|
+
</v-btn>
|
|
22
|
+
</div>
|
|
23
|
+
</v-card-text>
|
|
24
|
+
</v-card>
|
|
25
|
+
</AuthScreen>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script setup>
|
|
29
|
+
import { useDisplay } from "vuetify";
|
|
30
|
+
import AuthScreen from "./AuthScreen.vue";
|
|
31
|
+
import { useDefaultEmailChangeView } from "../composables/useDefaultEmailChangeView.js";
|
|
32
|
+
import { useJskitText } from "../i18n.js";
|
|
33
|
+
|
|
34
|
+
const { mobile: isMobileViewport } = useDisplay({ mobileBreakpoint: 960 });
|
|
35
|
+
const { t } = useJskitText();
|
|
36
|
+
const { status, message } = useDefaultEmailChangeView();
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<style scoped>
|
|
40
|
+
.email-change-card {
|
|
41
|
+
width: min(480px, 100%);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* On a phone the card is the screen below the brand row, if any. */
|
|
45
|
+
.email-change-card--mobile {
|
|
46
|
+
flex: 1 0 auto;
|
|
47
|
+
width: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.email-change-content {
|
|
51
|
+
padding: 28px;
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineFeature } from "@jskit-ai/kernel/server/features";
|
|
2
2
|
import { createAuthWeb } from "./authWeb.js";
|
|
3
|
+
import { registerEmailChangeRoutes } from "./routes/emailChangeRoutes.js";
|
|
3
4
|
import { registerPassSignInRoutes } from "./routes/passSignInRoutes.js";
|
|
4
5
|
import { registerSecondFactorRoutes } from "./routes/secondFactorRoutes.js";
|
|
5
6
|
|
|
@@ -29,6 +30,7 @@ const AuthWebFeature = defineFeature({
|
|
|
29
30
|
http.router.register(route.method, route.path, route, route.handler);
|
|
30
31
|
}
|
|
31
32
|
registerSecondFactorRoutes(http.router, { rateLimits: authWeb.rateLimits });
|
|
33
|
+
registerEmailChangeRoutes(http.router, { rateLimits: authWeb.rateLimits });
|
|
32
34
|
return { authWeb };
|
|
33
35
|
},
|
|
34
36
|
/**
|
|
@@ -23,7 +23,9 @@ const DEFAULT_AUTH_RATE_LIMITS = Object.freeze({
|
|
|
23
23
|
secondFactorSetupConfirm: Object.freeze({ max: 10, timeWindow: "1 minute" }),
|
|
24
24
|
secondFactorVerify: Object.freeze({ max: 10, timeWindow: "1 minute" }),
|
|
25
25
|
secondFactorRecoveryCodes: Object.freeze({ max: 5, timeWindow: "1 minute" }),
|
|
26
|
-
secondFactorRemove: Object.freeze({ max: 5, timeWindow: "1 minute" })
|
|
26
|
+
secondFactorRemove: Object.freeze({ max: 5, timeWindow: "1 minute" }),
|
|
27
|
+
emailChange: Object.freeze({ max: 5, timeWindow: "1 minute" }),
|
|
28
|
+
emailChangeConfirm: Object.freeze({ max: 10, timeWindow: "1 minute" })
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACTION_CONFIRM_EMAIL_CHANGE,
|
|
3
|
+
ACTION_REQUEST_EMAIL_CHANGE
|
|
4
|
+
} from "@jskit-ai/auth-core/server/actions/emailChangeActions";
|
|
5
|
+
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
6
|
+
import { authEmailChangeConfirmCommand, authEmailChangeRequestCommand } from "@jskit-ai/auth-core/shared/commands";
|
|
7
|
+
import { withStandardErrorResponses } from "@jskit-ai/http-runtime/shared/validators/errorResponses";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An account's email change: the signed-in person asks for a new address with their password, and the link sent to
|
|
11
|
+
* it confirms the change, from a browser signed in or not. Each route runs its auth.emailChange action, limited per
|
|
12
|
+
* client address by its entry in `rateLimits` (none when that entry is null).
|
|
13
|
+
* @param {import("@jskit-ai/kernel/server/types").RuntimeRouter} router
|
|
14
|
+
* @param {{ rateLimits: import("../types.js").AuthRateLimits }} dependencies
|
|
15
|
+
*/
|
|
16
|
+
function registerEmailChangeRoutes(router, { rateLimits }) {
|
|
17
|
+
router.register(
|
|
18
|
+
"POST",
|
|
19
|
+
AUTH_PATHS.EMAIL_CHANGE,
|
|
20
|
+
{
|
|
21
|
+
auth: "required",
|
|
22
|
+
meta: { tags: ["auth"], summary: "Ask to change the signed-in account's email: a link goes to the new address" },
|
|
23
|
+
body: authEmailChangeRequestCommand.operation.body,
|
|
24
|
+
responses: withStandardErrorResponses(
|
|
25
|
+
{ 200: authEmailChangeRequestCommand.operation.response },
|
|
26
|
+
{ includeValidation400: true }
|
|
27
|
+
),
|
|
28
|
+
rateLimit: rateLimits.emailChange
|
|
29
|
+
},
|
|
30
|
+
async function (request, reply) {
|
|
31
|
+
reply.code(200).send(await request.executeAction({ actionId: ACTION_REQUEST_EMAIL_CHANGE, input: request.input.body }));
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
router.register(
|
|
36
|
+
"POST",
|
|
37
|
+
AUTH_PATHS.EMAIL_CHANGE_CONFIRM,
|
|
38
|
+
{
|
|
39
|
+
auth: "public",
|
|
40
|
+
meta: { tags: ["auth"], summary: "Confirm an email change with the link sent to the new address" },
|
|
41
|
+
body: authEmailChangeConfirmCommand.operation.body,
|
|
42
|
+
responses: withStandardErrorResponses(
|
|
43
|
+
{ 200: authEmailChangeConfirmCommand.operation.response },
|
|
44
|
+
{ includeValidation400: true }
|
|
45
|
+
),
|
|
46
|
+
rateLimit: rateLimits.emailChangeConfirm
|
|
47
|
+
},
|
|
48
|
+
async function (request, reply) {
|
|
49
|
+
reply.code(200).send(await request.executeAction({ actionId: ACTION_CONFIRM_EMAIL_CHANGE, input: request.input.body }));
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { registerEmailChangeRoutes };
|
|
@@ -34,7 +34,7 @@ async function registerPassSignInRoutes(fastify, { service, rateLimit }) {
|
|
|
34
34
|
const form = /** @type {{ pass?: unknown } | undefined} */ (request.body);
|
|
35
35
|
let result;
|
|
36
36
|
try {
|
|
37
|
-
result = await service.signInWithPass({ pass: String(form?.pass ?? "") });
|
|
37
|
+
result = await service.signInWithPass({ pass: String(form?.pass ?? "") }, request);
|
|
38
38
|
} catch (error) {
|
|
39
39
|
if (!(error instanceof AppError) || error.statusCode >= 500) {
|
|
40
40
|
throw error;
|
|
@@ -124,14 +124,15 @@ class AuthWebService {
|
|
|
124
124
|
/**
|
|
125
125
|
* Signs in the account a one-time signed pass names; a provider without pass sign-in refuses it as unsupported.
|
|
126
126
|
* @param {{ pass: string }} input
|
|
127
|
+
* @param {object} request The request that posted the pass.
|
|
127
128
|
*/
|
|
128
|
-
async signInWithPass(input) {
|
|
129
|
+
async signInWithPass(input, request) {
|
|
129
130
|
const { authService } = this;
|
|
130
131
|
// readable-check: allow method-probe - optional operation: signInWithPass is an optional auth.service operation
|
|
131
132
|
if (typeof authService.signInWithPass !== "function") {
|
|
132
133
|
return throwUnsupportedAuthOperation("signInWithPass");
|
|
133
134
|
}
|
|
134
|
-
return authService.signInWithPass(input);
|
|
135
|
+
return authService.signInWithPass(input, request);
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
writeSessionCookies(reply, session) {
|
|
@@ -33,7 +33,7 @@ async function startAuthWeb(t, config = {}) {
|
|
|
33
33
|
inputs: {
|
|
34
34
|
"auth.service": createRefusingAuthService(),
|
|
35
35
|
"runtime.config": config,
|
|
36
|
-
"runtime.env": {
|
|
36
|
+
"runtime.env": { APP_ENV: "test" },
|
|
37
37
|
"runtime.fastify": app,
|
|
38
38
|
"runtime.logger": silentLogger
|
|
39
39
|
},
|
|
@@ -93,7 +93,12 @@ test("the auth views fill the viewport through AuthScreen: a card on wide window
|
|
|
93
93
|
// The full-viewport screen starts below shell banners shown on this bar-less surface.
|
|
94
94
|
assert.match(screen, /\.auth-screen\s*\{[\s\S]*inset:\s*var\(--shell-error-banners-inline-height, 0px\) 0 0;/);
|
|
95
95
|
assert.doesNotMatch(screen, /min-height:\s*100dvh/);
|
|
96
|
-
for (const [name, card] of [
|
|
96
|
+
for (const [name, card] of [
|
|
97
|
+
["DefaultLoginView", "auth-card"],
|
|
98
|
+
["DefaultResetPasswordView", "reset-card"],
|
|
99
|
+
["DefaultSignOutView", "signout-card"],
|
|
100
|
+
["DefaultEmailChangeView", "email-change-card"]
|
|
101
|
+
]) {
|
|
97
102
|
const view = read(name);
|
|
98
103
|
assert.match(view, /<AuthScreen\b/, name);
|
|
99
104
|
// The app's brand slot reaches the screen's pane and row.
|
|
@@ -164,6 +169,10 @@ test("auth-web package exports only minimal client runtime/view subpaths", () =>
|
|
|
164
169
|
exportsMap["./client/views/DefaultSignOutView"],
|
|
165
170
|
"./src/client/views/DefaultSignOutView.vue"
|
|
166
171
|
);
|
|
172
|
+
assert.equal(
|
|
173
|
+
exportsMap["./client/views/DefaultEmailChangeView"],
|
|
174
|
+
"./src/client/views/DefaultEmailChangeView.vue"
|
|
175
|
+
);
|
|
167
176
|
assert.equal(
|
|
168
177
|
exportsMap["./client/runtime/authGuardRuntime"],
|
|
169
178
|
"./src/client/runtime/authGuardRuntime.js"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { confirmEmailChangeLink } from "../src/client/runtime/emailChangeLink.js";
|
|
4
|
+
|
|
5
|
+
test("an email change page confirms the link it was opened with, once; a page without one asks nothing", async () => {
|
|
6
|
+
const calls = [];
|
|
7
|
+
const request = async (url, options) => {
|
|
8
|
+
calls.push([url, options]);
|
|
9
|
+
return { ok: true, email: "new@example.com" };
|
|
10
|
+
};
|
|
11
|
+
assert.deepEqual(await confirmEmailChangeLink("https://app.example/auth/email-change?token=link-token", request),
|
|
12
|
+
{ status: "done", email: "new@example.com", error: null });
|
|
13
|
+
assert.deepEqual(calls, [["/api/email-change/confirm", { method: "POST", body: { token: "link-token" } }]]);
|
|
14
|
+
|
|
15
|
+
assert.deepEqual(await confirmEmailChangeLink("https://app.example/auth/email-change", request),
|
|
16
|
+
{ status: "missing", email: "", error: null });
|
|
17
|
+
assert.deepEqual(await confirmEmailChangeLink("not an address", request), { status: "missing", email: "", error: null });
|
|
18
|
+
assert.equal(calls.length, 1);
|
|
19
|
+
|
|
20
|
+
const refused = Object.assign(new Error("This email change link is invalid, used or expired. Ask for the change again."), {
|
|
21
|
+
status: 400,
|
|
22
|
+
code: "auth.local.emailChange.linkInvalid"
|
|
23
|
+
});
|
|
24
|
+
const failed = await confirmEmailChangeLink("https://app.example/auth/email-change?token=used", async () => {
|
|
25
|
+
throw refused;
|
|
26
|
+
});
|
|
27
|
+
assert.deepEqual(failed, { status: "error", email: "", error: refused });
|
|
28
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import Fastify from "fastify";
|
|
7
|
+
import { AuthExtensionsProvider } from "@jskit-ai/auth-core/server/providers/AuthExtensionsProvider";
|
|
8
|
+
import { AuthFeature } from "@jskit-ai/auth-core/server/providers/AuthFeature";
|
|
9
|
+
import { AuthPolicyProvider } from "@jskit-ai/auth-core/server/providers/AuthPolicyProvider";
|
|
10
|
+
import { ActionProvider } from "@jskit-ai/kernel/server/actions";
|
|
11
|
+
import { HttpProvider } from "@jskit-ai/kernel/server/http";
|
|
12
|
+
import { EventProvider } from "@jskit-ai/kernel/server/runtime";
|
|
13
|
+
import { silentLogger } from "@jskit-ai/kernel/server/runtime/logger";
|
|
14
|
+
import { createCapabilityRuntime } from "@jskit-ai/kernel/shared/capabilities";
|
|
15
|
+
import { createLocalFileBackend } from "../../auth-provider-local-core/src/server/lib/index.js";
|
|
16
|
+
import { emailChangeService } from "../../auth-provider-local-core/test-support/emailChangeScenario.js";
|
|
17
|
+
import { sessionCookies } from "../../auth-provider-local-core/test-support/oauthHarness.js";
|
|
18
|
+
import { AuthWebFeature } from "../src/server/AuthWebFeature.js";
|
|
19
|
+
import { DEFAULT_AUTH_RATE_LIMITS } from "../src/server/authRateLimits.js";
|
|
20
|
+
|
|
21
|
+
const PASSWORD = "correct horse battery staple";
|
|
22
|
+
|
|
23
|
+
/** The auth routes over local auth in a store of the test's own, whose email-change sender keeps what it sends. */
|
|
24
|
+
async function startApp(t, config = {}) {
|
|
25
|
+
const storeDir = await fs.mkdtemp(path.join(os.tmpdir(), "jskit-auth-web-email-change-"));
|
|
26
|
+
t.after(() => fs.rm(storeDir, { recursive: true, force: true }));
|
|
27
|
+
const { service, takeSent } = emailChangeService(createLocalFileBackend({ storeDir }));
|
|
28
|
+
const app = Fastify();
|
|
29
|
+
const runtime = createCapabilityRuntime({
|
|
30
|
+
inputs: {
|
|
31
|
+
"auth.service": service,
|
|
32
|
+
"runtime.config": config,
|
|
33
|
+
"runtime.env": { APP_ENV: "test" },
|
|
34
|
+
"runtime.fastify": app,
|
|
35
|
+
"runtime.logger": silentLogger
|
|
36
|
+
},
|
|
37
|
+
providers: [EventProvider, ActionProvider, HttpProvider, AuthExtensionsProvider, AuthFeature, AuthPolicyProvider, AuthWebFeature]
|
|
38
|
+
});
|
|
39
|
+
await runtime.start();
|
|
40
|
+
t.after(async () => {
|
|
41
|
+
await runtime.shutdown();
|
|
42
|
+
await app.close();
|
|
43
|
+
});
|
|
44
|
+
return { app, service, takeSent };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A browser: its cookies and CSRF token, signed in as the email when one is given. */
|
|
48
|
+
async function browser(app, service, email = "") {
|
|
49
|
+
const cookies = email
|
|
50
|
+
? sessionCookies((await service.register({ email, password: PASSWORD })).session)
|
|
51
|
+
: {};
|
|
52
|
+
const session = await app.inject({ method: "GET", url: "/api/session", cookies });
|
|
53
|
+
for (const cookie of session.cookies) {
|
|
54
|
+
cookies[cookie.name] = cookie.value;
|
|
55
|
+
}
|
|
56
|
+
const csrfToken = session.json().csrfToken;
|
|
57
|
+
return (url, payload) => app.inject({ method: "POST", url, cookies, headers: { "csrf-token": csrfToken }, payload });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test("the signed-in person asks to change their email, and the link's page confirms it signed in or not", async (t) => {
|
|
61
|
+
const { app, service, takeSent } = await startApp(t);
|
|
62
|
+
const ada = await browser(app, service, "ada@example.com");
|
|
63
|
+
const stranger = await browser(app, service);
|
|
64
|
+
|
|
65
|
+
const refused = async (response, status, code) => {
|
|
66
|
+
assert.equal(response.statusCode, status, response.body);
|
|
67
|
+
assert.equal(response.json().code, code);
|
|
68
|
+
};
|
|
69
|
+
await refused(await stranger("/api/email-change", { email: "new@example.com", password: PASSWORD }), 401, "auth.session.required");
|
|
70
|
+
await refused(await ada("/api/email-change", { email: "new@example.com", password: "a wrong password" }), 400,
|
|
71
|
+
"auth.local.emailChange.passwordInvalid");
|
|
72
|
+
await refused(await ada("/api/email-change", { email: "new@example.com" }), 400, "validation_failed");
|
|
73
|
+
assert.deepEqual(await takeSent(), []);
|
|
74
|
+
|
|
75
|
+
const asked = await ada("/api/email-change", { email: "new@example.com", password: PASSWORD });
|
|
76
|
+
assert.equal(asked.statusCode, 200, asked.body);
|
|
77
|
+
assert.deepEqual(asked.json(), { ok: true, email: "new@example.com" });
|
|
78
|
+
const [link] = await takeSent();
|
|
79
|
+
const token = new URL(link.confirmationUrl).searchParams.get("token");
|
|
80
|
+
|
|
81
|
+
await refused(await stranger("/api/email-change/confirm", {}), 400, "validation_failed");
|
|
82
|
+
const confirmed = await stranger("/api/email-change/confirm", { token });
|
|
83
|
+
assert.equal(confirmed.statusCode, 200, confirmed.body);
|
|
84
|
+
assert.deepEqual(confirmed.json(), { ok: true, email: "new@example.com" });
|
|
85
|
+
await refused(await stranger("/api/email-change/confirm", { token }), 400, "auth.local.emailChange.linkInvalid");
|
|
86
|
+
assert.equal((await service.login({ email: "new@example.com", password: PASSWORD })).actor.email, "new@example.com");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("asking for an email change, and confirming one, are each limited per address", async (t) => {
|
|
90
|
+
assert.deepEqual([DEFAULT_AUTH_RATE_LIMITS.emailChange, DEFAULT_AUTH_RATE_LIMITS.emailChangeConfirm],
|
|
91
|
+
[{ max: 5, timeWindow: "1 minute" }, { max: 10, timeWindow: "1 minute" }]);
|
|
92
|
+
const { app, service } = await startApp(t, {
|
|
93
|
+
auth: { rateLimits: { emailChange: { max: 2 }, emailChangeConfirm: { max: 2 } } }
|
|
94
|
+
});
|
|
95
|
+
const ada = await browser(app, service, "ada@example.com");
|
|
96
|
+
const asked = [];
|
|
97
|
+
const confirmed = [];
|
|
98
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
99
|
+
asked.push((await ada("/api/email-change", { email: "new@example.com", password: "a wrong password" })).statusCode);
|
|
100
|
+
confirmed.push((await ada("/api/email-change/confirm", { token: "not-a-link" })).statusCode);
|
|
101
|
+
}
|
|
102
|
+
assert.deepEqual(asked, [400, 400, 429]);
|
|
103
|
+
assert.deepEqual(confirmed, [400, 400, 429]);
|
|
104
|
+
});
|
|
@@ -77,6 +77,7 @@ test("managed preview identity signs out before selecting an existing applicatio
|
|
|
77
77
|
}, {
|
|
78
78
|
...HOST_OPTIONS,
|
|
79
79
|
env: {
|
|
80
|
+
APP_ENV: "development",
|
|
80
81
|
AUTH_DEV_BYPASS_ENABLED: "true",
|
|
81
82
|
AUTH_DEV_BYPASS_SECRET: SECRET
|
|
82
83
|
},
|
|
@@ -114,7 +115,7 @@ test("managed preview identity rejects a disabled or non-local exchange", async
|
|
|
114
115
|
protocol: HOST_PROTOCOL,
|
|
115
116
|
requestId: "request-2",
|
|
116
117
|
target: { origin: "http://localhost:3000" }
|
|
117
|
-
}, { ...HOST_OPTIONS, env: {}, fetchImpl: async () => assert.fail("fetch must not run") });
|
|
118
|
+
}, { ...HOST_OPTIONS, env: { APP_ENV: "development" }, fetchImpl: async () => assert.fail("fetch must not run") });
|
|
118
119
|
assert.equal(disabled.ok, false);
|
|
119
120
|
assert.equal(disabled.code, "jskit_managed_preview_identity_disabled");
|
|
120
121
|
|
|
@@ -126,6 +127,7 @@ test("managed preview identity rejects a disabled or non-local exchange", async
|
|
|
126
127
|
}, {
|
|
127
128
|
...HOST_OPTIONS,
|
|
128
129
|
env: {
|
|
130
|
+
APP_ENV: "development",
|
|
129
131
|
AUTH_DEV_BYPASS_ENABLED: "true",
|
|
130
132
|
AUTH_DEV_BYPASS_SECRET: SECRET
|
|
131
133
|
},
|
|
@@ -141,6 +143,7 @@ test("managed preview identity rejects a disabled or non-local exchange", async
|
|
|
141
143
|
target: { origin: "http://preview-deadbeefcafe" }
|
|
142
144
|
}, {
|
|
143
145
|
env: {
|
|
146
|
+
APP_ENV: "development",
|
|
144
147
|
AUTH_DEV_BYPASS_ENABLED: "true",
|
|
145
148
|
AUTH_DEV_BYPASS_SECRET: SECRET
|
|
146
149
|
},
|
|
@@ -159,7 +162,7 @@ test("managed preview identity accepts the dev auth secret auth-core accepts", a
|
|
|
159
162
|
};
|
|
160
163
|
const missing = await executeManagedPreviewIdentityRequest(request, {
|
|
161
164
|
...HOST_OPTIONS,
|
|
162
|
-
env: { AUTH_DEV_BYPASS_ENABLED: "true", AUTH_DEV_BYPASS_SECRET: " " },
|
|
165
|
+
env: { APP_ENV: "development", AUTH_DEV_BYPASS_ENABLED: "true", AUTH_DEV_BYPASS_SECRET: " " },
|
|
163
166
|
fetchImpl: async () => assert.fail("fetch must not run")
|
|
164
167
|
});
|
|
165
168
|
assert.equal(missing.code, "jskit_managed_preview_identity_secret_missing");
|
|
@@ -170,7 +173,7 @@ test("managed preview identity accepts the dev auth secret auth-core accepts", a
|
|
|
170
173
|
];
|
|
171
174
|
const signedOut = await executeManagedPreviewIdentityRequest(request, {
|
|
172
175
|
...HOST_OPTIONS,
|
|
173
|
-
env: { AUTH_DEV_BYPASS_ENABLED: "true", AUTH_DEV_BYPASS_SECRET: " any-local-secret " },
|
|
176
|
+
env: { APP_ENV: "development", AUTH_DEV_BYPASS_ENABLED: "true", AUTH_DEV_BYPASS_SECRET: " any-local-secret " },
|
|
174
177
|
fetchImpl: async () => responses.shift()
|
|
175
178
|
});
|
|
176
179
|
assert.equal(signedOut.ok, true);
|
|
@@ -13,6 +13,7 @@ import { EventProvider } from "@jskit-ai/kernel/server/runtime";
|
|
|
13
13
|
import { silentLogger } from "@jskit-ai/kernel/server/runtime/logger";
|
|
14
14
|
import { createCapabilityRuntime } from "@jskit-ai/kernel/shared/capabilities";
|
|
15
15
|
import { createLocalAuthService, createLocalFileBackend } from "../../auth-provider-local-core/src/server/lib/index.js";
|
|
16
|
+
import { sha256Base64url } from "../../auth-provider-local-core/src/server/lib/tokens.js";
|
|
16
17
|
import { localServiceOptions } from "../../auth-provider-local-core/test-support/localService.js";
|
|
17
18
|
import { createPassIssuer, passIdentityByEmail, passwordlessAccount } from "../../auth-provider-local-core/test-support/passSignInScenario.js";
|
|
18
19
|
import { AuthWebFeature } from "../src/server/AuthWebFeature.js";
|
|
@@ -20,7 +21,7 @@ import { DEFAULT_AUTH_RATE_LIMITS } from "../src/server/authRateLimits.js";
|
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* The auth routes and policy over local auth in a store of the test's own, trusting the issuer's passes when `env`
|
|
23
|
-
* carries its key.
|
|
24
|
+
* carries its key, and the store it keeps.
|
|
24
25
|
* @param {import("node:test").TestContext} t
|
|
25
26
|
* @param {{ env?: Record<string, string>, config?: object }} [options]
|
|
26
27
|
*/
|
|
@@ -35,7 +36,7 @@ async function startApp(t, { env = {}, config = {} } = {}) {
|
|
|
35
36
|
inputs: {
|
|
36
37
|
"auth.service": authService,
|
|
37
38
|
"runtime.config": config,
|
|
38
|
-
"runtime.env": {
|
|
39
|
+
"runtime.env": { APP_ENV: "test", ...env },
|
|
39
40
|
"runtime.fastify": app,
|
|
40
41
|
"runtime.logger": silentLogger
|
|
41
42
|
},
|
|
@@ -44,7 +45,7 @@ async function startApp(t, { env = {}, config = {} } = {}) {
|
|
|
44
45
|
t.after(() => app.close());
|
|
45
46
|
await runtime.start();
|
|
46
47
|
t.after(() => runtime.shutdown());
|
|
47
|
-
return app;
|
|
48
|
+
return { app, backend };
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/** The browser's form post of a pass, from the issuer's page, with no CSRF token and no cookies. */
|
|
@@ -53,7 +54,7 @@ function postPass(app, pass, remoteAddress = "203.0.113.7") {
|
|
|
53
54
|
method: "POST",
|
|
54
55
|
url: "/api/login/pass",
|
|
55
56
|
remoteAddress,
|
|
56
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
57
|
+
headers: { "content-type": "application/x-www-form-urlencoded", "user-agent": "Issuer Page Browser/1.0" },
|
|
57
58
|
payload: new URLSearchParams({ pass }).toString()
|
|
58
59
|
});
|
|
59
60
|
}
|
|
@@ -71,7 +72,7 @@ function sentToSignIn(response, code) {
|
|
|
71
72
|
|
|
72
73
|
test("a pass posted as a form signs its person in and goes home; posted again, it goes to the sign-in page as replayed", async (t) => {
|
|
73
74
|
const issuer = createPassIssuer();
|
|
74
|
-
const app = await startApp(t, { env: issuer.env });
|
|
75
|
+
const { app, backend } = await startApp(t, { env: issuer.env });
|
|
75
76
|
const pass = issuer.pass("ada@example.com");
|
|
76
77
|
|
|
77
78
|
const signedIn = await postPass(app, pass);
|
|
@@ -83,6 +84,9 @@ test("a pass posted as a form signs its person in and goes home; posted again, i
|
|
|
83
84
|
const session = await app.inject({ method: "GET", url: "/api/session", cookies });
|
|
84
85
|
assert.equal(session.json().authenticated, true);
|
|
85
86
|
assert.equal(session.json().email, "ada@example.com");
|
|
87
|
+
// The session keeps the address and browser the pass was posted from.
|
|
88
|
+
const kept = await backend.withTransaction((tx) => tx.sessions.findByTokenHash(sha256Base64url(cookies.jskit_local_refresh_token)));
|
|
89
|
+
assert.deepEqual([kept.ip, kept.userAgent], ["203.0.113.7", "Issuer Page Browser/1.0"]);
|
|
86
90
|
|
|
87
91
|
sentToSignIn(await postPass(app, pass), "auth.pass.replayed");
|
|
88
92
|
sentToSignIn(await postPass(app, issuer.pass("nobody@example.com")), "auth.pass.unmapped");
|
|
@@ -93,7 +97,7 @@ test("a pass posted as a form signs its person in and goes home; posted again, i
|
|
|
93
97
|
|
|
94
98
|
test("one address may post 20 passes a minute; the next is refused with 429 and Retry-After", async (t) => {
|
|
95
99
|
const issuer = createPassIssuer();
|
|
96
|
-
const app = await startApp(t, { env: issuer.env });
|
|
100
|
+
const { app } = await startApp(t, { env: issuer.env });
|
|
97
101
|
assert.deepEqual(DEFAULT_AUTH_RATE_LIMITS.passSignIn, { max: 20, timeWindow: "1 minute" });
|
|
98
102
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
99
103
|
sentToSignIn(await postPass(app, "not a pass"), "auth.pass.malformed");
|
|
@@ -108,14 +112,14 @@ test("one address may post 20 passes a minute; the next is refused with 429 and
|
|
|
108
112
|
|
|
109
113
|
test("without AUTH_PASS_PUBLIC_KEY the app has no pass sign-in route", async (t) => {
|
|
110
114
|
const issuer = createPassIssuer();
|
|
111
|
-
const app = await startApp(t);
|
|
115
|
+
const { app } = await startApp(t);
|
|
112
116
|
assert.equal(app.hasRoute({ method: "POST", url: "/api/login/pass" }), false);
|
|
113
117
|
// The post meets the policy every unknown API post meets, and signs nobody in.
|
|
114
118
|
const posted = await postPass(app, issuer.pass("ada@example.com"));
|
|
115
119
|
assert.equal(posted.statusCode, 403, posted.body);
|
|
116
120
|
assert.deepEqual(posted.cookies, []);
|
|
117
121
|
|
|
118
|
-
const withPasses = await startApp(t, { env: issuer.env });
|
|
122
|
+
const { app: withPasses } = await startApp(t, { env: issuer.env });
|
|
119
123
|
assert.equal(withPasses.hasRoute({ method: "POST", url: "/api/login/pass" }), true);
|
|
120
124
|
});
|
|
121
125
|
|
|
@@ -127,6 +131,6 @@ test("a pass sign-in limit with no limiter to enforce it stops startup", async (
|
|
|
127
131
|
await assert.rejects(startApp(t, { env: issuer.env, config: { auth: { rateLimits: everyOtherLimitOff } } }),
|
|
128
132
|
(error) => /config\.auth\.rateLimits\.passSignIn limits one-time pass sign-in, and no route rate limiter is registered/u
|
|
129
133
|
.test(String(error.details?.cause?.message || error.message)));
|
|
130
|
-
const unlimited = await startApp(t, { env: issuer.env, config: { auth: { rateLimits: { ...everyOtherLimitOff, passSignIn: false } } } });
|
|
134
|
+
const { app: unlimited } = await startApp(t, { env: issuer.env, config: { auth: { rateLimits: { ...everyOtherLimitOff, passSignIn: false } } } });
|
|
131
135
|
assert.equal((await postPass(unlimited, issuer.pass("ada@example.com"))).headers.location, "/");
|
|
132
136
|
});
|
|
@@ -110,7 +110,7 @@ async function startAuthWeb({ env = {}, authService = null } = {}) {
|
|
|
110
110
|
"runtime.logger": silentLogger,
|
|
111
111
|
"auth.service": authService || createAuthService(),
|
|
112
112
|
"runtime.config": {},
|
|
113
|
-
"runtime.env": {
|
|
113
|
+
"runtime.env": { APP_ENV: "test", ...env },
|
|
114
114
|
"runtime.fastify": fastify
|
|
115
115
|
},
|
|
116
116
|
providers: [EventProvider, ActionProvider, HttpProvider, AuthFeature, AuthWebFeature]
|
|
@@ -141,7 +141,7 @@ test("AuthWebFeature exposes dev login only when the explicit dev policy enables
|
|
|
141
141
|
assert.equal(disabled.fastify.routes.some((route) => route.url === "/api/dev-auth/login-as"), false);
|
|
142
142
|
const enabled = await startAuthWeb({
|
|
143
143
|
env: {
|
|
144
|
-
|
|
144
|
+
APP_ENV: "development",
|
|
145
145
|
AUTH_DEV_BYPASS_ENABLED: "true",
|
|
146
146
|
AUTH_DEV_BYPASS_SECRET: "test-secret"
|
|
147
147
|
}
|
|
@@ -578,6 +578,36 @@ test("the account control is the avatar alone up to medium width and truncates a
|
|
|
578
578
|
await finish(api);
|
|
579
579
|
});
|
|
580
580
|
|
|
581
|
+
// WCAG 2.5.3 Label in Name: a control's name holds the text it shows. Up to medium width the account control is
|
|
582
|
+
// named by the person's name (its aria-label) and shows their initials, "AN" for ana.ferreira, which are not in that
|
|
583
|
+
// name (axe label-content-name-mismatch). Its avatar is hidden from assistive technology, so the control shows it no
|
|
584
|
+
// text beyond its name; on wider windows the name is the text it shows.
|
|
585
|
+
test("the account control's name holds every word it shows on a phone and a tablet: WCAG 2.5.3 (axe label-content-name-mismatch)", options, async () => {
|
|
586
|
+
const name = "ana.ferreira";
|
|
587
|
+
const words = (text) => text.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
588
|
+
for (const viewport of [{ width: 390, height: 844 }, { width: 768, height: 1024 }]) {
|
|
589
|
+
const at = `${viewport.width}px`;
|
|
590
|
+
const api = await openApp({ session: { ...SIGNED_IN, username: name }, viewport });
|
|
591
|
+
const { page } = api;
|
|
592
|
+
await page.goto("/home");
|
|
593
|
+
const control = page.getByRole("button", { name, exact: true });
|
|
594
|
+
await expect(control, at).toBeVisible();
|
|
595
|
+
await expect(control, `${at}: it shows the initials`).toHaveText("AN");
|
|
596
|
+
// The text the control shows assistive technology: its text outside anything aria-hidden.
|
|
597
|
+
const shown = await control.evaluate((button) => {
|
|
598
|
+
const walker = document.createTreeWalker(button, NodeFilter.SHOW_TEXT);
|
|
599
|
+
const texts = [];
|
|
600
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
601
|
+
if (!node.parentElement.closest("[aria-hidden=true]")) texts.push(node.textContent);
|
|
602
|
+
}
|
|
603
|
+
return texts.join(" ");
|
|
604
|
+
});
|
|
605
|
+
const missing = words(shown).filter((word) => !words(name).includes(word));
|
|
606
|
+
assert.deepEqual(missing, [], `${at}: the control shows "${shown.trim()}", which its name "${name}" does not hold`);
|
|
607
|
+
await finish(api);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
|
|
581
611
|
// Material 3's segmented button: one outline, equal segments, the selected one on secondary-container with a check.
|
|
582
612
|
// Register has no "Back to sign in": the Sign in segment is the way back.
|
|
583
613
|
test("Sign in and Register are a segmented button, and Register has no way back but its segment", options, async () => {
|
|
@@ -744,9 +774,12 @@ test("every auth screen's text, its field labels and hints included, reads at WC
|
|
|
744
774
|
const { page } = api;
|
|
745
775
|
const failures = [];
|
|
746
776
|
const readable = async (where) => {
|
|
747
|
-
// The modes fade and move their labels in
|
|
748
|
-
|
|
749
|
-
|
|
777
|
+
// The modes fade and move their labels in, and a button's label fades in over 0.2s: a text that stays under the
|
|
778
|
+
// minimum for the whole wait is a finding. The findings are the wait's own last look; a fresh look once it had
|
|
779
|
+
// settled could land at the start of a fade (a "Register" button label at 0.02 opacity read 1.00:1).
|
|
780
|
+
let findings = [];
|
|
781
|
+
await expect.poll(async () => (findings = await unreadableText(page)), { timeout: 5_000 }).toEqual([]).catch(() => undefined);
|
|
782
|
+
failures.push(...findings.map((finding) => `${where}: ${finding}`));
|
|
750
783
|
};
|
|
751
784
|
for (const colorScheme of ["light", "dark"]) {
|
|
752
785
|
await page.emulateMedia({ colorScheme });
|