11import { ForbiddenHttpError , KeyValueStorage } from '@solid/community-server' ;
22import { Mocked , MockInstance } from 'vitest' ;
3+ import { WEBID } from '../../../src/credentials/Claims' ;
34import { ClaimSet } from '../../../src/credentials/ClaimSet' ;
45import { Verifier } from '../../../src/credentials/verify/Verifier' ;
56import { ContractNegotiator } from '../../../src/dialog/ContractNegotiator' ;
@@ -10,13 +11,6 @@ import { Ticket } from '../../../src/ticketing/Ticket';
1011import { SerializedToken , TokenFactory } from '../../../src/tokens/TokenFactory' ;
1112import { ODRLContract } from '../../../src/views/Contract' ;
1213
13- // vi.mock('../../../src/policies/contracts/ContractManager', () => ({
14- // ContractManager: vi.fn().mockReturnValue({
15- // createContract: vi.fn(),
16- // findContract: vi.fn(),
17- // }),
18- // }))
19-
2014describe ( 'ContractNegotiator' , ( ) : void => {
2115 const input : DialogInput = {
2216 permissions : [
@@ -27,7 +21,6 @@ describe('ContractNegotiator', (): void => {
2721 const claims : ClaimSet = { claim1 : 'value1' , claim2 : 'value2' } ;
2822 const ticket : Ticket = {
2923 permissions : [ { resource_id : 'id1' , resource_scopes : [ 'scope1' ] } ] ,
30- required : [ ] ,
3124 provided : { claim : 'value' } ,
3225 } ;
3326 const token : SerializedToken = { token : 'token' , tokenType : 'type' } ;
@@ -142,4 +135,21 @@ describe('ContractNegotiator', (): void => {
142135 await expect ( negotiator . negotiate ( input ) ) . rejects . toThrow ( ForbiddenHttpError ) ;
143136 expect ( ticketStore . set ) . toHaveBeenCalledTimes ( 0 ) ;
144137 } ) ;
138+
139+ it ( 'includes the WEBID claim in generated tokens as sub value.' , async ( ) : Promise < void > => {
140+ const webId = 'https://example.com/profile/card#me' ;
141+ ticketingStrategy . validateClaims . mockResolvedValueOnce ( {
142+ ...ticket ,
143+ provided : { [ WEBID ] : webId } ,
144+ } ) ;
145+
146+ await expect ( negotiator . negotiate ( { ...input , claim_token : 'token' , claim_token_format : 'format' } ) ) . resolves
147+ . toEqual ( { access_token : 'token' , token_type : 'type' } ) ;
148+
149+ expect ( tokenFactory . serialize ) . toHaveBeenLastCalledWith ( {
150+ contract,
151+ permissions : [ { resource_id : 'target' , resource_scopes : [ 'https://w3id.org/oac#action' ] } ] ,
152+ sub : webId ,
153+ } ) ;
154+ } ) ;
145155} ) ;
0 commit comments