@@ -6,11 +6,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
66const {
77 mockAuthorizeCredentialUseForAuth,
88 mockCaptureServerEvent,
9- mockCredentialProviderMatchesService,
109 mockExecuteManagedToken,
1110 mockGetCredential,
12- mockGetServiceConfigByProviderId,
13- mockGetServiceConfigByServiceId,
1411 mockGetToolMetadata,
1512 mockRecordAudit,
1613 mockRefreshTokenIfNeeded,
@@ -19,11 +16,8 @@ const {
1916} = vi . hoisted ( ( ) => ( {
2017 mockAuthorizeCredentialUseForAuth : vi . fn ( ) ,
2118 mockCaptureServerEvent : vi . fn ( ) ,
22- mockCredentialProviderMatchesService : vi . fn ( ) ,
2319 mockExecuteManagedToken : vi . fn ( ) ,
2420 mockGetCredential : vi . fn ( ) ,
25- mockGetServiceConfigByProviderId : vi . fn ( ) ,
26- mockGetServiceConfigByServiceId : vi . fn ( ) ,
2721 mockGetToolMetadata : vi . fn ( ) ,
2822 mockRecordAudit : vi . fn ( ) ,
2923 mockRefreshTokenIfNeeded : vi . fn ( ) ,
@@ -84,10 +78,7 @@ vi.mock('@/tools/metadata', () => ({
8478} ) )
8579
8680vi . mock ( '@/lib/oauth/utils' , ( ) => ( {
87- credentialProviderMatchesService : mockCredentialProviderMatchesService ,
8881 getCanonicalScopesForProvider : vi . fn ( ) . mockReturnValue ( [ ] ) ,
89- getServiceConfigByProviderId : mockGetServiceConfigByProviderId ,
90- getServiceConfigByServiceId : mockGetServiceConfigByServiceId ,
9182} ) )
9283
9384import { OrchestrationError } from '@/lib/core/orchestration/types'
@@ -355,12 +346,6 @@ describe('resolveCredentialAccessToken', () => {
355346 beforeEach ( ( ) => {
356347 vi . clearAllMocks ( )
357348 mockResolveOAuthAccountId . mockResolvedValue ( null )
358- mockCredentialProviderMatchesService . mockReturnValue ( true )
359- mockGetServiceConfigByServiceId . mockReturnValue ( {
360- providerId : 'google' ,
361- serviceAccountProviderId : 'google-service-account' ,
362- } )
363- mockGetServiceConfigByProviderId . mockReturnValue ( null )
364349 authenticate . mockResolvedValue ( INTERNAL_AUTH )
365350 resolveManagedPrincipal . mockResolvedValue ( EXECUTOR_PRINCIPAL )
366351 mockGetToolMetadata . mockReturnValue ( {
@@ -426,160 +411,6 @@ describe('resolveCredentialAccessToken', () => {
426411 } )
427412 } )
428413
429- it ( 'rejects a service-account credential with no provider before authentication' , async ( ) => {
430- mockResolveOAuthAccountId . mockResolvedValue ( {
431- credentialType : 'service_account' ,
432- credentialId : 'service-account-1' ,
433- workspaceId : 'ws-1' ,
434- accountId : '' ,
435- usedCredentialTable : true ,
436- } )
437- mockGetToolMetadata . mockReturnValue ( {
438- oauth : {
439- required : true ,
440- provider : 'google' ,
441- credentialKind : 'service-account' ,
442- } ,
443- } )
444-
445- await expect (
446- resolveCredentialAccessToken ( {
447- requestId : 'req-1' ,
448- credentialId : 'service-account-1' ,
449- toolId : 'google_service_account_tool' ,
450- authenticate,
451- } )
452- ) . resolves . toEqual ( {
453- ok : false ,
454- status : 403 ,
455- code : 'CREDENTIAL_PROVIDER_MISMATCH' ,
456- error : 'Credential belongs to another service' ,
457- } )
458- expect ( authenticate ) . not . toHaveBeenCalled ( )
459- expect ( mockResolveServiceAccountToken ) . not . toHaveBeenCalled ( )
460- } )
461-
462- it ( 'rejects a service-account credential from another provider before authentication' , async ( ) => {
463- mockResolveOAuthAccountId . mockResolvedValue ( {
464- credentialType : 'service_account' ,
465- credentialId : 'service-account-1' ,
466- providerId : 'atlassian-service-account' ,
467- workspaceId : 'ws-1' ,
468- accountId : '' ,
469- usedCredentialTable : true ,
470- } )
471- mockGetToolMetadata . mockReturnValue ( {
472- oauth : {
473- required : true ,
474- provider : 'google' ,
475- credentialKind : 'service-account' ,
476- } ,
477- } )
478- mockCredentialProviderMatchesService . mockReturnValue ( false )
479-
480- await expect (
481- resolveCredentialAccessToken ( {
482- requestId : 'req-1' ,
483- credentialId : 'service-account-1' ,
484- toolId : 'google_service_account_tool' ,
485- authenticate,
486- } )
487- ) . resolves . toEqual ( {
488- ok : false ,
489- status : 403 ,
490- code : 'CREDENTIAL_PROVIDER_MISMATCH' ,
491- error : 'Credential belongs to another service' ,
492- } )
493- expect ( authenticate ) . not . toHaveBeenCalled ( )
494- expect ( mockResolveServiceAccountToken ) . not . toHaveBeenCalled ( )
495- } )
496-
497- it ( 'accepts a non-Oracle service account whose provider matches the tool service' , async ( ) => {
498- mockResolveOAuthAccountId . mockResolvedValue ( {
499- credentialType : 'service_account' ,
500- credentialId : 'service-account-1' ,
501- providerId : 'google-service-account' ,
502- workspaceId : 'ws-1' ,
503- accountId : '' ,
504- usedCredentialTable : true ,
505- } )
506- mockGetToolMetadata . mockReturnValue ( {
507- oauth : {
508- required : true ,
509- provider : 'google-email' ,
510- requiredScopes : [ 'scope-a' ] ,
511- credentialKind : 'service-account' ,
512- } ,
513- } )
514- mockGetServiceConfigByServiceId . mockReturnValue ( null )
515- mockGetServiceConfigByProviderId . mockReturnValue ( {
516- providerId : 'google-email' ,
517- serviceAccountProviderId : 'google-service-account' ,
518- } )
519- mockAuthorizeCredentialUseForAuth . mockResolvedValue ( {
520- ok : true ,
521- requesterUserId : 'user-1' ,
522- workspaceId : 'ws-1' ,
523- } )
524- mockResolveServiceAccountToken . mockResolvedValue ( { accessToken : 'service-account-token' } )
525-
526- await expect (
527- resolveCredentialAccessToken ( {
528- requestId : 'req-1' ,
529- credentialId : 'service-account-1' ,
530- toolId : 'gmail_read' ,
531- scopes : [ 'scope-a' ] ,
532- authenticate,
533- } )
534- ) . resolves . toMatchObject ( {
535- ok : true ,
536- token : { accessToken : 'service-account-token' , credentialType : 'service_account' } ,
537- } )
538- expect ( mockGetServiceConfigByProviderId ) . toHaveBeenCalledWith ( 'google-email' )
539- expect ( mockResolveServiceAccountToken ) . toHaveBeenCalledWith (
540- 'service-account-1' ,
541- 'google-service-account' ,
542- [ 'scope-a' ] ,
543- undefined
544- )
545- } )
546-
547- it . each ( [
548- [ 'an OAuth credential for a service-account-only tool' , undefined , 'service-account' ] ,
549- [ 'a service account for an OAuth-only tool' , 'service_account' , 'oauth' ] ,
550- ] ) ( 'rejects %s before authentication' , async ( _label , credentialType , requiredKind ) => {
551- mockResolveOAuthAccountId . mockResolvedValue ( {
552- ...( credentialType ? { credentialType } : { } ) ,
553- credentialId : 'credential-1' ,
554- providerId : credentialType ? 'google-service-account' : undefined ,
555- workspaceId : 'ws-1' ,
556- accountId : credentialType ? '' : 'account-1' ,
557- usedCredentialTable : true ,
558- } )
559- mockGetToolMetadata . mockReturnValue ( {
560- oauth : {
561- required : true ,
562- provider : 'google' ,
563- credentialKind : requiredKind ,
564- } ,
565- } )
566-
567- const result = await resolveCredentialAccessToken ( {
568- requestId : 'req-1' ,
569- credentialId : 'credential-1' ,
570- toolId : 'kind_restricted_tool' ,
571- authenticate,
572- } )
573-
574- expect ( result ) . toEqual ( {
575- ok : false ,
576- status : 403 ,
577- code : 'CREDENTIAL_PROVIDER_MISMATCH' ,
578- error : 'Credential belongs to another service' ,
579- } )
580- expect ( authenticate ) . not . toHaveBeenCalled ( )
581- } )
582-
583414 it ( 'rejects a managed credential when no delegation resolver is wired' , async ( ) => {
584415 mockResolveOAuthAccountId . mockResolvedValue ( MANAGED_RESOLVED )
585416
0 commit comments