@@ -256,4 +256,85 @@ describe('#4940: what an admin identity operation leaves in sys_audit_log', () =
256256 expect ( metadata ) . toMatchObject ( { total : 1 , created : 1 , updated : 0 , skipped : 0 , errors : 0 } ) ;
257257 expect ( metadata . delivery ) . toMatchObject ( { temporary : 1 } ) ;
258258 } , 120_000 ) ;
259+
260+ // ── W5 (#30958): the SCIM credential door, on the composed runtime ──────
261+ //
262+ // The platform admin mints a SCIM connection bearer, an identity provider
263+ // provisions with it, the admin revokes it and the next provisioning call is
264+ // refused. Then the secret is looked for everywhere this stack keeps or
265+ // serves: the bearer must appear ONLY in the mint's own answer, and its
266+ // keyed digest only in its own column at rest — never in a `sys_audit_log`
267+ // row (the door's explicit rows AND plugin-audit's generic ones for the
268+ // credential writes), never in `sys_activity`, never in the data API's list
269+ // or export of the credential object.
270+
271+ it ( 'POST /admin/scim/mint-credential + revoke-credential: the bearer provisions, is refused once revoked, and is shown nowhere else' , async ( ) => {
272+ const minted = await stack . apiAs ( adminToken , 'POST' , '/auth/admin/scim/mint-credential' , {
273+ connectionId : 'okta-dogfood-30958' ,
274+ } ) ;
275+ expect ( minted . status , await minted . clone ( ) . text ( ) ) . toBe ( 200 ) ;
276+ expect ( minted . headers . get ( 'cache-control' ) ) . toBe ( 'no-store' ) ;
277+ const { token, credentialId } = ( await minted . json ( ) ) . data as { token : string ; credentialId : string } ;
278+
279+ const provision = ( localPart : string ) =>
280+ stack . api ( '/auth/scim/v2/Users' , {
281+ method : 'POST' ,
282+ headers : { authorization : `Bearer ${ token } ` , 'content-type' : 'application/scim+json' } ,
283+ body : JSON . stringify ( {
284+ schemas : [ 'urn:ietf:params:scim:schemas:core:2.0:User' ] ,
285+ userName : `${ localPart } @example.com` ,
286+ name : { givenName : localPart , familyName : 'Dogfood' } ,
287+ emails : [ { value : `${ localPart } @example.com` , primary : true , type : 'work' } ] ,
288+ active : true ,
289+ } ) ,
290+ } ) ;
291+ const created = await provision ( 'scim-provisioned-30958' ) ;
292+ expect ( created . status , await created . clone ( ) . text ( ) ) . toBe ( 201 ) ;
293+
294+ const revoked = await stack . apiAs ( adminToken , 'POST' , '/auth/admin/scim/revoke-credential' , { credentialId } ) ;
295+ expect ( revoked . status , await revoked . clone ( ) . text ( ) ) . toBe ( 200 ) ;
296+ const refused = await provision ( 'scim-after-revoke-30958' ) ;
297+ expect ( refused . status , await refused . clone ( ) . text ( ) ) . toBe ( 401 ) ;
298+
299+ // The digest as stored, read below the engine (the engine never serves it).
300+ const driver = ql . getDriver ?.( 'sys_scim_connection_credential' ) ;
301+ expect ( driver , 'no driver read for the credential object' ) . toBeTruthy ( ) ;
302+ const atRest = ( await driver . find ( 'sys_scim_connection_credential' , { where : { id : credentialId } } ) ) as any [ ] ;
303+ const digest = String ( atRest [ 0 ] ?. token_digest ?? '' ) ;
304+ expect ( digest . length , 'the credential row holds no digest at rest' ) . toBeGreaterThan ( 20 ) ;
305+ expect ( JSON . stringify ( atRest [ 0 ] ) ) . not . toContain ( token ) ;
306+
307+ // The door's explicit rows: one per mint and per revoke, naming the admin and the connection.
308+ const explicit = await waitForRows (
309+ async ( ) => ( await findRows ( ql , 'sys_audit_log' , { object_name : 'sys_scim_connection_credential' , record_id : credentialId } ) )
310+ . filter ( ( r ) => ! isGeneric ( r ) ) ,
311+ ( rows ) => rows . length === 2 ,
312+ 'the mint and revoke rows' ,
313+ ) ;
314+ expect ( explicit . map ( ( r ) => JSON . parse ( String ( r . metadata ) ) . event ) . sort ( ) )
315+ . toEqual ( [ 'scim_credential_minted' , 'scim_credential_revoked' ] ) ;
316+ for ( const row of explicit ) {
317+ expect ( row . user_id ) . toBe ( adminUserId ) ;
318+ expect ( JSON . parse ( String ( row . metadata ) ) . connectionId ) . toBe ( 'okta-dogfood-30958' ) ;
319+ }
320+
321+ // Nowhere else: every ledger row, the activity feed, and the data API's reads.
322+ const ledgers = JSON . stringify ( [
323+ await findRows ( ql , 'sys_audit_log' , { } , 5000 ) ,
324+ ...( ql . getSchema ?.( 'sys_activity' ) ? [ await findRows ( ql , 'sys_activity' , { } , 5000 ) ] : [ ] ) ,
325+ ] ) ;
326+ expect ( ledgers ) . not . toContain ( token ) ;
327+ expect ( ledgers ) . not . toContain ( digest ) ;
328+ const list = await stack . apiAs ( adminToken , 'GET' , '/data/sys_scim_connection_credential' ) ;
329+ const listed = await list . text ( ) ;
330+ expect ( list . status , listed ) . toBe ( 200 ) ;
331+ expect ( listed ) . toContain ( credentialId ) ;
332+ const exported = await stack . apiAs ( adminToken , 'GET' , '/data/sys_scim_connection_credential/export' ) ;
333+ const exportedText = await exported . text ( ) ;
334+ expect ( exported . status , exportedText . slice ( 0 , 300 ) ) . toBe ( 200 ) ;
335+ for ( const served of [ listed , exportedText ] ) {
336+ expect ( served ) . not . toContain ( token ) ;
337+ expect ( served ) . not . toContain ( digest ) ;
338+ }
339+ } , 120_000 ) ;
259340} ) ;
0 commit comments