@@ -270,6 +270,47 @@ describe("chutes plugin OAuth", () => {
270270 expect ( timeoutSpy ) . toHaveBeenCalledTimes ( 2 ) ;
271271 } ) ;
272272
273+ it ( "cancels the userinfo error response body when profile lookup fails" , async ( ) => {
274+ let canceled = false ;
275+ let bytesPulled = 0 ;
276+ const userInfoResponse = new Response (
277+ new ReadableStream < Uint8Array > ( {
278+ pull ( controller ) {
279+ if ( bytesPulled > 0 ) {
280+ controller . close ( ) ;
281+ return ;
282+ }
283+ bytesPulled += 1 ;
284+ controller . enqueue ( new TextEncoder ( ) . encode ( "temporarily unavailable" ) ) ;
285+ } ,
286+ cancel ( ) {
287+ canceled = true ;
288+ } ,
289+ } ) ,
290+ { status : 503 } ,
291+ ) ;
292+ const fetchFn = vi . fn ( async ( input : RequestInfo | URL ) => {
293+ const url = fetchInputUrl ( input ) ;
294+ if ( url === CHUTES_TOKEN_ENDPOINT ) {
295+ return new Response (
296+ '{"access_token":"at_123","refresh_token":"rt_123","expires_in":3600}' ,
297+ { status : 200 , headers : { "Content-Type" : "application/json" } } ,
298+ ) ;
299+ }
300+ if ( url === CHUTES_USERINFO_ENDPOINT ) {
301+ return userInfoResponse ;
302+ }
303+ return new Response ( "not found" , { status : 404 } ) ;
304+ } ) ;
305+
306+ const credentials = await loginWithFetch ( fetchFn ) ;
307+
308+ expect ( canceled ) . toBe ( true ) ;
309+ expect ( credentials . access ) . toBe ( "at_123" ) ;
310+ expect ( credentials . email ) . toBeUndefined ( ) ;
311+ expect ( credentials . accountId ) . toBeUndefined ( ) ;
312+ } ) ;
313+
273314 it ( "cancels authentication when the caller aborts during userinfo" , async ( ) => {
274315 const controller = new AbortController ( ) ;
275316 const reason = new Error ( "cancelled by caller" ) ;
0 commit comments