@@ -15,13 +15,11 @@ describe('HTTP APIs', function() {
1515 } ;
1616 var getLink = function ( res , rel ) {
1717 var links = res . headers . link . split ( ',' ) ;
18- for ( var linkIndex in links ) {
19- var link = links [ linkIndex ] ;
18+ for ( var i in links ) {
19+ var link = links [ i ] ;
2020 var parsedLink = li . parse ( link ) ;
21- for ( var linkRel in parsedLink ) {
22- if ( linkRel == rel ) {
23- return parsedLink [ rel ] ;
24- }
21+ if ( parsedLink [ rel ] ) {
22+ return parsedLink [ rel ] ;
2523 }
2624 }
2725 return undefined ;
@@ -31,23 +29,25 @@ describe('HTTP APIs', function() {
3129 var link = getLink ( res , rel ) ;
3230 if ( link ) {
3331 if ( link !== value ) {
34- console . log ( "Not same value" ) ;
32+ console . log ( "Not same value:" , value , '!=' , link ) ;
3533 }
3634 } else {
37- console . log ( "Header does not exist" ) ;
35+ console . log ( rel , "header does not exist:" , link ) ;
3836 }
3937 } ;
4038 return handler ;
4139 } ;
4240
4341 var address = 'http://localhost:3457' ;
44- var ldp = ldnode . createServer ( {
42+ var ldpServer = ldnode . createServer ( {
4543 root : __dirname + '/resources' ,
4644 } ) ;
47- ldp . listen ( 3457 ) ;
45+ ldpServer . listen ( 3457 ) ;
4846
49- var server = supertest ( address ) ;
47+ var suffixAcl = ".acl" ;
48+ var suffixMeta = ".meta" ;
5049
50+ var server = supertest ( address ) ;
5151
5252 describe ( 'GET Root container' , function ( ) {
5353 it ( 'should have Access-Control-Allow-Origin as the req.Origin' , function ( done ) {
@@ -82,26 +82,40 @@ describe('HTTP APIs', function() {
8282 . end ( done ) ;
8383 } ) ;
8484
85- it ( 'should have Access-Control-Allow-Origin on OPTIONS ' , function ( done ) {
85+ it ( 'should have Access-Control-Allow-Origin' , function ( done ) {
8686 server . options ( '/sampleContainer/example1.ttl' )
8787 . set ( 'Origin' , 'http://example.com' )
8888 . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
8989 . end ( done ) ;
9090 } ) ;
9191
92- it ( 'should have set Link as resource in OPTIONS' , function ( done ) {
92+ it ( 'should have set acl and describedBy Links for resource' , function ( done ) {
93+ server . options ( '/sampleContainer/example1.ttl' )
94+ . expect ( hasHeader ( 'acl' , 'example1.ttl' + suffixAcl ) )
95+ . expect ( hasHeader ( 'describedBy' , 'example1.ttl' + suffixMeta ) )
96+ . end ( done ) ;
97+ } ) ;
98+
99+ it ( 'should have set Link as resource' , function ( done ) {
93100 server . options ( '/sampleContainer/example1.ttl' )
94101 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
95102 . end ( done ) ;
96103 } ) ;
97104
98- it ( 'should have set Link as Container/BasicContainer in OPTIONS ' , function ( done ) {
105+ it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
99106 server . options ( '/sampleContainer/' )
100107 . set ( 'Origin' , 'http://example.com' )
101108 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # B a s i c C o n t a i n e r > ; r e l = " t y p e " / )
102109 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # C o n t a i n e r > ; r e l = " t y p e " / )
103110 . end ( done ) ;
104111 } ) ;
112+
113+ it ( 'should have set acl and describedBy Links for container' , function ( done ) {
114+ server . options ( '/sampleContainer/' )
115+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
116+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
117+ . end ( done ) ;
118+ } ) ;
105119 } ) ;
106120
107121 describe ( 'GET API' , function ( ) {
@@ -124,36 +138,48 @@ describe('HTTP APIs', function() {
124138 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
125139 . expect ( 200 , done ) ;
126140 } ) ;
141+ it ( 'should have set acl and describedBy Links for resource' , function ( done ) {
142+ server . get ( '/sampleContainer/example1.ttl' )
143+ . expect ( hasHeader ( 'acl' , 'example1.ttl' + suffixAcl ) )
144+ . expect ( hasHeader ( 'describedBy' , 'example1.ttl' + suffixMeta ) )
145+ . end ( done ) ;
146+ } ) ;
127147
128148 it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
129149 server . head ( '/sampleContainer/' )
130150 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # B a s i c C o n t a i n e r > ; r e l = " t y p e " / )
131151 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # C o n t a i n e r > ; r e l = " t y p e " / )
132152 . expect ( 200 , done ) ;
133153 } ) ;
134- it ( 'Should return 404 for non-existent resource' , function ( done ) {
154+ it ( 'should return 404 for non-existent resource' , function ( done ) {
135155 server . get ( '/invalidfile.foo' )
136156 . expect ( 404 , done ) ;
137157 } ) ;
138- it ( 'Should return basic container link for directories' , function ( done ) {
158+ it ( 'should return basic container link for directories' , function ( done ) {
139159 server . get ( '/' )
140160 . expect ( 'Link' , / h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # B a s i c C o n t a i n e r / )
141161 . expect ( 200 , done ) ;
142162 } ) ;
143- it ( 'Should return resource link for files' , function ( done ) {
163+ it ( 'should return resource link for files' , function ( done ) {
144164 server . get ( '/hello.html' )
145165 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
146166 . expect ( 200 , done ) ;
147167 } ) ;
148- it ( 'Should have glob support' , function ( done ) {
168+ it ( 'should have glob support' , function ( done ) {
149169 server . get ( '/sampleContainer/example*' )
150170 . expect ( 'content-type' , / t e x t \/ t u r t l e / )
151171 . expect ( 200 , done ) ;
152172 } ) ;
173+
174+ it ( 'should have set acl and describedBy Links for container' , function ( done ) {
175+ server . get ( '/sampleContainer/' )
176+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
177+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
178+ . end ( done ) ;
179+ } ) ;
153180 } ) ;
154181
155182 describe ( 'HEAD API' , function ( ) {
156-
157183 it ( 'should have Access-Control-Allow-Origin as Origin' , function ( done ) {
158184 server . head ( '/sampleContainer/example1.ttl' )
159185 . set ( 'Origin' , 'http://example.com' )
@@ -172,25 +198,26 @@ describe('HTTP APIs', function() {
172198 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # R e s o u r c e > ; r e l = " t y p e " / )
173199 . expect ( 200 , done ) ;
174200 } ) ;
201+ it ( 'should have set acl and describedBy Links for resource' , function ( done ) {
202+ server . get ( '/sampleContainer/example1.ttl' )
203+ . expect ( hasHeader ( 'acl' , 'example1.ttl' + suffixAcl ) )
204+ . expect ( hasHeader ( 'describedBy' , 'example1.ttl' + suffixMeta ) )
205+ . end ( done ) ;
206+ } ) ;
175207
176208 it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
177209 server . get ( '/sampleContainer/' )
178210 . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # B a s i c C o n t a i n e r > ; r e l = " t y p e " / )
179- . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # C o n t a i n e r > ; r e l = " t y p e " / )
211+ . expect ( 'Link' , / < h t t p : \/ \/ w w w .w 3 .o r g \/ n s \/ l d p # C o n t a i n e r > ; r e l = " t y p e " / )
180212 . expect ( 200 , done ) ;
181213 } ) ;
182214
183- it ( 'Should return meta header' , function ( done ) {
184- server . head ( '/' )
185- . expect ( hasHeader ( '\'describedBy\'' , address + '/' + '.meta' ) )
186- . expect ( 200 , done ) ;
187- } ) ;
188- it ( 'Should return acl header' , function ( done ) {
189- server . head ( '/' )
190- . expect ( hasHeader ( '\'acl\'' , address + '/' + '.acl' ) )
191- . expect ( 200 , done ) ;
215+ it ( 'should have set acl and describedBy Links for container' , function ( done ) {
216+ server . get ( '/sampleContainer/' )
217+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
218+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
219+ . end ( done ) ;
192220 } ) ;
193-
194221 } ) ;
195222
196223 describe ( 'PUT API' , function ( ) {
@@ -207,6 +234,8 @@ describe('HTTP APIs', function() {
207234 server . put ( '/foo/bar/baz.ttl' )
208235 . send ( putRequestBody )
209236 . set ( 'content-type' , 'text/turtle' )
237+ . expect ( hasHeader ( 'describedBy' , 'baz.ttl' + suffixMeta ) )
238+ . expect ( hasHeader ( 'acl' , 'baz.ttl' + suffixAcl ) )
210239 . expect ( function ( ) {
211240 fs . unlinkSync ( __dirname + '/resources/foo/bar/baz.ttl' ) ;
212241 fs . rmdirSync ( __dirname + '/resources/foo/bar/' ) ;
@@ -245,6 +274,8 @@ describe('HTTP APIs', function() {
245274 . set ( 'content-type' , 'text/turtle' )
246275 . set ( 'slug' , 'post-resource-1' )
247276 . expect ( 'location' , address + '/post-resource-1.ttl' )
277+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
278+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
248279 . expect ( 201 , done ) ;
249280 } ) ;
250281 it ( 'Should reject requests to existing resources' , function ( done ) {
0 commit comments