diff options
| author | Adam Soltys <[email protected]> | 2026-12-03 21:37:06 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-12-03 21:37:06 -0700 |
| commit | 9cb28c714529130a9abf01db489335f764cc853a (patch) | |
| tree | cf61e9d21f4a9f215b6e69f6a894fea870b1f172 /names/lnurl-proxy.test.js | |
| parent | ac1999d50b83bd7a8d5068abebcb0e1756a63eeb (diff) | |
| download | coinosv3-server-9cb28c714529130a9abf01db489335f764cc853a.tar.gz coinosv3-server-9cb28c714529130a9abf01db489335f764cc853a.zip | |
names: /lnurlp-fetch fetches a Lightning address's pay parameters for a browser that can't.
"another thing is coinos cannot reach speed.app wallet, not sure why" (Shark, relayed by Adam 2026-12-04). speed.app answers /.well-known/lnurlp/<name> with a 301 to appapi.tryspeed.com that carries no Access-Control-Allow-Origin, and a browser won't follow a cross-origin redirect without it: from v3.coinos.io the fetch fails ("Failed to fetch"), though the target itself allows any origin. GET /lnurlp-fetch?url=https://<host>/.well-known/lnurlp/<name> fetches it server-side with the link previews' guards (public hosts only, rechecked after every redirect, capped body), https only, that one path only, and returns the pay parameters (200), the host's own error (404) or 502. Rate-limited, cached 5 minutes (30 s for failures). New lnurl-proxy.test.js passes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar
Diffstat (limited to 'names/lnurl-proxy.test.js')
| -rw-r--r-- | names/lnurl-proxy.test.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/names/lnurl-proxy.test.js b/names/lnurl-proxy.test.js new file mode 100644 index 0000000..930844a --- /dev/null +++ b/names/lnurl-proxy.test.js @@ -0,0 +1,35 @@ +// bun test names/lnurl-proxy.test.js +import { test, expect } from 'bun:test'; +import { fetchLnurlPay } from './preview.js'; + +const ok = async (s) => { try { const u = new URL(s); return /internal/.test(u.hostname) ? null : u; } catch { return null; } }; +const pay = { tag: 'payRequest', callback: 'https://api.example/cb', minSendable: 1000, maxSendable: 1e9, metadata: '[]' }; +const site = (routes) => async (url) => { + const r = routes[url]; + if (!r) return new Response('nope', { status: 404 }); + if (r.to) return new Response('', { status: 301, headers: { location: r.to } }); + return Response.json(r.body, { status: r.status || 200 }); +}; + +test('follows a redirect to the pay parameters (speed.app)', async () => { + const f = site({ 'https://speed.example/.well-known/lnurlp/bob': { to: 'https://api.example/.well-known/lnurlp/*/speed/bob' }, + 'https://api.example/.well-known/lnurlp/*/speed/bob': { body: pay } }); + expect(await fetchLnurlPay('https://speed.example/.well-known/lnurlp/bob', f, ok)).toEqual(pay); +}); +test('only a Lightning address path, only https', async () => { + const f = site({ 'https://a.example/anything': { body: pay } }); + expect(await fetchLnurlPay('https://a.example/anything', f, ok)).toBeNull(); + expect(await fetchLnurlPay('http://a.example/.well-known/lnurlp/bob', f, ok)).toBeNull(); +}); +test('a redirect into a private host is refused', async () => { + const f = site({ 'https://a.example/.well-known/lnurlp/bob': { to: 'https://x.internal/secret' } }); + expect(await fetchLnurlPay('https://a.example/.well-known/lnurlp/bob', f, ok)).toBeNull(); +}); +test("the host's own error comes back as an error", async () => { + const f = site({ 'https://a.example/.well-known/lnurlp/bob': { body: { status: 'ERROR', reason: 'no such user' }, status: 404 } }); + expect(await fetchLnurlPay('https://a.example/.well-known/lnurlp/bob', f, ok)).toEqual({ status: 'ERROR', reason: 'no such user' }); +}); +test('anything that is not pay parameters is dropped', async () => { + const f = site({ 'https://a.example/.well-known/lnurlp/bob': { body: { hello: 1 } } }); + expect(await fetchLnurlPay('https://a.example/.well-known/lnurlp/bob', f, ok)).toBeNull(); +}); |
