From 6854a650fbc97bef8cdee574fb4eb3bcd6d5fcf1 Mon Sep 17 00:00:00 2001 From: Aran Roig Date: Mon, 19 Oct 2026 19:13:57 +0200 Subject: [PATCH] jkdsjkd --- backend/src/services/service-links.js | 4 ++++ tests/service-link-target.test.js | 30 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/service-link-target.test.js diff --git a/backend/src/services/service-links.js b/backend/src/services/service-links.js index e99ee8e9..c1775322 100644 --- a/backend/src/services/service-links.js +++ b/backend/src/services/service-links.js @@ -13,6 +13,10 @@ const NOTIFICATION_WINDOW_MS = 15 * 60 * 1000; // somebody to open the sign-up link again every 48 hours. It carries the id of the link so that // revoking the link works right away — see services/passport.js. const OBSIDIAN_TOKEN_TTL = '365d'; +// A service describes itself with a handful of short values (its Foundry system, its Discord +// user id...), and those are shown to the user who answers the link, so both are capped. +const MAX_META_ENTRIES = 10; +const MAX_META_VALUE_LENGTH = 200; // Every service that connects to a campaign does it the same way: it asks the // backend for a sign-up link, shows it to the person sitting in front of it, diff --git a/tests/service-link-target.test.js b/tests/service-link-target.test.js new file mode 100644 index 00000000..eeecf51d --- /dev/null +++ b/tests/service-link-target.test.js @@ -0,0 +1,30 @@ +// A service asking for its sign-up link describes itself in `target`; the backend +// keeps only the short, plain values it can show the user who answers the link. +// Run with `npm test` from the repository root, or `node --test tests/`. + +const { test } = require("node:test"); +const assert = require("node:assert/strict"); + +const serviceLinks = require("../backend/src/services/service-links"); + +test("a link request keeps the service metadata short and plain", () => { + const target = serviceLinks.readTarget({ + target: { + id: "world-1", + name: "Test World", + user: "Test GM", + meta: { + system: "dnd5e", + url: "https://vtt.test/some/path", + nested: { ignored: true }, + long: "x".repeat(500), + }, + }, + }); + + assert.equal(target.targetId, "world-1"); + assert.equal(target.targetMeta.system, "dnd5e"); + assert.equal(target.targetMeta.url, "https://vtt.test", "only the origin of the world URL is kept"); + assert.equal(target.targetMeta.nested, undefined, "objects are not copied into the metadata"); + assert.equal(target.targetMeta.long.length, 200, "long values are cut to the metadata limit"); +});