@@ -16,7 +16,10 @@ jest.mock('express', () => {
1616 return express ;
1717} ) ;
1818
19- jest . mock ( 'cors' , ( ) => jest . fn ( ( ) => 'cors-middleware' ) ) ;
19+ jest . mock ( '../../../server/transport/security.js' , ( ) => ( {
20+ createCorsMiddleware : jest . fn ( ( ) => 'cors-middleware' ) ,
21+ validateSecurityConfig : jest . fn ( )
22+ } ) ) ;
2023
2124jest . mock ( '@modelcontextprotocol/sdk/server/sse.js' , ( ) => ( {
2225 SSEServerTransport : jest . fn ( )
@@ -27,7 +30,8 @@ describe('HttpSseTransport', () => {
2730 let mockExpress : jest . MockedFunction < any > ;
2831 let mockApp : any ;
2932 let mockServer : any ;
30- let mockCors : jest . MockedFunction < any > ;
33+ let mockCreateCorsMiddleware : jest . MockedFunction < any > ;
34+ let mockValidateSecurityConfig : jest . MockedFunction < any > ;
3135 let mockSSEServerTransport : jest . MockedFunction < any > ;
3236 let mockTransport : any ;
3337 let mockMcpServer : any ;
@@ -38,11 +42,12 @@ describe('HttpSseTransport', () => {
3842
3943 // Import mocked modules
4044 const expressModule = await import ( 'express' ) ;
41- const corsModule = await import ( 'cors ' ) ;
45+ const securityModule = await import ( '../../../server/transport/security.js ' ) ;
4246 const { SSEServerTransport } = await import ( '@modelcontextprotocol/sdk/server/sse.js' ) ;
4347
4448 mockExpress = expressModule . default as jest . MockedFunction < any > ;
45- mockCors = corsModule . default as jest . MockedFunction < any > ;
49+ mockCreateCorsMiddleware = securityModule . createCorsMiddleware as jest . MockedFunction < any > ;
50+ mockValidateSecurityConfig = securityModule . validateSecurityConfig as jest . MockedFunction < any > ;
4651 mockSSEServerTransport = SSEServerTransport as jest . MockedFunction < any > ;
4752
4853 // Setup mock objects
@@ -70,7 +75,7 @@ describe('HttpSseTransport', () => {
7075 // Configure mocks
7176 mockExpress . mockReturnValue ( mockApp ) ;
7277 mockExpress . json = jest . fn ( ) . mockReturnValue ( 'json-middleware' ) ;
73- mockCors . mockReturnValue ( 'cors-middleware' ) ;
78+ mockCreateCorsMiddleware . mockReturnValue ( 'cors-middleware' ) ;
7479 mockSSEServerTransport . mockImplementation ( ( ) => mockTransport ) ;
7580
7681 // Import the class after mocks are set up
@@ -96,14 +101,8 @@ describe('HttpSseTransport', () => {
96101
97102 expect ( mockExpress ) . toHaveBeenCalled ( ) ;
98103 expect ( mockApp . use ) . toHaveBeenCalledWith ( 'json-middleware' ) ;
99- expect ( mockCors ) . toHaveBeenCalledWith ( {
100- origin : '*' ,
101- methods : [ 'GET' , 'POST' , 'OPTIONS' ] ,
102- allowedHeaders : [ 'Content-Type' , 'Authorization' ] ,
103- credentials : true ,
104- exposedHeaders : [ 'Content-Type' , 'Access-Control-Allow-Origin' ]
105- } ) ;
106- expect ( mockApp . options ) . toHaveBeenCalledWith ( '*' , 'cors-middleware' ) ;
104+ expect ( mockCreateCorsMiddleware ) . toHaveBeenCalled ( ) ;
105+ expect ( mockApp . use ) . toHaveBeenCalledWith ( 'cors-middleware' ) ;
107106 expect ( mockApp . get ) . toHaveBeenCalledWith ( '/health' , expect . any ( Function ) ) ;
108107 expect ( mockApp . get ) . toHaveBeenCalledWith ( '/sse' , expect . any ( Function ) ) ;
109108 expect ( mockApp . post ) . toHaveBeenCalledWith ( '/sse/message' , expect . any ( Function ) ) ;
0 commit comments