11import { createMockRequest } from '@sim/testing'
2+ import { createRouteContext } from '@sim/testing/helpers/http'
23import { authMockFns } from '@sim/testing/mocks/auth.mock'
34import { oauthUtilsMock , oauthUtilsMockFns } from '@sim/testing/mocks/oauth-utils.mock'
45import { urlsMockFns } from '@sim/testing/mocks/urls.mock'
@@ -45,7 +46,7 @@ describe('Instagram authorize route', () => {
4546 'https://sim.test/api/auth/instagram/authorize?workspaceId=workspace-1&draftId=draft-exact'
4647 )
4748
48- const response = await GET ( request )
49+ const response = await GET ( request , createRouteContext ( { } ) )
4950
5051 expect ( response . status ) . toBe ( 307 )
5152 expect ( response . headers . get ( 'set-cookie' ) ) . toContain (
@@ -54,6 +55,20 @@ describe('Instagram authorize route', () => {
5455 expect ( mocks . createCredentialConnection ) . not . toHaveBeenCalled ( )
5556 } )
5657
58+ it ( 'refuses a cross-site workspace launch before creating a connection draft' , async ( ) => {
59+ const request = createMockRequest (
60+ 'GET' ,
61+ undefined ,
62+ { 'sec-fetch-site' : 'cross-site' } ,
63+ 'https://sim.test/api/auth/instagram/authorize?workspaceId=workspace-1'
64+ )
65+
66+ const response = await GET ( request , createRouteContext ( { } ) )
67+
68+ expect ( response . status ) . toBe ( 403 )
69+ expect ( mocks . createCredentialConnection ) . not . toHaveBeenCalled ( )
70+ } )
71+
5772 it ( 'returns a conflict when a different connection intent is already active' , async ( ) => {
5873 mocks . createCredentialConnection . mockRejectedValue (
5974 new OrchestrationError (
@@ -68,7 +83,7 @@ describe('Instagram authorize route', () => {
6883 'https://sim.test/api/auth/instagram/authorize?workspaceId=workspace-1'
6984 )
7085
71- const response = await GET ( request )
86+ const response = await GET ( request , createRouteContext ( { } ) )
7287
7388 expect ( response . status ) . toBe ( 409 )
7489 await expect ( response . json ( ) ) . resolves . toEqual ( {
0 commit comments