@@ -228,6 +228,25 @@ describe("exchangeMSTeamsCodeForTokens", () => {
228228 } ) ,
229229 ) . rejects . toThrow ( / M S T e a m s t o k e n e x c h a n g e f a i l e d \( 4 0 0 \) / ) ;
230230 } ) ;
231+
232+ it ( "reports malformed token exchange JSON with a stable OAuth error" , async ( ) => {
233+ fetchSpy . mockResolvedValueOnce (
234+ new Response ( "{ nope" , {
235+ status : 200 ,
236+ headers : { "Content-Type" : "application/json" } ,
237+ } ) ,
238+ ) ;
239+
240+ await expect (
241+ exchangeMSTeamsCodeForTokens ( {
242+ tenantId : "t" ,
243+ clientId : "c" ,
244+ clientSecret : "s" , // pragma: allowlist secret
245+ code : "bad-json" ,
246+ verifier : "v" ,
247+ } ) ,
248+ ) . rejects . toThrow ( "MSTeams token exchange failed: malformed JSON response" ) ;
249+ } ) ;
231250} ) ;
232251
233252describe ( "refreshMSTeamsDelegatedTokens" , ( ) => {
@@ -310,4 +329,22 @@ describe("refreshMSTeamsDelegatedTokens", () => {
310329 } ) ,
311330 ) . rejects . toThrow ( / M S T e a m s t o k e n r e f r e s h f a i l e d \( 4 0 1 \) / ) ;
312331 } ) ;
332+
333+ it ( "reports malformed token refresh JSON with a stable OAuth error" , async ( ) => {
334+ fetchSpy . mockResolvedValueOnce (
335+ new Response ( "{ nope" , {
336+ status : 200 ,
337+ headers : { "Content-Type" : "application/json" } ,
338+ } ) ,
339+ ) ;
340+
341+ await expect (
342+ refreshMSTeamsDelegatedTokens ( {
343+ tenantId : "t" ,
344+ clientId : "c" ,
345+ clientSecret : "s" , // pragma: allowlist secret
346+ refreshToken : "bad-json" ,
347+ } ) ,
348+ ) . rejects . toThrow ( "MSTeams token refresh failed: malformed JSON response" ) ;
349+ } ) ;
313350} ) ;
0 commit comments