@@ -12,7 +12,7 @@ describe('OAuth Token API Routes', () => {
1212 const mockRefreshTokenIfNeeded = vi . fn ( )
1313 const mockGetOAuthToken = vi . fn ( )
1414 const mockAuthorizeCredentialUse = vi . fn ( )
15- const mockCheckHybridAuth = vi . fn ( )
15+ const mockCheckSessionOrInternalAuth = vi . fn ( )
1616
1717 const mockLogger = createMockLogger ( )
1818
@@ -42,7 +42,7 @@ describe('OAuth Token API Routes', () => {
4242 } ) )
4343
4444 vi . doMock ( '@/lib/auth/hybrid' , ( ) => ( {
45- checkHybridAuth : mockCheckHybridAuth ,
45+ checkSessionOrInternalAuth : mockCheckSessionOrInternalAuth ,
4646 } ) )
4747 } )
4848
@@ -235,7 +235,7 @@ describe('OAuth Token API Routes', () => {
235235
236236 describe ( 'credentialAccountUserId + providerId path' , ( ) => {
237237 it ( 'should reject unauthenticated requests' , async ( ) => {
238- mockCheckHybridAuth . mockResolvedValueOnce ( {
238+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
239239 success : false ,
240240 error : 'Authentication required' ,
241241 } )
@@ -255,30 +255,8 @@ describe('OAuth Token API Routes', () => {
255255 expect ( mockGetOAuthToken ) . not . toHaveBeenCalled ( )
256256 } )
257257
258- it ( 'should reject API key authentication' , async ( ) => {
259- mockCheckHybridAuth . mockResolvedValueOnce ( {
260- success : true ,
261- authType : 'api_key' ,
262- userId : 'test-user-id' ,
263- } )
264-
265- const req = createMockRequest ( 'POST' , {
266- credentialAccountUserId : 'test-user-id' ,
267- providerId : 'google' ,
268- } )
269-
270- const { POST } = await import ( '@/app/api/auth/oauth/token/route' )
271-
272- const response = await POST ( req )
273- const data = await response . json ( )
274-
275- expect ( response . status ) . toBe ( 401 )
276- expect ( data ) . toHaveProperty ( 'error' , 'User not authenticated' )
277- expect ( mockGetOAuthToken ) . not . toHaveBeenCalled ( )
278- } )
279-
280258 it ( 'should reject internal JWT authentication' , async ( ) => {
281- mockCheckHybridAuth . mockResolvedValueOnce ( {
259+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
282260 success : true ,
283261 authType : 'internal_jwt' ,
284262 userId : 'test-user-id' ,
@@ -300,7 +278,7 @@ describe('OAuth Token API Routes', () => {
300278 } )
301279
302280 it ( 'should reject requests for other users credentials' , async ( ) => {
303- mockCheckHybridAuth . mockResolvedValueOnce ( {
281+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
304282 success : true ,
305283 authType : 'session' ,
306284 userId : 'attacker-user-id' ,
@@ -322,7 +300,7 @@ describe('OAuth Token API Routes', () => {
322300 } )
323301
324302 it ( 'should allow session-authenticated users to access their own credentials' , async ( ) => {
325- mockCheckHybridAuth . mockResolvedValueOnce ( {
303+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
326304 success : true ,
327305 authType : 'session' ,
328306 userId : 'test-user-id' ,
@@ -345,7 +323,7 @@ describe('OAuth Token API Routes', () => {
345323 } )
346324
347325 it ( 'should return 404 when credential not found for user' , async ( ) => {
348- mockCheckHybridAuth . mockResolvedValueOnce ( {
326+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
349327 success : true ,
350328 authType : 'session' ,
351329 userId : 'test-user-id' ,
@@ -373,7 +351,7 @@ describe('OAuth Token API Routes', () => {
373351 */
374352 describe ( 'GET handler' , ( ) => {
375353 it ( 'should return access token successfully' , async ( ) => {
376- mockCheckHybridAuth . mockResolvedValueOnce ( {
354+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
377355 success : true ,
378356 authType : 'session' ,
379357 userId : 'test-user-id' ,
@@ -402,7 +380,7 @@ describe('OAuth Token API Routes', () => {
402380 expect ( response . status ) . toBe ( 200 )
403381 expect ( data ) . toHaveProperty ( 'accessToken' , 'fresh-token' )
404382
405- expect ( mockCheckHybridAuth ) . toHaveBeenCalled ( )
383+ expect ( mockCheckSessionOrInternalAuth ) . toHaveBeenCalled ( )
406384 expect ( mockGetCredential ) . toHaveBeenCalledWith ( mockRequestId , 'credential-id' , 'test-user-id' )
407385 expect ( mockRefreshTokenIfNeeded ) . toHaveBeenCalled ( )
408386 } )
@@ -421,7 +399,7 @@ describe('OAuth Token API Routes', () => {
421399 } )
422400
423401 it ( 'should handle authentication failure' , async ( ) => {
424- mockCheckHybridAuth . mockResolvedValueOnce ( {
402+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
425403 success : false ,
426404 error : 'Authentication required' ,
427405 } )
@@ -440,7 +418,7 @@ describe('OAuth Token API Routes', () => {
440418 } )
441419
442420 it ( 'should handle credential not found' , async ( ) => {
443- mockCheckHybridAuth . mockResolvedValueOnce ( {
421+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
444422 success : true ,
445423 authType : 'session' ,
446424 userId : 'test-user-id' ,
@@ -461,7 +439,7 @@ describe('OAuth Token API Routes', () => {
461439 } )
462440
463441 it ( 'should handle missing access token' , async ( ) => {
464- mockCheckHybridAuth . mockResolvedValueOnce ( {
442+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
465443 success : true ,
466444 authType : 'session' ,
467445 userId : 'test-user-id' ,
@@ -487,7 +465,7 @@ describe('OAuth Token API Routes', () => {
487465 } )
488466
489467 it ( 'should handle token refresh failure' , async ( ) => {
490- mockCheckHybridAuth . mockResolvedValueOnce ( {
468+ mockCheckSessionOrInternalAuth . mockResolvedValueOnce ( {
491469 success : true ,
492470 authType : 'session' ,
493471 userId : 'test-user-id' ,
0 commit comments