@@ -5,6 +5,10 @@ var ldnode = require('../index');
55var fs = require ( 'fs' ) ;
66var S = require ( 'string' ) ;
77
8+ var emptyResponse = function ( res ) {
9+ return 0 !== res . text . length ;
10+ } ;
11+
812describe ( 'HTTP APIs' , function ( ) {
913 var address = 'http://localhost:3457' ;
1014 var ldp = ldnode . createServer ( {
@@ -14,30 +18,15 @@ describe('HTTP APIs', function() {
1418
1519 var server = supertest ( address ) ;
1620
17- describe ( 'CORS are enabled' , function ( ) {
18- it ( 'should have Access-Control-Allow-Origin in header on root container' , function ( done ) {
19- server . get ( '/' )
20- . set ( 'Origin' , 'http://example.com' )
21- . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
22- . expect ( 200 , done ) ;
23- } ) ;
24-
25- it ( 'should have Access-Control-Allow-Origin in header on other containers' , function ( done ) {
26- server . get ( '/sampleContainer' )
27- . set ( 'Origin' , 'http://example.com' )
28- . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
29- . expect ( 200 , done ) ;
30- } ) ;
31-
32- it ( 'should have Access-Control-Allow-Origin in header on resources' , function ( done ) {
33- server . get ( '/sampleContainer/example1.ttl' )
34- . set ( 'Origin' , 'http://example.com' )
35- . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
36- . expect ( 200 , done ) ;
37- } ) ;
38- } ) ;
3921
4022 describe ( 'GET Root container' , function ( ) {
23+ it ( 'should have Access-Control-Allow-Origin as the req.Origin' , function ( done ) {
24+ server . get ( '/' )
25+ . set ( 'Origin' , 'http://example.com' )
26+ . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
27+ . expect ( 200 , done ) ;
28+ } ) ;
29+
4130 it ( 'Should exists' , function ( done ) {
4231 server . get ( '/' )
4332 . expect ( 200 , done ) ;
@@ -49,7 +38,69 @@ describe('HTTP APIs', function() {
4938 } ) ;
5039 } ) ;
5140
41+ describe ( 'OPTIONS API' , function ( ) {
42+
43+ it ( 'should have an empty response' , function ( done ) {
44+ server . options ( '/sampleContainer/example1.ttl' )
45+ . expect ( emptyResponse )
46+ . end ( done ) ;
47+ } ) ;
48+
49+ it ( 'should return 204 on success' , function ( done ) {
50+ server . options ( '/sampleContainer/example1.ttl' )
51+ . expect ( 204 )
52+ . end ( done ) ;
53+ } ) ;
54+
55+ it ( 'should have Access-Control-Allow-Origin on OPTIONS' , function ( done ) {
56+ server . options ( '/sampleContainer/example1.ttl' )
57+ . set ( 'Origin' , 'http://example.com' )
58+ . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
59+ . end ( done ) ;
60+ } ) ;
61+
62+ it ( 'should have set Link as resource in OPTIONS' , function ( done ) {
63+ server . options ( '/sampleContainer/example1.ttl' )
64+ . expect ( 'Link' , "<http://www.w3.org/ns/ldp#Resource>; rel='type'" )
65+ . end ( done ) ;
66+ } ) ;
67+
68+ it ( 'should have set Link as Container/BasicContainer in OPTIONS' , function ( done ) {
69+ server . options ( '/sampleContainer/' )
70+ . set ( 'Origin' , 'http://example.com' )
71+ . expect ( 'Link' , "<http://www.w3.org/ns/ldp#Container>; rel='type'," +
72+ " <http://www.w3.org/ns/ldp#BasicContainer>; rel='type'" )
73+ . end ( done ) ;
74+ } ) ;
75+ } ) ;
76+
5277 describe ( 'GET API' , function ( ) {
78+ it ( 'should have Access-Control-Allow-Origin as Origin on containers' , function ( done ) {
79+ server . get ( '/sampleContainer' )
80+ . set ( 'Origin' , 'http://example.com' )
81+ . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
82+ . expect ( 200 , done ) ;
83+ } ) ;
84+
85+ it ( 'should have Access-Control-Allow-Origin as Origin on resources' , function ( done ) {
86+ server . get ( '/sampleContainer/example1.ttl' )
87+ . set ( 'Origin' , 'http://example.com' )
88+ . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
89+ . expect ( 200 , done ) ;
90+ } ) ;
91+
92+ it ( 'should have set Link as resource' , function ( done ) {
93+ server . get ( '/sampleContainer/example1.ttl' )
94+ . expect ( 'Link' , "<http://www.w3.org/ns/ldp#Resource>; rel='type'" )
95+ . expect ( 200 , done ) ;
96+ } ) ;
97+
98+ it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
99+ server . head ( '/sampleContainer/' )
100+ . expect ( 'Link' , "<http://www.w3.org/ns/ldp#Container>; rel='type'," +
101+ " <http://www.w3.org/ns/ldp#BasicContainer>; rel='type'" )
102+ . expect ( 200 , done ) ;
103+ } ) ;
53104 it ( 'Should return 404 for non-existent resource' , function ( done ) {
54105 server . get ( '/invalidfile.foo' )
55106 . expect ( 404 , done ) ;
@@ -72,14 +123,31 @@ describe('HTTP APIs', function() {
72123 } ) ;
73124
74125 describe ( 'HEAD API' , function ( ) {
75- var emptyResponse = function ( res ) {
76- return 0 !== res . text . length ;
77- } ;
126+ it ( 'should have Access-Control-Allow-Origin == Origin' , function ( done ) {
127+ server . head ( '/sampleContainer/example1.ttl' )
128+ . set ( 'Origin' , 'http://example.com' )
129+ . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
130+ . expect ( 200 , done ) ;
131+ } ) ;
132+
78133 it ( 'Should return empty response body' , function ( done ) {
79134 server . head ( '/patch-5-initial.ttl' )
80135 . expect ( emptyResponse )
81136 . expect ( 200 , done ) ;
82137 } ) ;
138+
139+ it ( 'should have set Link as Resource' , function ( done ) {
140+ server . head ( '/sampleContainer/example1.ttl' )
141+ . expect ( 'Link' , "<http://www.w3.org/ns/ldp#Resource>; rel='type'" )
142+ . expect ( 200 , done ) ;
143+ } ) ;
144+
145+ it ( 'should have set Link as Container/BasicContainer' , function ( done ) {
146+ server . get ( '/sampleContainer/' )
147+ . expect ( 'Link' , "<http://www.w3.org/ns/ldp#Container>; rel='type'," +
148+ " <http://www.w3.org/ns/ldp#BasicContainer>; rel='type'" )
149+ . expect ( 200 , done ) ;
150+ } ) ;
83151 } ) ;
84152
85153 describe ( 'PUT API' , function ( ) {
0 commit comments