mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
Merge pull request #1397 from MBombeck/chore/deps-2026-11-15
build(deps): weekly updates, Node 22.23.5 and Next 16.4.6
This commit is contained in:
10 files changed
+668
-325
No files matched your search
@@ -2,10 +2,22 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- API responses and CSV or JSON exports now go out gzip-compressed when the
|
||||
browser or app asks for it, which comes with Next.js 16.4.6. The live Coach
|
||||
and document chat streams are left uncompressed, so their text still
|
||||
arrives as it is written.
|
||||
|
||||
### Fixed
|
||||
|
||||
- A lab marker created from a text result, such as "negative" on a scanned report or a CSV row without a unit, can be edited again. It opens with "No unit" ticked, a rename saves without touching the unit, and the unit can be set while the marker holds only text results. The unit stays locked once numbers are stored under it, and writing the same unit another way (`mg/dl` for `mg/dL`) no longer counts as a change. (#1393)
|
||||
|
||||
### Security
|
||||
|
||||
- The container image moves to Node 22.23.5, a security release with fixes
|
||||
in HTTP, HTTP/2 and TLS handling (CVE-2026-123863 and others).
|
||||
|
||||
## [1.47.6] — 2026-11-15
|
||||
|
||||
### Added
|
||||
|
||||
+6
-6
@@ -17,7 +17,7 @@
|
||||
# future change to one of the stages cannot pair them wrongly.
|
||||
|
||||
# ── Stage 1: Dependencies ──────────────────────────────────
|
||||
FROM node:22-trixie-slim@sha256:be1e2a3dc2c4fd68cdfadad2a696a280e0d2749098bee509230174d72fb768c6 AS deps
|
||||
FROM node:22-trixie-slim@sha256:68c76cfad89921b927eae28ba21407475e29d0ce450afcdbe70c1532db042b64 AS deps
|
||||
RUN corepack enable && corepack prepare pnpm@11.15.1 --activate
|
||||
WORKDIR /app
|
||||
|
||||
@@ -29,7 +29,7 @@ COPY scripts/prepare.mjs scripts/prepare.mjs
|
||||
RUN pnpm install --frozen-lockfile --prod=false
|
||||
|
||||
# ── Stage 2: Build ─────────────────────────────────────────
|
||||
FROM node:22-trixie-slim@sha256:be1e2a3dc2c4fd68cdfadad2a696a280e0d2749098bee509230174d72fb768c6 AS builder
|
||||
FROM node:22-trixie-slim@sha256:68c76cfad89921b927eae28ba21407475e29d0ce450afcdbe70c1532db042b64 AS builder
|
||||
RUN corepack enable && corepack prepare pnpm@11.15.1 --activate
|
||||
WORKDIR /app
|
||||
|
||||
@@ -127,7 +127,7 @@ RUN node scripts/verify-message-catalogs.mjs --dir messages \
|
||||
# npm install never reads. Rebuilding this install both ways confirms it:
|
||||
# without the two fields below npm resolves 1.19.11 and 1.2.0, with them it
|
||||
# resolves 1.19.17 and 1.4.2, and `prisma --version` still reports 7.8.0.
|
||||
FROM node:22-trixie-slim@sha256:be1e2a3dc2c4fd68cdfadad2a696a280e0d2749098bee509230174d72fb768c6 AS prisma-cli
|
||||
FROM node:22-trixie-slim@sha256:68c76cfad89921b927eae28ba21407475e29d0ce450afcdbe70c1532db042b64 AS prisma-cli
|
||||
RUN mkdir -p /opt/prisma-cli && \
|
||||
cd /opt/prisma-cli && \
|
||||
npm init -y && \
|
||||
@@ -136,7 +136,7 @@ RUN mkdir -p /opt/prisma-cli && \
|
||||
npm pkg set 'overrides.@hono/node-server=^2.1.3' && \
|
||||
npm pkg set 'overrides.valibot=^1.4.2' && \
|
||||
npm pkg set 'allowScripts.@prisma/engines=true' 'allowScripts.prisma=true' 'allowScripts.esbuild=true' --json && \
|
||||
npm install --omit=dev prisma@7.10.1 @prisma/engines@7.10.1 tsx@4.23.1 dotenv@18.0.9 --no-fund --no-audit
|
||||
npm install --omit=dev prisma@7.10.1 @prisma/engines@7.10.1 tsx@4.23.1 dotenv@18.0.10 --no-fund --no-audit
|
||||
|
||||
# ── Stage 4: PostgreSQL client ─────────────────────────────
|
||||
# pg_dump and pg_restore of the bundled database's major, taken from the
|
||||
@@ -150,7 +150,7 @@ RUN mkdir -p /opt/prisma-cli && \
|
||||
# does for the bundled database. The libpq file is found through the loader
|
||||
# rather than by an architecture path, so the step is the same on amd64 and
|
||||
# arm64.
|
||||
FROM postgres:18.6-trixie@sha256:3a4264520e121176619f54ff867d12774bc81e95e7b84db58d63bccdb6144b81 AS pgclient
|
||||
FROM postgres:18.6-trixie@sha256:e3d24f6906d0760bf4da0dae872415391ededefad23fd471c47dc53b0ddf3c42 AS pgclient
|
||||
RUN set -eu; \
|
||||
mkdir -p /out/bin /out/lib; \
|
||||
cp /usr/lib/postgresql/18/bin/pg_dump /usr/lib/postgresql/18/bin/pg_restore /out/bin/; \
|
||||
@@ -159,7 +159,7 @@ RUN set -eu; \
|
||||
cp -L "$LIBPQ" /out/lib/libpq.so.5
|
||||
|
||||
# ── Stage 5: Production runner ─────────────────────────────
|
||||
FROM node:22-trixie-slim@sha256:be1e2a3dc2c4fd68cdfadad2a696a280e0d2749098bee509230174d72fb768c6 AS runner
|
||||
FROM node:22-trixie-slim@sha256:68c76cfad89921b927eae28ba21407475e29d0ce450afcdbe70c1532db042b64 AS runner
|
||||
# The package managers the base ships (npm, npx, corepack, yarn) go first.
|
||||
# Nothing at runtime installs a package, and the bundled npm carried the only
|
||||
# HIGH findings with a fix the image scan reported. Removed in a later layer,
|
||||
|
||||
@@ -217,8 +217,15 @@ async function attemptCount(page: Page): Promise<number> {
|
||||
* sync-from-server shape, no effect involved. A value typed into the input
|
||||
* before that copy runs is silently replaced by the server's, so the save that
|
||||
* follows persists an empty field and the next request is refused for a reason
|
||||
* that points nowhere near the test. Waiting for the two reads is what makes
|
||||
* the copy already done rather than pending.
|
||||
* that points nowhere near the test.
|
||||
*
|
||||
* Waiting for the two reads alone is not enough. Playwright settles a
|
||||
* response on its headers, and the body can follow later: API responses are
|
||||
* compressed, and the compressed body reaches the socket only after a round
|
||||
* through zlib on the thread pool, which a loaded runner can hold up. The copy
|
||||
* runs only once the body is parsed. Each card keeps its enable switch
|
||||
* disabled until its read has landed and does the copy in that same render,
|
||||
* so an enabled switch is the signal that the seed is in the input.
|
||||
*/
|
||||
async function openChannels(page: Page): Promise<void> {
|
||||
const seeded = ["/api/settings/email", "/api/settings/ntfy"].map((endpoint) =>
|
||||
@@ -231,6 +238,8 @@ async function openChannels(page: Page): Promise<void> {
|
||||
await page.goto("/settings/integrations", { waitUntil: "domcontentloaded" });
|
||||
await expect(page.locator(CHANNELS_PANEL)).toBeVisible({ timeout: 30_000 });
|
||||
await Promise.all(seeded);
|
||||
await expect(page.locator("#email-toggle")).toBeEnabled();
|
||||
await expect(page.locator("#ntfy-toggle")).toBeEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+14
-14
@@ -54,38 +54,38 @@
|
||||
"mcp:stdio": "npx tsx src/cli/mcp-stdio.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.1162.0",
|
||||
"@aws-sdk/lib-storage": "3.1162.0",
|
||||
"@aws-sdk/client-s3": "^3.1167.0",
|
||||
"@aws-sdk/lib-storage": "3.1167.0",
|
||||
"@dnd-kit/core": "^6.3.1",
|
||||
"@dnd-kit/sortable": "^10.0.0",
|
||||
"@dnd-kit/utilities": "^3.2.2",
|
||||
"@modelcontextprotocol/sdk": "^1.32.2",
|
||||
"@napi-rs/canvas": "1.1.0",
|
||||
"@napi-rs/canvas": "1.1.1",
|
||||
"@node-rs/argon2": "^2.2.2",
|
||||
"@parse/node-apn": "^8.2.0",
|
||||
"@prisma/adapter-pg": "^7.10.1",
|
||||
"@prisma/client": "^7.10.1",
|
||||
"@simplewebauthn/browser": "^14.0.0",
|
||||
"@simplewebauthn/server": "^14.0.3",
|
||||
"@tanstack/react-query": "5.106.1",
|
||||
"@simplewebauthn/server": "^14.1.0",
|
||||
"@tanstack/react-query": "5.107.1",
|
||||
"@tanstack/react-virtual": "^3.14.26",
|
||||
"@types/sax": "^1.2.7",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"date-fns": "^4.4.0",
|
||||
"dotenv": "^18.0.9",
|
||||
"dotenv": "^18.0.10",
|
||||
"fflate": "^0.8.3",
|
||||
"jose": "^6.2.15",
|
||||
"jose": "^6.2.17",
|
||||
"jspdf": "^4.2.1",
|
||||
"jspdf-autotable": "^5.0.9",
|
||||
"lucide-react": "^1.69.0",
|
||||
"mmdb-lib": "^3.0.4",
|
||||
"next": "16.4.5",
|
||||
"nodemailer": "10.3.1",
|
||||
"lucide-react": "^1.72.0",
|
||||
"mmdb-lib": "^3.0.5",
|
||||
"next": "16.4.6",
|
||||
"nodemailer": "10.5.0",
|
||||
"otpauth": "^9.6.0",
|
||||
"p-limit": "^7.3.3",
|
||||
"pg": "^8.23.1",
|
||||
"pg-boss": "^12.38.1",
|
||||
"pg-boss": "^12.38.2",
|
||||
"prisma": "^7.10.1",
|
||||
"qrcode": "^1.5.4",
|
||||
"radix-ui": "^1.8.1",
|
||||
@@ -99,7 +99,7 @@
|
||||
"tailwind-merge": "^3.7.0",
|
||||
"tesseract.js": "^7.0.0",
|
||||
"undici": "^8.12.4",
|
||||
"web-push": "^3.6.7",
|
||||
"web-push": "^4.0.0",
|
||||
"yaml": "^2.9.1",
|
||||
"zod": "^4.6.7",
|
||||
"zod-openapi": "^6.0.2",
|
||||
@@ -125,7 +125,7 @@
|
||||
"@vitest/coverage-v8": "^5.1.0",
|
||||
"ajv": "^8.20.0",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.4.5",
|
||||
"eslint-config-next": "16.4.6",
|
||||
"fast-check": "4.10.2",
|
||||
"knip": "^6.45.1",
|
||||
"lefthook": "^2.2.2",
|
||||
|
||||
Generated
+323
-301
File diff suppressed because it is too large.
Load diff
@@ -228,7 +228,7 @@ describe("release container inputs", () => {
|
||||
expect(fromLines).toHaveLength(4);
|
||||
expect(new Set(fromLines.map((line) => line.split(" AS ")[0]))).toEqual(
|
||||
new Set([
|
||||
"FROM node:22-trixie-slim@sha256:be1e2a3dc2c4fd68cdfadad2a696a280e0d2749098bee509230174d72fb768c6",
|
||||
"FROM node:22-trixie-slim@sha256:68c76cfad89921b927eae28ba21407475e29d0ce450afcdbe70c1532db042b64",
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Every response this app streams as Server-Sent Events says
|
||||
* `Cache-Control: no-transform`.
|
||||
*
|
||||
* Next.js compresses route-handler responses for a client that accepts it
|
||||
* (since 16.4.6), and its compression middleware skips a response only when
|
||||
* the type is not compressible or `Cache-Control` carries `no-transform`.
|
||||
* `text/event-stream` is compressible, so without the directive a Coach or
|
||||
* document-chat stream would go out gzipped: every token a separate deflate
|
||||
* flush, and a proxy that buffers compressed bodies would hold the reply until
|
||||
* it ends. The directive is what keeps the stream as written.
|
||||
*
|
||||
* The guard finds the SSE surfaces by the content type they declare, so a new
|
||||
* one is covered without being listed, and it fails if it finds none, which
|
||||
* would mean the matcher went blind rather than that the surfaces went away.
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
readSourceText,
|
||||
stripComments,
|
||||
walkSourceFiles,
|
||||
} from "./helpers/source-files";
|
||||
|
||||
const SRC = join(process.cwd(), "src");
|
||||
|
||||
/** A `Content-Type` header literal (either quote style) naming SSE. */
|
||||
const SSE_CONTENT_TYPE = /["']?content-type["']?\s*:\s*["']text\/event-stream/i;
|
||||
/** A `Cache-Control` header literal whose value lists `no-transform`. */
|
||||
const NO_TRANSFORM =
|
||||
/["']?cache-control["']?\s*:\s*["'][^"']*\bno-transform\b/i;
|
||||
|
||||
function sseSurfaces(): string[] {
|
||||
return walkSourceFiles(SRC, { floor: 3000 })
|
||||
.filter((p) => !p.startsWith("generated/"))
|
||||
.filter((p) => !p.includes("__tests__"))
|
||||
.filter((p) => !p.endsWith(".test.ts") && !p.endsWith(".test.tsx"))
|
||||
.filter((p) =>
|
||||
SSE_CONTENT_TYPE.test(stripComments(readSourceText(join(SRC, p)), p)),
|
||||
)
|
||||
.sort();
|
||||
}
|
||||
|
||||
describe("SSE responses opt out of compression", () => {
|
||||
it("finds the SSE surfaces it is meant to watch", () => {
|
||||
// The Coach turn and the fenced document chat today.
|
||||
const surfaces = sseSurfaces();
|
||||
expect(surfaces.length).toBeGreaterThanOrEqual(2);
|
||||
expect(surfaces).toEqual(
|
||||
expect.arrayContaining([
|
||||
"lib/ai/coach/turn/sse.ts",
|
||||
"lib/documents/fenced-chat.ts",
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("sets Cache-Control: no-transform wherever it declares text/event-stream", () => {
|
||||
const missing = sseSurfaces().filter(
|
||||
(p) => !NO_TRANSFORM.test(stripComments(readSourceText(join(SRC, p)), p)),
|
||||
);
|
||||
expect(missing).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -791,6 +791,10 @@ describe("stored credentials", () => {
|
||||
userVerified: info.userVerified,
|
||||
origin: info.origin,
|
||||
rpID: info.rpID,
|
||||
// Filled only when a FIDO metadata service has been initialised, which
|
||||
// downloads from the FIDO Alliance. HealthLog never initialises one, so
|
||||
// registration stays offline and this stays undefined.
|
||||
passkeyProviderMetadata: info.passkeyProviderMetadata ?? "absent",
|
||||
registrationInfoKeys: Object.keys(info).sort(),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
@@ -802,6 +806,7 @@ describe("stored credentials", () => {
|
||||
"credentialType": "public-key",
|
||||
"fmt": "none",
|
||||
"origin": "https://health.example.test",
|
||||
"passkeyProviderMetadata": "absent",
|
||||
"publicKeyHex": "a50102032620012158202a40dff8de2ee1ba264ae10e05136e3933839a3bf5a24fb40672a2fb90bccf722258205508587675cda220cac807aa2bb93596dc3ce76590eb728fab4d00dbda17d4b4",
|
||||
"registrationInfoKeys": [
|
||||
"aaguid",
|
||||
@@ -813,6 +818,7 @@ describe("stored credentials", () => {
|
||||
"credentialType",
|
||||
"fmt",
|
||||
"origin",
|
||||
"passkeyProviderMetadata",
|
||||
"rpID",
|
||||
"userVerified",
|
||||
],
|
||||
|
||||
@@ -18,7 +18,7 @@ describe("pg-boss failed-row ledger retention", () => {
|
||||
) as { version: string };
|
||||
const plans = readFileSync(join(PG_BOSS_ROOT, "dist/plans.js"), "utf8");
|
||||
|
||||
expect(packageJson.version).toBe("12.38.1");
|
||||
expect(packageJson.version).toBe("12.38.2");
|
||||
expect(plans).toContain("retention_seconds: FORTEEN_DAYS");
|
||||
expect(plans).toContain("deletion_seconds: SEVEN_DAYS");
|
||||
// 12.37 reads the clock through job_now(), which is pg_catalog.now()
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Wire contract between HealthLog and `web-push`, exercised against the real
|
||||
* library rather than a mock.
|
||||
*
|
||||
* Every sender test mocks `web-push`, so a major bump of it would pass them
|
||||
* all while changing what a push service receives. The sender only borrows
|
||||
* three functions from the library (`generateVAPIDKeys`, `setVapidDetails`,
|
||||
* `generateRequestDetails`) and dials the result itself through `safeFetch`,
|
||||
* so this file pins what those three must keep doing:
|
||||
*
|
||||
* 1. They are reachable on the namespace a dynamic `import("web-push")`
|
||||
* returns, which is how the sender and the VAPID route load the library.
|
||||
* 2. A VAPID key pair stored before an upgrade is still accepted, and a fresh
|
||||
* one has the same shape.
|
||||
* 3. The request a subscription gets: method, the RFC 8030 headers (TTL,
|
||||
* Urgency, aes128gcm encoding), a VAPID `Authorization` whose JWT verifies
|
||||
* against the public key and names the endpoint's origin, and a body the
|
||||
* subscriber's keys decrypt back to the exact payload (RFC 8291).
|
||||
*/
|
||||
import {
|
||||
createECDH,
|
||||
createHash,
|
||||
createDecipheriv,
|
||||
createHmac,
|
||||
createPublicKey,
|
||||
randomBytes,
|
||||
verify,
|
||||
} from "node:crypto";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const ENDPOINT = "https://push.example.test/send/abc123?x=1";
|
||||
const SUBJECT = "mailto:operator@example.test";
|
||||
|
||||
/** A P-256 key pair from a fixed seed, so its encoded form is stable. */
|
||||
function fixedVapidKeys() {
|
||||
const ecdh = createECDH("prime256v1");
|
||||
ecdh.setPrivateKey(createHash("sha256").update("healthlog-vapid").digest());
|
||||
return {
|
||||
publicKey: ecdh.getPublicKey().toString("base64url"),
|
||||
privateKey: ecdh.getPrivateKey().toString("base64url"),
|
||||
};
|
||||
}
|
||||
|
||||
/** A browser-side subscription: its own P-256 key pair plus an auth secret. */
|
||||
function subscriber() {
|
||||
const ecdh = createECDH("prime256v1");
|
||||
ecdh.generateKeys();
|
||||
const auth = randomBytes(16);
|
||||
return {
|
||||
ecdh,
|
||||
auth,
|
||||
subscription: {
|
||||
endpoint: ENDPOINT,
|
||||
keys: {
|
||||
p256dh: ecdh.getPublicKey().toString("base64url"),
|
||||
auth: auth.toString("base64url"),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function hmac(key: Buffer, data: Buffer): Buffer {
|
||||
return createHmac("sha256", key).update(data).digest();
|
||||
}
|
||||
|
||||
/** RFC 8291 / RFC 8188 decryption of a single-record aes128gcm body. */
|
||||
function decryptAes128gcm(
|
||||
body: Buffer,
|
||||
ecdh: ReturnType<typeof createECDH>,
|
||||
auth: Buffer,
|
||||
) {
|
||||
const salt = body.subarray(0, 16);
|
||||
const recordSize = body.readUInt32BE(16);
|
||||
const idLength = body[20]!;
|
||||
const serverPublic = body.subarray(21, 21 + idLength);
|
||||
const record = body.subarray(21 + idLength);
|
||||
expect(record.length).toBeLessThanOrEqual(recordSize);
|
||||
|
||||
const shared = ecdh.computeSecret(serverPublic);
|
||||
const keyInfo = Buffer.concat([
|
||||
Buffer.from("WebPush: info\0"),
|
||||
ecdh.getPublicKey(),
|
||||
serverPublic,
|
||||
]);
|
||||
const ikm = hmac(
|
||||
hmac(auth, shared),
|
||||
Buffer.concat([keyInfo, Buffer.from([1])]),
|
||||
);
|
||||
const prk = hmac(salt, ikm);
|
||||
const cek = hmac(
|
||||
prk,
|
||||
Buffer.from("Content-Encoding: aes128gcm\0\x01"),
|
||||
).subarray(0, 16);
|
||||
const nonce = hmac(
|
||||
prk,
|
||||
Buffer.from("Content-Encoding: nonce\0\x01"),
|
||||
).subarray(0, 12);
|
||||
|
||||
const decipher = createDecipheriv("aes-128-gcm", cek, nonce);
|
||||
decipher.setAuthTag(record.subarray(record.length - 16));
|
||||
const padded = Buffer.concat([
|
||||
decipher.update(record.subarray(0, record.length - 16)),
|
||||
decipher.final(),
|
||||
]);
|
||||
// The last record ends in the 0x02 delimiter followed by zero padding.
|
||||
let end = padded.length - 1;
|
||||
while (end >= 0 && padded[end] === 0) end -= 1;
|
||||
expect(padded[end]).toBe(2);
|
||||
return padded.subarray(0, end).toString("utf8");
|
||||
}
|
||||
|
||||
function verifyVapidJwt(jwt: string, publicKeyB64: string) {
|
||||
const [header, claims, signature] = jwt.split(".");
|
||||
const point = Buffer.from(publicKeyB64, "base64url");
|
||||
const key = createPublicKey({
|
||||
key: {
|
||||
kty: "EC",
|
||||
crv: "P-256",
|
||||
x: point.subarray(1, 33).toString("base64url"),
|
||||
y: point.subarray(33, 65).toString("base64url"),
|
||||
},
|
||||
format: "jwk",
|
||||
});
|
||||
const valid = verify(
|
||||
"sha256",
|
||||
Buffer.from(`${header}.${claims}`),
|
||||
{ key, dsaEncoding: "ieee-p1363" },
|
||||
Buffer.from(signature!, "base64url"),
|
||||
);
|
||||
return {
|
||||
valid,
|
||||
header: JSON.parse(Buffer.from(header!, "base64url").toString()),
|
||||
claims: JSON.parse(Buffer.from(claims!, "base64url").toString()),
|
||||
};
|
||||
}
|
||||
|
||||
type RequestDetails = {
|
||||
endpoint: string;
|
||||
method: string;
|
||||
headers: Record<string, string | number>;
|
||||
body: Buffer | null;
|
||||
};
|
||||
|
||||
describe("web-push library contract", () => {
|
||||
it("exposes the three functions on the dynamically imported namespace", async () => {
|
||||
const webpush = await import("web-push");
|
||||
expect(typeof webpush.generateVAPIDKeys).toBe("function");
|
||||
expect(typeof webpush.setVapidDetails).toBe("function");
|
||||
expect(typeof webpush.generateRequestDetails).toBe("function");
|
||||
});
|
||||
|
||||
it("accepts a stored VAPID pair and mints new ones of the same shape", async () => {
|
||||
const webpush = await import("web-push");
|
||||
const stored = fixedVapidKeys();
|
||||
expect(() =>
|
||||
webpush.setVapidDetails(SUBJECT, stored.publicKey, stored.privateKey),
|
||||
).not.toThrow();
|
||||
|
||||
const fresh = webpush.generateVAPIDKeys();
|
||||
expect(Buffer.from(fresh.publicKey, "base64url")).toHaveLength(65);
|
||||
expect(Buffer.from(fresh.privateKey, "base64url")).toHaveLength(32);
|
||||
expect(fresh.publicKey).toMatch(/^[A-Za-z0-9_-]+$/);
|
||||
expect(fresh.privateKey).toMatch(/^[A-Za-z0-9_-]+$/);
|
||||
});
|
||||
|
||||
it("builds a signed, encrypted request the subscriber can open", async () => {
|
||||
const webpush = await import("web-push");
|
||||
const vapid = fixedVapidKeys();
|
||||
webpush.setVapidDetails(SUBJECT, vapid.publicKey, vapid.privateKey);
|
||||
const { ecdh, auth, subscription } = subscriber();
|
||||
const payload = JSON.stringify({
|
||||
title: "Reminder",
|
||||
body: "Täglich 08:00",
|
||||
});
|
||||
|
||||
const details = webpush.generateRequestDetails(
|
||||
subscription,
|
||||
payload,
|
||||
) as unknown as RequestDetails;
|
||||
|
||||
expect(details.endpoint).toBe(ENDPOINT);
|
||||
expect(details.method).toBe("POST");
|
||||
expect(Object.keys(details.headers).sort()).toEqual([
|
||||
"Authorization",
|
||||
"Content-Encoding",
|
||||
"Content-Length",
|
||||
"Content-Type",
|
||||
"TTL",
|
||||
"Urgency",
|
||||
]);
|
||||
// The sender passes no TTL, so the library default is what a push
|
||||
// service is told to hold an undelivered reminder for: four weeks.
|
||||
expect(String(details.headers.TTL)).toBe("2419200");
|
||||
expect(details.headers.Urgency).toBe("normal");
|
||||
expect(details.headers["Content-Encoding"]).toBe("aes128gcm");
|
||||
expect(details.headers["Content-Type"]).toBe("application/octet-stream");
|
||||
expect(Buffer.isBuffer(details.body)).toBe(true);
|
||||
expect(Number(details.headers["Content-Length"])).toBe(
|
||||
details.body!.length,
|
||||
);
|
||||
|
||||
const auth_ = String(details.headers.Authorization);
|
||||
const match = /^vapid t=([^,]+), k=(.+)$/.exec(auth_);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![2]).toBe(vapid.publicKey);
|
||||
const jwt = verifyVapidJwt(match![1]!, vapid.publicKey);
|
||||
expect(jwt.valid).toBe(true);
|
||||
expect(jwt.header).toEqual({ typ: "JWT", alg: "ES256" });
|
||||
expect(jwt.claims.aud).toBe("https://push.example.test");
|
||||
expect(jwt.claims.sub).toBe(SUBJECT);
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
expect(jwt.claims.exp).toBeGreaterThan(now);
|
||||
expect(jwt.claims.exp).toBeLessThanOrEqual(now + 24 * 60 * 60);
|
||||
|
||||
expect(decryptAes128gcm(details.body!, ecdh, auth)).toBe(payload);
|
||||
});
|
||||
|
||||
it("carries the Urgency the sender asks for on an urgent event", async () => {
|
||||
const webpush = await import("web-push");
|
||||
const vapid = fixedVapidKeys();
|
||||
webpush.setVapidDetails(SUBJECT, vapid.publicKey, vapid.privateKey);
|
||||
const { subscription } = subscriber();
|
||||
|
||||
const details = webpush.generateRequestDetails(subscription, "{}", {
|
||||
urgency: "high",
|
||||
}) as unknown as RequestDetails;
|
||||
|
||||
expect(details.headers.Urgency).toBe("high");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user