@@ -18,7 +18,8 @@ interface UmaConfig {
1818describe ( 'A server with partial results enabled' , ( ) : void => {
1919 const owner = 'http://example.com/alice#me' ;
2020 const user = `http://example.com/bob` ;
21- const resource = `http://localhost:${ rsPort } /alice/data` ;
21+ const aliceResource = `http://localhost:${ rsPort } /alice/data` ;
22+ const bobResource = `http://localhost:${ rsPort } /bob/data` ;
2223 const readScope = 'http://www.w3.org/ns/odrl/2/read' ;
2324 const writeScope = 'http://www.w3.org/ns/odrl/2/write' ;
2425 let umaApp : App ;
@@ -75,18 +76,31 @@ describe('A server with partial results enabled', (): void => {
7576 const patJson = await patResponse . json ( ) as { access_token : string , token_type : string } ;
7677 pat = `${ patJson . token_type } ${ patJson . access_token } ` ;
7778
78- const registrationBody = {
79- name : resource ,
80- resource_scopes : [ readScope , writeScope ] ,
81- } ;
82- const resourceRegistrationResponse = await fetch ( umaConfig . resource_registration_endpoint , {
79+ let resourceRegistrationResponse = await fetch ( umaConfig . resource_registration_endpoint , {
8380 method : 'POST' ,
8481 headers : {
8582 Authorization : pat ,
8683 'Content-Type' : 'application/json' ,
8784 Accept : 'application/json' ,
8885 } ,
89- body : JSON . stringify ( registrationBody ) ,
86+ body : JSON . stringify ( {
87+ name : aliceResource ,
88+ resource_scopes : [ readScope , writeScope ] ,
89+ } ) ,
90+ } ) ;
91+ expect ( resourceRegistrationResponse . status ) . toBe ( 201 ) ;
92+
93+ resourceRegistrationResponse = await fetch ( umaConfig . resource_registration_endpoint , {
94+ method : 'POST' ,
95+ headers : {
96+ Authorization : pat ,
97+ 'Content-Type' : 'application/json' ,
98+ Accept : 'application/json' ,
99+ } ,
100+ body : JSON . stringify ( {
101+ name : bobResource ,
102+ resource_scopes : [ readScope , writeScope ] ,
103+ } ) ,
90104 } ) ;
91105 expect ( resourceRegistrationResponse . status ) . toBe ( 201 ) ;
92106
@@ -99,7 +113,7 @@ describe('A server with partial results enabled', (): void => {
99113 }
100114
101115 const auth = request . headers . authorization ;
102- if ( hasScope ( auth , resource , readScope ) ) {
116+ if ( hasScope ( auth , aliceResource , readScope ) ) {
103117 response . statusCode = 200 ;
104118 response . end ( 'protected data' ) ;
105119 return ;
@@ -114,7 +128,7 @@ describe('A server with partial results enabled', (): void => {
114128 } ,
115129 body : JSON . stringify ( [
116130 {
117- resource_id : resource ,
131+ resource_id : aliceResource ,
118132 resource_scopes : [ readScope ] ,
119133 }
120134 ] ) ,
@@ -174,13 +188,13 @@ describe('A server with partial results enabled', (): void => {
174188 odrl:assigner <${ owner } > ;
175189 odrl:action odrl:create, odrl:modify ;
176190 odrl:target <http://localhost:${ rsPort } /alice/> ,
177- <${ resource } > .
191+ <${ aliceResource } > .
178192
179193 ex:userPermission a odrl:Permission ;
180194 odrl:assignee <${ user } > ;
181195 odrl:assigner <${ owner } > ;
182196 odrl:action odrl:read ;
183- odrl:target <${ resource } > .` ;
197+ odrl:target <${ aliceResource } > .` ;
184198
185199 const url = `http://localhost:${ umaPort } /uma/policies` ;
186200 let response = await fetch ( url , {
@@ -190,11 +204,11 @@ describe('A server with partial results enabled', (): void => {
190204 } ) ;
191205 expect ( response . status ) . toBe ( 201 ) ;
192206
193- response = await umaFetch ( resource , { } , user ) ;
207+ response = await umaFetch ( aliceResource , { } , user ) ;
194208 expect ( response . status ) . toBe ( 200 ) ;
195209 } ) ;
196210
197- it ( 'returns partial=true when not all requested scopes are granted.' , async ( ) : Promise < void > => {
211+ it ( 'returns partial=true for mixed namespaces when not all scopes are granted.' , async ( ) : Promise < void > => {
198212 const permissionResponse = await fetch ( umaConfig . permission_endpoint , {
199213 method : 'POST' ,
200214 headers : {
@@ -204,9 +218,13 @@ describe('A server with partial results enabled', (): void => {
204218 } ,
205219 body : JSON . stringify ( [
206220 {
207- resource_id : resource ,
221+ resource_id : aliceResource ,
208222 resource_scopes : [ readScope , writeScope ] ,
209- }
223+ } ,
224+ {
225+ resource_id : bobResource ,
226+ resource_scopes : [ readScope ] ,
227+ } ,
210228 ] ) ,
211229 } ) ;
212230 expect ( permissionResponse . status ) . toBe ( 201 ) ;
@@ -220,14 +238,14 @@ describe('A server with partial results enabled', (): void => {
220238 // Verify the token contains the allowed scope
221239 const jwtPayload = JSON . parse ( Buffer . from ( token . access_token . split ( '.' ) [ 1 ] , 'base64' ) . toString ( ) ) ;
222240 expect ( Array . isArray ( jwtPayload . permissions ) ) . toBe ( true ) ;
223- expect ( jwtPayload . permissions ) . toContainEqual ( {
224- resource_id : resource ,
241+ expect ( jwtPayload . permissions ) . toEqual ( [ {
242+ resource_id : aliceResource ,
225243 resource_scopes : [ readScope ]
226- } ) ;
244+ } ] ) ;
227245 } ) ;
228246
229247 it ( 'can access a protected resource with partial results.' , async ( ) : Promise < void > => {
230- const response = await umaFetch ( resource , { } , user ) ;
248+ const response = await umaFetch ( aliceResource , { } , user ) ;
231249 expect ( response . status ) . toBe ( 200 ) ;
232250 } ) ;
233251} ) ;
0 commit comments