@@ -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,30 +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 ( {
45- root : __dirname + '/resources' ,
46- xssProxy : '/proxy'
42+ var ldpServer = ldnode . createServer ( {
43+ root : __dirname + '/resources'
4744 } ) ;
48- ldp . listen ( 3457 ) ;
45+ ldpServer . listen ( 3457 ) ;
4946
50- var server = supertest ( address ) ;
47+ var suffixAcl = ".acl" ;
48+ var suffixMeta = ".meta" ;
5149
52- describe ( 'Proxy' , function ( ) {
53- it ( 'should return the website in ?uri' , function ( done ) {
54- server . get ( '/proxy?uri=http://google.com' )
55- . expect ( 200 , done ) ;
56- } ) ;
57- } ) ;
50+ var server = supertest ( address ) ;
5851
5952 describe ( 'GET Root container' , function ( ) {
6053 it ( 'should have Access-Control-Allow-Origin as the req.Origin' , function ( done ) {
@@ -89,26 +82,40 @@ describe('HTTP APIs', function() {
8982 . end ( done ) ;
9083 } ) ;
9184
92- it ( 'should have Access-Control-Allow-Origin on OPTIONS ' , function ( done ) {
85+ it ( 'should have Access-Control-Allow-Origin' , function ( done ) {
9386 server . options ( '/sampleContainer/example1.ttl' )
9487 . set ( 'Origin' , 'http://example.com' )
9588 . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
9689 . end ( done ) ;
9790 } ) ;
9891
99- 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 ) {
100100 server . options ( '/sampleContainer/example1.ttl' )
101101 . 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 " / )
102102 . end ( done ) ;
103103 } ) ;
104104
105- it ( 'should have set Link as Container/BasicContainer in OPTIONS ' , function ( done ) {
105+ it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
106106 server . options ( '/sampleContainer/' )
107107 . set ( 'Origin' , 'http://example.com' )
108108 . 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 " / )
109109 . 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 " / )
110110 . end ( done ) ;
111111 } ) ;
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+ } ) ;
112119 } ) ;
113120
114121 describe ( 'GET API' , function ( ) {
@@ -131,36 +138,48 @@ describe('HTTP APIs', function() {
131138 . 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 " / )
132139 . expect ( 200 , done ) ;
133140 } ) ;
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+ } ) ;
134147
135148 it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
136149 server . head ( '/sampleContainer/' )
137150 . 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 " / )
138151 . 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 " / )
139152 . expect ( 200 , done ) ;
140153 } ) ;
141- it ( 'Should return 404 for non-existent resource' , function ( done ) {
154+ it ( 'should return 404 for non-existent resource' , function ( done ) {
142155 server . get ( '/invalidfile.foo' )
143156 . expect ( 404 , done ) ;
144157 } ) ;
145- it ( 'Should return basic container link for directories' , function ( done ) {
158+ it ( 'should return basic container link for directories' , function ( done ) {
146159 server . get ( '/' )
147160 . 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 / )
148161 . expect ( 200 , done ) ;
149162 } ) ;
150- it ( 'Should return resource link for files' , function ( done ) {
163+ it ( 'should return resource link for files' , function ( done ) {
151164 server . get ( '/hello.html' )
152165 . 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 " / )
153166 . expect ( 200 , done ) ;
154167 } ) ;
155- it ( 'Should have glob support' , function ( done ) {
168+ it ( 'should have glob support' , function ( done ) {
156169 server . get ( '/sampleContainer/example*' )
157170 . expect ( 'content-type' , / t e x t \/ t u r t l e / )
158171 . expect ( 200 , done ) ;
159172 } ) ;
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+ } ) ;
160180 } ) ;
161181
162182 describe ( 'HEAD API' , function ( ) {
163-
164183 it ( 'should have Access-Control-Allow-Origin as Origin' , function ( done ) {
165184 server . head ( '/sampleContainer/example1.ttl' )
166185 . set ( 'Origin' , 'http://example.com' )
@@ -179,25 +198,26 @@ describe('HTTP APIs', function() {
179198 . 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 " / )
180199 . expect ( 200 , done ) ;
181200 } ) ;
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+ } ) ;
182207
183208 it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
184209 server . get ( '/sampleContainer/' )
185210 . 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 " / )
186- . 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 " / )
187212 . expect ( 200 , done ) ;
188213 } ) ;
189214
190- it ( 'Should return meta header' , function ( done ) {
191- server . head ( '/' )
192- . expect ( hasHeader ( '\'describedBy\'' , address + '/' + '.meta' ) )
193- . expect ( 200 , done ) ;
194- } ) ;
195- it ( 'Should return acl header' , function ( done ) {
196- server . head ( '/' )
197- . expect ( hasHeader ( '\'acl\'' , address + '/' + '.acl' ) )
198- . 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 ) ;
199220 } ) ;
200-
201221 } ) ;
202222
203223 describe ( 'PUT API' , function ( ) {
@@ -214,6 +234,8 @@ describe('HTTP APIs', function() {
214234 server . put ( '/foo/bar/baz.ttl' )
215235 . send ( putRequestBody )
216236 . set ( 'content-type' , 'text/turtle' )
237+ . expect ( hasHeader ( 'describedBy' , 'baz.ttl' + suffixMeta ) )
238+ . expect ( hasHeader ( 'acl' , 'baz.ttl' + suffixAcl ) )
217239 . expect ( function ( ) {
218240 fs . unlinkSync ( __dirname + '/resources/foo/bar/baz.ttl' ) ;
219241 fs . rmdirSync ( __dirname + '/resources/foo/bar/' ) ;
@@ -252,6 +274,8 @@ describe('HTTP APIs', function() {
252274 . set ( 'content-type' , 'text/turtle' )
253275 . set ( 'slug' , 'post-resource-1' )
254276 . expect ( 'location' , address + '/post-resource-1.ttl' )
277+ . expect ( hasHeader ( 'describedBy' , suffixMeta ) )
278+ . expect ( hasHeader ( 'acl' , suffixAcl ) )
255279 . expect ( 201 , done ) ;
256280 } ) ;
257281 it ( 'Should reject requests to existing resources' , function ( done ) {
0 commit comments