From 7774e78e509dcd8cd7b69d5149678956d8cd472c Mon Sep 17 00:00:00 2001 From: Chris Portscheller Date: Mon, 16 Nov 2026 11:51:29 -0600 Subject: [PATCH] test(hono): keep honeytoken tests offline --- packages/hono/src/middleware.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/hono/src/middleware.test.ts b/packages/hono/src/middleware.test.ts index d98be4d..794e67c 100644 --- a/packages/hono/src/middleware.test.ts +++ b/packages/hono/src/middleware.test.ts @@ -84,15 +84,40 @@ describe('the Hono middleware', () => { describe('honeytoken injection through Hono', () => { const withKey = { apiKey: 'sk_live_hono_test', skipLocalAnalysis: true, mode: 'monitor' as const }; + const realFetch = global.fetch; /** The token derives via async HMAC; give it a tick to settle. */ const settle = () => new Promise((r) => setTimeout(r, 50)); + beforeEach(() => { + // These are response-decoration tests, not ingest integration tests. A + // dummy API key must never turn them into live requests or make their + // runtime depend on the production service. + global.fetch = jest.fn(async () => + new Response( + JSON.stringify({ + decision: 'allow', + confidence: 0, + threat_level: 'MINIMAL', + bot_detected: false, + detection_id: 'hono-test', + rule_enforced: false, + }), + { status: 200, headers: { 'content-type': 'application/json' } }, + ), + ) as unknown as typeof fetch; + }); + + afterEach(() => { + global.fetch = realFetch; + }); + it('injects into an HTML response', async () => { const app = appWith(withKey); await settle(); const body = await (await app.request('/page')).text(); expect(body).toMatch(/]*href="\/__wd\//); expect(body).toContain('

hi

'); + expect(global.fetch).toHaveBeenCalledTimes(1); }); it('leaves JSON completely alone', async () => {