File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ class LDP {
3838 constructor ( argv = { } ) {
3939 extend ( this , argv )
4040
41+ // Acl contentType
42+ if ( ! this . aclContentType ) {
43+ this . aclContentType = 'text/turtle'
44+ }
45+
4146 // Suffixes
4247 if ( ! this . suffixAcl ) {
4348 this . suffixAcl = '.acl'
@@ -138,6 +143,12 @@ class LDP {
138143 if ( slug . match ( / \/ | \| | : / ) ) {
139144 throw error ( 400 , 'The name of new file POSTed may not contain : | or /' )
140145 }
146+ // not to break pod ACL must have text/turtle contentType
147+ if ( slug . endsWith ( this . suffixAcl ) || extension === this . suffixAcl ) {
148+ if ( contentType !== this . aclContentType ) {
149+ throw error ( 415 , 'POST contentType for ACL must be text/turtle' )
150+ }
151+ }
141152 }
142153 // Containers should not receive an extension
143154 if ( container ) {
@@ -209,6 +220,11 @@ class LDP {
209220 'PUT request require a valid content type via the Content-Type header' )
210221 }
211222
223+ // not to break pod : url ACL must have text/turtle contentType
224+ if ( ( url . url || url ) . endsWith ( this . suffixAcl ) && contentType !== this . aclContentType ) {
225+ throw error ( 415 , 'PUT contentType for ACL must be text-turtle' )
226+ }
227+
212228 // First check if we are above quota
213229 let isOverQuota
214230 try {
Original file line number Diff line number Diff line change @@ -481,6 +481,12 @@ describe('HTTP APIs', function () {
481481 . set ( 'content-type' , 'text/turtle' )
482482 . expect ( 201 , done )
483483 } )
484+ it ( 'should reject create .acl resource, if contentType not text/turtle' , function ( done ) {
485+ server . put ( '/put-resource-1.acl' )
486+ . send ( putRequestBody )
487+ . set ( 'content-type' , 'text/plain' )
488+ . expect ( 415 , done )
489+ } )
484490 it ( 'should create directories if they do not exist' , function ( done ) {
485491 server . put ( '/foo/bar/baz.ttl' )
486492 . send ( putRequestBody )
@@ -594,6 +600,13 @@ describe('HTTP APIs', function () {
594600 . set ( 'content-type' , '' )
595601 . expect ( 415 , done )
596602 } )
603+ it ( 'should error with 415 if file.acl and contentType not text/turtle' , function ( done ) {
604+ server . post ( '/post-tests/' )
605+ . set ( 'slug' , 'post-acl-no-content-type.acl' )
606+ . send ( postRequest1Body )
607+ . set ( 'content-type' , '' )
608+ . expect ( 415 , done )
609+ } )
597610 it ( 'should create new resource even if no trailing / is in the target' ,
598611 function ( done ) {
599612 server . post ( '' )
Original file line number Diff line number Diff line change @@ -163,6 +163,13 @@ describe('LDP', function () {
163163 assert . equal ( err . status , 415 )
164164 } )
165165 } )
166+
167+ it ( 'should fail if file.acl and content type not text/turtle' , ( ) => {
168+ var stream = stringToStream ( 'hello world' )
169+ return ldp . put ( '/resources/testPut.txt.acl' , stream , 'text/plain' ) . catch ( err => {
170+ assert . equal ( err . status , 415 )
171+ } )
172+ } )
166173 } )
167174
168175 describe ( 'delete' , function ( ) {
You can’t perform that action at this time.
0 commit comments