@@ -180,6 +180,38 @@ test("GET /healthz returns 503 when drand is down", async () => {
180180 assert . equal ( res . status , 503 ) ;
181181 const body = res . body as Record < string , unknown > ;
182182 assert . equal ( body . ok , false ) ;
183+ assert . equal ( body . reason , "health check failed" ) ;
184+ assert . doesNotMatch ( JSON . stringify ( body ) , / d r a n d d o w n / ) ;
185+ } ,
186+ ) ;
187+ } ) ;
188+
189+ test ( "GET /healthz redacts secret-bearing upstream errors from the response body" , async ( ) => {
190+ const secretRpc = "https://rpc.example.internal/secret-token-abc123" ;
191+ await withServer (
192+ makeSource ( {
193+ reader : {
194+ getRound : async ( ) => {
195+ throw new Error ( `connection refused to ${ secretRpc } ` ) ;
196+ } ,
197+ getBidState : async ( ) => ( { revealed_value : null } ) as never ,
198+ } ,
199+ drand : {
200+ chain : ( ) => ( {
201+ info : async ( ) => {
202+ throw new Error ( `connection refused to ${ secretRpc } ` ) ;
203+ } ,
204+ } ) ,
205+ } as never ,
206+ } ) ,
207+ async ( server ) => {
208+ const res = await get ( server , "/healthz" ) ;
209+ assert . equal ( res . status , 503 ) ;
210+ const body = res . body as Record < string , unknown > ;
211+ assert . equal ( body . reason , "health check failed" ) ;
212+ const serialized = JSON . stringify ( body ) ;
213+ assert . doesNotMatch ( serialized , / s e c r e t - t o k e n - a b c 1 2 3 / ) ;
214+ assert . doesNotMatch ( serialized , / r p c \. e x a m p l e \. i n t e r n a l / ) ;
183215 } ,
184216 ) ;
185217} ) ;
0 commit comments