aboutsummaryrefslogtreecommitdiffstats
path: root/names/migrate-check.test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-12-02 10:41:29 -0700
committerAdam Soltys <[email protected]>2026-12-02 10:41:29 -0700
commit8076d1323566fe90a43f857384e5e46c257c692a (patch)
tree16282510dc94a9f1e238e60e8be9fc9ede2f9663 /names/migrate-check.test.js
parentc851718782ec8c26d8fd32372ec50a9f7e9efd23 (diff)
downloadcoinosv3-server-8076d1323566fe90a43f857384e5e46c257c692a.tar.gz
coinosv3-server-8076d1323566fe90a43f857384e5e46c257c692a.zip
names: /migrate-grant needs a fresh v3 hand-off stamp from coinos.io.
"Fix the gap" (Adam, 2026-12-02). The reverted check keyed on `migrated`, which coinos.io has set on every new account since 2023, so it stopped nothing (c851718). coinos-server 796999cb now records `v3migrated`, a timestamp set only when an account's own session posts the hand-off, and shows it on /api/users/<name>. The grant follows within seconds, so it goes ahead only when that stamp is under 5 minutes old. That is the same proof as carrying the old account's session to /api/me, without sending coinos.io JWTs (no expiry, no revocation) to this host. A name handed over earlier can't be re-granted to a different key unless its owner hands it over again. Refused: stale, future-dated or missing stamp (409); no such account (404); coinos.io unreachable (502, the caller retries). migrate-check.test.js runs in `bun run test` (18 pass). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SSfVopM1ZzXKZmLYU
Diffstat (limited to 'names/migrate-check.test.js')
-rw-r--r--names/migrate-check.test.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/names/migrate-check.test.js b/names/migrate-check.test.js
new file mode 100644
index 0000000..a1ad725
--- /dev/null
+++ b/names/migrate-check.test.js
@@ -0,0 +1,41 @@
+// bun test names/migrate-check.test.js
+import { test, expect } from 'bun:test';
+import { migrateGrantRefusal, FRESH_MS } from './migrate-check.js';
+
+const NOW = 1_800_000_000_000;
+const coinos = (users, status) => async (url) => {
+ const name = decodeURIComponent(url.split('/').pop());
+ if (status) return new Response('', { status });
+ const u = users[name.toLowerCase()];
+ return u ? Response.json(u) : new Response('{}', { status: 404 });
+};
+const users = {
+ alice: { username: 'Alice', migrated: true, v3migrated: NOW - 5_000 },
+ // every account created since 2023 carries migrated: true; it proves nothing
+ victim: { username: 'victim', migrated: true },
+ bob: { username: 'bob' },
+ stale: { username: 'stale', migrated: true, v3migrated: NOW - FRESH_MS - 1 },
+ future: { username: 'future', v3migrated: NOW + 10 * 60_000 },
+ junk: { username: 'junk', v3migrated: 'yes' },
+};
+const refusal = (n, f = coinos(users)) => migrateGrantRefusal(n, f, NOW);
+
+test('an account that just handed itself over may hand its name over', async () => {
+ expect(await refusal('alice')).toBeNull();
+});
+test('the legacy `migrated` flag alone is not enough', async () => {
+ expect((await refusal('victim'))[0]).toBe(409);
+ expect((await refusal('bob'))[0]).toBe(409);
+});
+test('a hand-off that is stale, from the future, or not a timestamp is refused', async () => {
+ expect((await refusal('stale'))[0]).toBe(409);
+ expect((await refusal('future'))[0]).toBe(409);
+ expect((await refusal('junk'))[0]).toBe(409);
+});
+test('a name with no coinos.io account is refused', async () => {
+ expect((await refusal('nobody'))[0]).toBe(404);
+});
+test("coinos.io down means no grant, and it says to try again", async () => {
+ expect((await refusal('alice', coinos(users, 502)))[0]).toBe(502);
+ expect((await refusal('alice', async () => { throw new Error('net'); }))[0]).toBe(502);
+});