@@ -97,9 +97,10 @@ jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
9797} ) ) ;
9898
9999// Mock the toast hook
100+ const mockToast = jest . fn ( ) ;
100101jest . mock ( "@/lib/hooks/useToast" , ( ) => ( {
101102 useToast : ( ) => ( {
102- toast : jest . fn ( ) ,
103+ toast : mockToast ,
103104 } ) ,
104105} ) ) ;
105106
@@ -913,6 +914,42 @@ describe("useConnection", () => {
913914 expect ( headers ) . toHaveProperty ( "Authorization" , "Bearer mock-token" ) ;
914915 } ) ;
915916
917+ test ( "warns of enabled empty Bearer token" , async ( ) => {
918+ // This test prevents regression of the bug where default "Bearer " header
919+ // prevented OAuth token injection, causing infinite auth loops
920+ const customHeaders : CustomHeaders = [
921+ {
922+ name : "Authorization" ,
923+ value : "Bearer " , // Empty Bearer token placeholder
924+ enabled : true , // enabled
925+ } ,
926+ ] ;
927+
928+ const propsWithEmptyBearer = {
929+ ...defaultProps ,
930+ customHeaders,
931+ } ;
932+
933+ const { result } = renderHook ( ( ) => useConnection ( propsWithEmptyBearer ) ) ;
934+
935+ await act ( async ( ) => {
936+ await result . current . connect ( ) ;
937+ } ) ;
938+
939+ const headers = mockSSETransport . options ?. requestInit ?. headers ;
940+
941+ expect ( headers ) . toHaveProperty ( "Authorization" , "Bearer" ) ;
942+ // Should not have the x-custom-auth-headers since Authorization is standard
943+ expect ( headers ) . not . toHaveProperty ( "x-custom-auth-headers" ) ;
944+
945+ // Should show toast notification for empty Authorization header
946+ expect ( mockToast ) . toHaveBeenCalledWith ( {
947+ title : "Invalid Authorization Header" ,
948+ description : expect . any ( String ) ,
949+ variant : "destructive" ,
950+ } ) ;
951+ } ) ;
952+
916953 test ( "prioritizes custom headers over legacy auth" , async ( ) => {
917954 const customHeaders : CustomHeaders = [
918955 { name : "Authorization" , value : "Bearer custom-token" , enabled : true } ,
0 commit comments