@@ -46,11 +46,11 @@ describe("OAuth Authorization", () => {
46
46
it ( "returns metadata when first fetch fails but second without MCP header succeeds" , async ( ) => {
47
47
// Set up a counter to control behavior
48
48
let callCount = 0 ;
49
-
49
+
50
50
// Mock implementation that changes behavior based on call count
51
51
mockFetch . mockImplementation ( ( _url , _options ) => {
52
52
callCount ++ ;
53
-
53
+
54
54
if ( callCount === 1 ) {
55
55
// First call with MCP header - fail with TypeError (simulating CORS error)
56
56
// We need to use TypeError specifically because that's what the implementation checks for
@@ -68,22 +68,22 @@ describe("OAuth Authorization", () => {
68
68
// Should succeed with the second call
69
69
const metadata = await discoverOAuthMetadata ( "https://auth.example.com" ) ;
70
70
expect ( metadata ) . toEqual ( validMetadata ) ;
71
-
71
+
72
72
// Verify both calls were made
73
73
expect ( mockFetch ) . toHaveBeenCalledTimes ( 2 ) ;
74
-
74
+
75
75
// Verify first call had MCP header
76
76
expect ( mockFetch . mock . calls [ 0 ] [ 1 ] ?. headers ) . toHaveProperty ( "MCP-Protocol-Version" ) ;
77
77
} ) ;
78
78
79
79
it ( "throws an error when all fetch attempts fail" , async ( ) => {
80
80
// Set up a counter to control behavior
81
81
let callCount = 0 ;
82
-
82
+
83
83
// Mock implementation that changes behavior based on call count
84
84
mockFetch . mockImplementation ( ( _url , _options ) => {
85
85
callCount ++ ;
86
-
86
+
87
87
if ( callCount === 1 ) {
88
88
// First call - fail with TypeError
89
89
return Promise . reject ( new TypeError ( "First failure" ) ) ;
@@ -96,7 +96,7 @@ describe("OAuth Authorization", () => {
96
96
// Should fail with the second error
97
97
await expect ( discoverOAuthMetadata ( "https://auth.example.com" ) )
98
98
. rejects . toThrow ( "Second failure" ) ;
99
-
99
+
100
100
// Verify both calls were made
101
101
expect ( mockFetch ) . toHaveBeenCalledTimes ( 2 ) ;
102
102
} ) ;
@@ -250,6 +250,7 @@ describe("OAuth Authorization", () => {
250
250
clientInformation : validClientInfo ,
251
251
authorizationCode : "code123" ,
252
252
codeVerifier : "verifier123" ,
253
+ redirectUri : "http://localhost:3000/callback" ,
253
254
} ) ;
254
255
255
256
expect ( tokens ) . toEqual ( validTokens ) ;
@@ -271,6 +272,7 @@ describe("OAuth Authorization", () => {
271
272
expect ( body . get ( "code_verifier" ) ) . toBe ( "verifier123" ) ;
272
273
expect ( body . get ( "client_id" ) ) . toBe ( "client123" ) ;
273
274
expect ( body . get ( "client_secret" ) ) . toBe ( "secret123" ) ;
275
+ expect ( body . get ( "redirect_uri" ) ) . toBe ( "http://localhost:3000/callback" ) ;
274
276
} ) ;
275
277
276
278
it ( "validates token response schema" , async ( ) => {
@@ -288,6 +290,7 @@ describe("OAuth Authorization", () => {
288
290
clientInformation : validClientInfo ,
289
291
authorizationCode : "code123" ,
290
292
codeVerifier : "verifier123" ,
293
+ redirectUri : "http://localhost:3000/callback" ,
291
294
} )
292
295
) . rejects . toThrow ( ) ;
293
296
} ) ;
@@ -303,6 +306,7 @@ describe("OAuth Authorization", () => {
303
306
clientInformation : validClientInfo ,
304
307
authorizationCode : "code123" ,
305
308
codeVerifier : "verifier123" ,
309
+ redirectUri : "http://localhost:3000/callback" ,
306
310
} )
307
311
) . rejects . toThrow ( "Token exchange failed" ) ;
308
312
} ) ;
0 commit comments