aboutsummaryrefslogtreecommitdiffstats
path: root/names/migrate-check.test.js
diff options
context:
space:
mode:
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);
+});