@@ -797,19 +797,37 @@ describe("Twilio SMS helpers", () => {
797797 } ) ;
798798 } ) ;
799799
800- it ( "includes non-JSON Twilio error text in send failures" , async ( ) => {
801- const fetchImpl = vi . fn < typeof fetch > (
802- async ( ) => new Response ( "upstream unavailable" , { status : 503 } ) ,
800+ it ( "redacts credentials reflected in Twilio error text" , async ( ) => {
801+ const account = createAccount ( ) ;
802+ const encodedCredential = Buffer . from ( `${ account . accountSid } :${ account . authToken } ` ) . toString (
803+ "base64" ,
803804 ) ;
805+ const fetchImpl = vi . fn < typeof fetch > ( async ( _input , init ) => {
806+ const authorization = new Headers ( init ?. headers ) . get ( "authorization" ) ;
807+ expect ( authorization ) . toBe ( `Basic ${ encodedCredential } ` ) ;
808+ return new Response ( `upstream unavailable; Authorization: ${ authorization } ` , {
809+ status : 503 ,
810+ } ) ;
811+ } ) ;
804812
805- await expect (
806- sendSmsViaTwilio ( {
807- account : createAccount ( ) ,
813+ let caught : ( Error & { responseText : string } ) | undefined ;
814+ try {
815+ await sendSmsViaTwilio ( {
816+ account,
808817 to : "+15551234567" ,
809818 text : "hello" ,
810819 fetchImpl,
811- } ) ,
812- ) . rejects . toThrow ( "Twilio SMS send failed (503): upstream unavailable" ) ;
820+ } ) ;
821+ } catch ( error ) {
822+ caught = error as Error & { responseText : string } ;
823+ }
824+
825+ expect ( caught ) . toMatchObject ( {
826+ message : "Twilio SMS send failed (503): upstream unavailable; Authorization: Basic ***" ,
827+ responseText : "upstream unavailable; Authorization: Basic ***" ,
828+ } ) ;
829+ expect ( caught ?. message ) . not . toContain ( encodedCredential ) ;
830+ expect ( caught ?. responseText ) . not . toContain ( encodedCredential ) ;
813831 } ) ;
814832
815833 it ( "releases guarded Twilio egress on failed send responses" , async ( ) => {
0 commit comments