@@ -47,10 +47,15 @@ const savedEnv: Record<string, string | undefined> = {};
4747 * adapter dialect: `findMany` / `findOne` over the provider's camelCase field
4848 * names with `eq` clauses, the only shape the consent read sends. `reads`
4949 * counts every call, so a leg can pin how many reads one verification costs.
50+ *
51+ * [objectstack-ai/cloud#3820, card 2] The grant read starts at the client row:
52+ * a disabled client, or one whose row is gone, admits nothing. So the default
53+ * store holds the one client every token below names, enabled, and a leg that
54+ * is about the client passes its own rows.
5055 */
5156function consentStore (
5257 consents : Array < { clientId : string ; userId : string ; referenceId ?: string | null ; createdAt : Date } > ,
53- clients : Array < { clientId : string ; skipConsent ?: boolean } > = [ ] ,
58+ clients : Array < { clientId : string ; skipConsent ?: boolean ; disabled ?: boolean } > = [ { clientId : 'client-abc' } ] ,
5459) {
5560 const tables : Record < string , Array < Record < string , unknown > > > = { oauthConsent : consents , oauthClient : clients } ;
5661 const reads : string [ ] = [ ] ;
@@ -573,14 +578,28 @@ describe('verifyMcpAccessToken reads the consent the token was minted under (rul
573578 . sign ( privateKey ) ;
574579 }
575580
576- it ( 'admits a token whose consent stands — at the cost of exactly ONE read ' , async ( ) => {
581+ it ( 'admits a token whose consent stands — at the cost of exactly TWO reads, the client and then the consent ' , async ( ) => {
577582 const store = consentStore ( [ { clientId : 'client-abc' , userId : 'user-1' , referenceId : null , createdAt : HOUR_AGO } ] ) ;
578583 expect ( await managerOver ( store ) . verifyMcpAccessToken ( await signToken ( ) ) ) . toEqual ( {
579584 userId : 'user-1' ,
580585 scopes : [ 'data:read' ] ,
581586 clientId : 'client-abc' ,
582587 } ) ;
583- expect ( store . reads ) . toEqual ( [ 'findMany oauthConsent' ] ) ;
588+ // [objectstack-ai/cloud#3820, card 2] The client row is read first, so a
589+ // disabled client's token is refused before its consent is looked at.
590+ expect ( store . reads ) . toEqual ( [ 'findOne oauthClient' , 'findMany oauthConsent' ] ) ;
591+ } ) ;
592+
593+ it ( '[objectstack-ai/cloud#3820, card 2] refuses the token of a disabled client, or of a client whose row is gone, though its consent stands' , async ( ) => {
594+ const consent = [ { clientId : 'client-abc' , userId : 'user-1' , referenceId : null , createdAt : HOUR_AGO } ] ;
595+ const disabled = consentStore ( consent , [ { clientId : 'client-abc' , disabled : true } ] ) ;
596+ expect ( await managerOver ( disabled ) . verifyMcpAccessToken ( await signToken ( ) ) ) . toBeNull ( ) ;
597+ // Refused on the client row alone: the consent is never read.
598+ expect ( disabled . reads ) . toEqual ( [ 'findOne oauthClient' ] ) ;
599+ expect ( await managerOver ( consentStore ( consent , [ ] ) ) . verifyMcpAccessToken ( await signToken ( ) ) ) . toBeNull ( ) ;
600+ // The control: the same consent under the same client, enabled, admits.
601+ const enabled = consentStore ( consent , [ { clientId : 'client-abc' , disabled : false } ] ) ;
602+ expect ( await managerOver ( enabled ) . verifyMcpAccessToken ( await signToken ( ) ) ) . not . toBeNull ( ) ;
584603 } ) ;
585604
586605 it ( 'refuses a token whose consent is gone (revoked, or withdrawn in the Console)' , async ( ) => {
@@ -630,7 +649,8 @@ describe('verifyMcpAccessToken reads the consent the token was minted under (rul
630649 it ( 'a server-only `skip_consent` client has no consent row and is admitted without one (ruling A, step 5)' , async ( ) => {
631650 const skip = consentStore ( [ ] , [ { clientId : 'client-abc' , skipConsent : true } ] ) ;
632651 expect ( await managerOver ( skip ) . verifyMcpAccessToken ( await signToken ( ) ) ) . not . toBeNull ( ) ;
633- expect ( skip . reads ) . toEqual ( [ 'findMany oauthConsent' , 'findOne oauthClient' ] ) ;
652+ // One client read answers both questions: enabled, and consent-less.
653+ expect ( skip . reads ) . toEqual ( [ 'findOne oauthClient' , 'findMany oauthConsent' ] ) ;
634654 // The control: the same client without the flag is refused.
635655 const consenting = consentStore ( [ ] , [ { clientId : 'client-abc' , skipConsent : false } ] ) ;
636656 expect ( await managerOver ( consenting ) . verifyMcpAccessToken ( await signToken ( ) ) ) . toBeNull ( ) ;
0 commit comments