import { test } from 'node:test'; import assert from 'node:assert/strict'; import { startCallback } from '../callback.js'; test('OAuth callback ignores invalid state and accepts matching code', async () => { const uri = 'http://127.0.0.1:18765/oauth/callback'; const listener = await startCallback(uri, 'expected', 2000); try { assert.equal((await fetch(`${uri}?code=bad&state=wrong`)).status, 400); assert.equal((await fetch(`${uri}?code=good&state=expected`)).status, 200); assert.equal(await listener.result, 'good'); } finally { listener.close(); } }); test('OAuth callback rejects non-loopback addresses', async () => { await assert.rejects(startCallback('http://0.0.0.0:8765/oauth/callback', 'state')); });