@@ -24,6 +24,17 @@ vi.mock('@/lib/core/config/feature-flags', () => ({
2424 isProd : false ,
2525} ) )
2626
27+ vi . mock ( '@/lib/core/config/env' , ( ) => ( {
28+ getEnv : vi . fn ( ( key : string ) => {
29+ if ( key === 'NEXT_PUBLIC_APP_URL' ) return 'http://localhost:3000'
30+ return undefined
31+ } ) ,
32+ } ) )
33+
34+ vi . mock ( '@/lib/core/utils/urls' , ( ) => ( {
35+ getBaseUrl : vi . fn ( ( ) => 'http://localhost:3000' ) ,
36+ } ) )
37+
2738vi . mock ( '@/lib/workflows/utils' , ( ) => ( {
2839 authorizeWorkflowByWorkspacePermission : vi . fn ( ) ,
2940} ) )
@@ -114,7 +125,7 @@ describe('Form API Utils', () => {
114125 } )
115126
116127 describe ( 'CORS handling' , ( ) => {
117- it . concurrent ( 'should add CORS headers for any origin ' , ( ) => {
128+ it ( 'should add CORS headers for allowed origins ' , ( ) => {
118129 const mockRequest = {
119130 headers : {
120131 get : vi . fn ( ) . mockReturnValue ( 'http://localhost:3000' ) ,
@@ -147,7 +158,25 @@ describe('Form API Utils', () => {
147158 )
148159 } )
149160
150- it . concurrent ( 'should not set CORS headers when no origin' , ( ) => {
161+ it ( 'should not set CORS headers for disallowed origins' , ( ) => {
162+ const mockRequest = {
163+ headers : {
164+ get : vi . fn ( ) . mockReturnValue ( 'https://evil.com' ) ,
165+ } ,
166+ } as any
167+
168+ const mockResponse = {
169+ headers : {
170+ set : vi . fn ( ) ,
171+ } ,
172+ } as unknown as NextResponse
173+
174+ addCorsHeaders ( mockResponse , mockRequest )
175+
176+ expect ( mockResponse . headers . set ) . not . toHaveBeenCalled ( )
177+ } )
178+
179+ it ( 'should not set CORS headers when no origin' , ( ) => {
151180 const mockRequest = {
152181 headers : {
153182 get : vi . fn ( ) . mockReturnValue ( '' ) ,
0 commit comments