@@ -103,3 +103,35 @@ async def test_disconnected_endpoint_remains_connection_error():
103103 await LangChainProvider ().send_message (
104104 [ChatMessage (role = "user" , content = "owned prompt" )], config (url )
105105 )
106+
107+
108+ @pytest .mark .asyncio
109+ @pytest .mark .parametrize ("auth,key,custom,required" , [
110+ ("bearer" , "owned-key" , {}, {"Authorization" : "Bearer owned-key" }),
111+ ("basic" , "owned:password" , {}, {"Authorization" : "Basic b3duZWQ6cGFzc3dvcmQ=" }),
112+ ("api_key" , "owned-key" , {}, {"X-API-Key" : "owned-key" }),
113+ ("none" , "" , {"X-Owned-Token" : "owned-token" }, {"X-Owned-Token" : "owned-token" }),
114+ ])
115+ async def test_langserve_authenticated_invoke_uses_configured_headers (monkeypatch , auth , key , custom , required ):
116+ monkeypatch .delenv ("IFIXAI_EXTRA_HEADERS" , raising = False )
117+ seen = []
118+ async def invoke (request ):
119+ seen .append (dict (request .headers ))
120+ if any (request .headers .get (name ) != value for name , value in required .items ()):
121+ return web .json_response ({"detail" : "owned authentication required" }, status = 401 )
122+ return web .json_response ({"output" : "owned authenticated reply" })
123+
124+ app = web .Application ()
125+ app .router .add_post ("/invoke" , invoke )
126+ runner = web .AppRunner (app )
127+ await runner .setup ()
128+ site = web .TCPSite (runner , "127.0.0.1" , 0 )
129+ await site .start ()
130+ url = f"http://127.0.0.1:{ site ._server .sockets [0 ].getsockname ()[1 ]} "
131+ try :
132+ config = ProviderConfig (provider = "langchain" , endpoint = url , auth_method = auth ,
133+ api_key = key , extra_headers = custom , max_retries = 0 )
134+ assert await LangChainProvider ().send_message ([ChatMessage (content = "hello" )], config ) == "owned authenticated reply"
135+ assert len (seen ) == 1
136+ finally :
137+ await runner .cleanup ()
0 commit comments