@@ -10,9 +10,13 @@ import http from "node:http";
1010import { createRequire } from "node:module" ;
1111import net from "node:net" ;
1212import path from "node:path" ;
13- import zlib from "node:zlib" ;
1413import { vi } from "vitest" ;
15- import { handleHermesBrokerCoexistencePortal } from "./helpers/hermes-tool-gateway-broker-fixture" ;
14+ import {
15+ handleHermesBrokerCoexistencePortal ,
16+ handleHermesBrokerUpstream ,
17+ HERMES_BROKER_REDIRECT_TARGET ,
18+ type HermesBrokerUpstreamRequest ,
19+ } from "./helpers/hermes-tool-gateway-broker-fixture" ;
1620import {
1721 describe ,
1822 expect ,
@@ -988,32 +992,9 @@ describe("Hermes managed-tool gateway broker", () => {
988992 ) ;
989993 const portalPort = await listen ( portal ) ;
990994
991- const upstreamRequests : Array < {
992- url ?: string ;
993- authorization ?: string ;
994- browserUseApiKey ?: string ;
995- apiKey ?: string ;
996- acceptEncoding ?: string ;
997- } > = [ ] ;
995+ const upstreamRequests : HermesBrokerUpstreamRequest [ ] = [ ] ;
998996 const upstream = resources . ownServer (
999- http . createServer ( ( req , res ) => {
1000- upstreamRequests . push ( {
1001- url : req . url ,
1002- authorization : req . headers . authorization ,
1003- browserUseApiKey : req . headers [ "x-browser-use-api-key" ] as string | undefined ,
1004- apiKey : req . headers [ "x-api-key" ] as string | undefined ,
1005- acceptEncoding : req . headers [ "accept-encoding" ] as string | undefined ,
1006- } ) ;
1007- const body = zlib . gzipSync ( JSON . stringify ( { ok : true , path : req . url } ) ) ;
1008- res . writeHead ( 200 , {
1009- "Content-Type" : "application/json" ,
1010- "Content-Encoding" : "gzip" ,
1011- "Content-Length" : String ( body . length ) ,
1012- "Content-MD5" : "not-a-real-digest" ,
1013- "Set-Cookie" : "fixture_session=1; HttpOnly; Secure; SameSite=Strict" ,
1014- } ) ;
1015- res . end ( body ) ;
1016- } ) ,
997+ http . createServer ( ( req , res ) => handleHermesBrokerUpstream ( upstreamRequests , req , res ) ) ,
1017998 ) ;
1018999 const upstreamPort = await listen ( upstream ) ;
10191000 const matrixPath = path . join ( tmp , "matrix.json" ) ;
@@ -1165,6 +1146,17 @@ describe("Hermes managed-tool gateway broker", () => {
11651146 url : "/sandboxes" ,
11661147 authorization : "Bearer access-2" ,
11671148 } ) ;
1149+
1150+ const redirect = await fetch ( `http://127.0.0.1:${ brokerPort } /firecrawl/v1/redirect-probe` , {
1151+ headers : { "x-api-key" : "refresh-2" } ,
1152+ redirect : "manual" ,
1153+ } ) ;
1154+ const redirectBody = await redirect . text ( ) ;
1155+ expect ( upstreamRequests . at ( - 1 ) ?. url ) . toBe ( "/v1/redirect-probe" ) ;
1156+ expect ( redirect . status ) . toBe ( 502 ) ;
1157+ expect ( redirect . headers . get ( "location" ) ) . toBeNull ( ) ;
1158+ expect ( redirectBody ) . toContain ( "redirect" ) ;
1159+ expect ( redirectBody ) . not . toContain ( HERMES_BROKER_REDIRECT_TARGET ) ;
11681160 expect ( tokenRequests ) . toHaveLength ( 1 ) ;
11691161 expect ( agentKeyRequests ) . toHaveLength ( 1 ) ;
11701162 expect ( output ) . not . toContain ( "refresh-1" ) ;
0 commit comments