1+ import 'jest-rdf' ;
12import { App } from '@solid/community-server' ;
23import { ODRL } from '@solidlab/uma' ;
34import { setGlobalLoggerFactory , WinstonLoggerFactory } from 'global-logger-factory' ;
@@ -151,6 +152,57 @@ describe('A policy server setup', (): void => {
151152 expect ( response . status ) . toBe ( 204 ) ;
152153 } ) ;
153154
155+ it ( 'can replace policies using PUT.' , async ( ) : Promise < void > => {
156+ const policyA = `
157+ @prefix ex: <http://example.org/>.
158+ @prefix odrl: <http://www.w3.org/ns/odrl/2/> .
159+
160+ ex:purposePolicy a odrl:Agreement ;
161+ odrl:uid ex:purposePolicy ;
162+ odrl:permission ex:purposePermission .
163+ ex:purposePermission a odrl:Permission ;
164+ odrl:action odrl:read ;
165+ odrl:target ex:target ;
166+ odrl:assignee ex:assignee ;
167+ odrl:assigner <${ webIds . a } > ;
168+ odrl:constraint ex:constraint1 .
169+ ex:constraint1 a odrl:Constraint ;
170+ odrl:leftOperand odrl:purpose ;
171+ odrl:operator odrl:eq ;
172+ odrl:rightOperand ex:purpose1 .
173+ ` ;
174+ // There was an issue where constraints were not fully removed when replacing policies with PUT
175+ let response = await fetchPolicy ( 'PUT' , webIds . a , 'http://example.org/purposePolicy' , policyA ) ;
176+ expect ( response . status ) . toBe ( 204 ) ;
177+
178+ const policyB = `
179+ @prefix ex: <http://example.org/>.
180+ @prefix odrl: <http://www.w3.org/ns/odrl/2/> .
181+
182+ ex:purposePolicy a odrl:Agreement ;
183+ odrl:uid ex:purposePolicy ;
184+ odrl:permission ex:purposePermission .
185+ ex:purposePermission a odrl:Permission ;
186+ odrl:action odrl:read ;
187+ odrl:target ex:target ;
188+ odrl:assignee ex:assignee ;
189+ odrl:assigner <${ webIds . a } > ;
190+ odrl:constraint ex:constraint1 .
191+ ex:constraint1 a odrl:Constraint ;
192+ odrl:leftOperand odrl:purpose ;
193+ odrl:operator odrl:eq ;
194+ odrl:rightOperand ex:purpose3 .
195+ ` ;
196+ response = await fetchPolicy ( 'PUT' , webIds . a , 'http://example.org/purposePolicy' , policyB ) ;
197+ expect ( response . status ) . toBe ( 204 ) ;
198+
199+ response = await fetchPolicy ( 'GET' , webIds . a , 'http://example.org/purposePolicy' ) ;
200+ expect ( response . status ) . toBe ( 200 ) ;
201+ const getResponse = await response . text ( ) ;
202+ const parser = new Parser ( ) ;
203+ expect ( parser . parse ( policyB ) ) . toBeRdfIsomorphic ( parser . parse ( getResponse ) ) ;
204+ } ) ;
205+
154206 it ( 'can show a user their policies.' , async ( ) : Promise < void > => {
155207 let response = await fetch ( policyEndpoint ) ;
156208 expect ( response . status ) . toBe ( 401 ) ;
@@ -160,6 +212,7 @@ describe('A policy server setup', (): void => {
160212 let store = new Store ( new Parser ( ) . parse ( await response . text ( ) ) ) ;
161213 let policies = store . getSubjects ( ODRL . terms . uid , null , null ) ;
162214 expect ( policies . map ( ( term ) => term . value ) . sort ( ) ) . toEqual ( [
215+ 'http://example.org/purposePolicy' ,
163216 'http://example.org/usagePolicy1' ,
164217 'http://example.org/usagePolicy1a' ,
165218 'urn:uuid:95efe0e8-4fb7-496d-8f3c-4d78c97829bc' ,
0 commit comments