@@ -29,7 +29,7 @@ import { ADMIN_FULL_ACCESS } from '@objectstack/spec/identity';
2929import { AuthManager } from './auth-manager.js' ;
3030import { authIdentityObjects } from './manifest.js' ;
3131import { createTenancyService } from './tenancy-service.js' ;
32- import { mintScimConnectionCredential } from './scim-connection-service.js' ;
32+ import { mintScimConnectionCredential , revokeScimConnectionCredential } from './scim-connection-service.js' ;
3333import { runDeleteIdpGroupMapping , runSetIdpGroupMapping , type IdpGroupMappingAdminDeps } from './idp-group-mapping-admin.js' ;
3434import { createScimGroupProjection , scimGroupProjectionReason , type OrganizationBoundaryJudge } from './scim-group-projection.js' ;
3535import { bindTestSecurityCatalog } from './__tests__/security-catalog.testkit.js' ;
@@ -126,6 +126,7 @@ interface Harness {
126126 door : IdpGroupMappingAdminDeps ;
127127 send : ( method : string , path : string , body ?: unknown ) => Promise < Response > ;
128128 judge : OrganizationBoundaryJudge ;
129+ credentialId : string ;
129130}
130131
131132async function boot ( ) : Promise < Harness > {
@@ -139,7 +140,7 @@ async function boot(): Promise<Harness> {
139140 plugins : { scim : true , organization : true } ,
140141 organizationBoundary : async ( ) => judge ,
141142 } as never ) ;
142- const { token } = await mintScimConnectionCredential ( engine as never , SECRET , { connectionId : CONNECTION , organizationId : ORG } ) ;
143+ const { token, credentialId } = await mintScimConnectionCredential ( engine as never , SECRET , { connectionId : CONNECTION , organizationId : ORG } ) ;
143144 const door : IdpGroupMappingAdminDeps = {
144145 getDataEngine : ( ) => manager . getDataEngine ( ) as never ,
145146 isScimEnabled : ( ) => manager . isScimWired ( ) ,
@@ -159,7 +160,7 @@ async function boot(): Promise<Harness> {
159160 ...( body !== undefined ? { body : JSON . stringify ( body ) } : { } ) ,
160161 } ) ,
161162 ) ;
162- return { engine, manager, token, door, send, judge } ;
163+ return { engine, manager, token, credentialId , door, send, judge } ;
163164}
164165
165166const ADMIN = { id : 'usr_platform_admin' } ;
@@ -432,4 +433,28 @@ describe('SCIM group push → mapped permission set', () => {
432433 await pushGroup ( h , { displayName : 'Sales' , externalId : 'okta-grp-sales' } , [ gina . scimId ] ) ;
433434 expect ( await grantsOf ( h , gina . userId ) ) . toEqual ( [ ] ) ;
434435 } ) ;
436+ it ( '(S4) a revoked credential does not count: revoke in one organization, mint in another, and the save lands in the new one' , async ( ) => {
437+ const h = await boot ( ) ;
438+ const ORG_B = 'org_scim_30959_b' ;
439+ expect ( ( await revokeScimConnectionCredential ( h . engine as never , h . credentialId ) ) . outcome ) . toBe ( 'revoked' ) ;
440+ await mintScimConnectionCredential ( h . engine as never , SECRET , { connectionId : CONNECTION , organizationId : ORG_B } ) ;
441+
442+ const saved = await saveMapping ( h , { connectionId : CONNECTION , groupExternalId : 'okta-grp-sales' , permissionSet : SALES } ) ;
443+
444+ expect ( saved . status , JSON . stringify ( saved . body ) ) . toBe ( 200 ) ;
445+ expect ( ( saved . body as { data : { organizationId : string } } ) . data . organizationId ) . toBe ( ORG_B ) ;
446+ const rows = ( await h . engine . find ( 'sys_idp_group_mapping' , { } , SYSTEM ) ) as Array < Record < string , unknown > > ;
447+ expect ( rows . map ( ( r ) => r . organization_id ) ) . toEqual ( [ ORG_B ] ) ;
448+ } ) ;
449+
450+ it ( '(S4) a connection whose every credential is revoked is refused at save' , async ( ) => {
451+ const h = await boot ( ) ;
452+ await revokeScimConnectionCredential ( h . engine as never , h . credentialId ) ;
453+ const refused = await saveMapping ( h , { connectionId : CONNECTION , groupExternalId : 'okta-grp-sales' , permissionSet : SALES } ) ;
454+ expect ( refused . status ) . toBe ( 400 ) ;
455+ const error = ( refused . body as { error : { code : string ; fields : Array < { field : string ; code : string } > } } ) . error ;
456+ expect ( error . code ) . toBe ( 'VALIDATION_FAILED' ) ;
457+ expect ( error . fields . map ( ( f ) => [ f . field , f . code ] ) ) . toEqual ( [ [ 'connectionId' , 'rule_violation' ] ] ) ;
458+ expect ( await h . engine . find ( 'sys_idp_group_mapping' , { } , SYSTEM ) ) . toEqual ( [ ] ) ;
459+ } ) ;
435460} ) ;
0 commit comments