11var assert = require ( 'chai' ) . assert
22var supertest = require ( 'supertest' )
3- var nock = require ( 'nock' )
4- var async = require ( 'async' )
53var path = require ( 'path' )
64// Helper functions for the FS
75var rm = require ( './test-utils' ) . rm
@@ -12,103 +10,6 @@ var read = require('./test-utils').read
1210var ldnode = require ( '../index' )
1311
1412describe ( 'LDNODE params' , function ( ) {
15- describe ( 'proxy' , function ( ) {
16- var ldp = ldnode ( {
17- root : path . join ( __dirname , '/resources' ) ,
18- proxy : '/proxy'
19- } )
20- var server = supertest ( ldp )
21-
22- it ( 'should return the website in /proxy?uri' , function ( done ) {
23- nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 )
24- server . get ( '/proxy?uri=https://amazingwebsite.tld/' )
25- . expect ( 200 , done )
26- } )
27-
28- it ( 'should return error on local network requests' , function ( done ) {
29- nock ( 'https://192.168.0.0' ) . get ( '/' ) . reply ( 200 )
30- server . get ( '/proxy?uri=https://192.168.0.0/' )
31- . expect ( 406 , done )
32- } )
33-
34- it ( 'should return error on invalid uri' , function ( done ) {
35- server . get ( '/proxy?uri=HELLOWORLD' )
36- . expect ( 406 , done )
37- } )
38-
39- it ( 'should return error on relative paths' , function ( done ) {
40- server . get ( '/proxy?uri=../' )
41- . expect ( 406 , done )
42- } )
43-
44- it ( 'should return the same headers of proxied request' , function ( done ) {
45- nock ( 'https://amazingwebsite.tld' )
46- . get ( '/' )
47- . reply ( function ( uri , req ) {
48- if ( this . req . headers [ 'accept' ] !== 'text/turtle' ) {
49- throw Error ( 'Accept is received on the header' )
50- }
51- if ( this . req . headers [ 'test' ] && this . req . headers [ 'test' ] === 'test1' ) {
52- return [ 200 , 'YES' ]
53- } else {
54- return [ 500 , 'empty' ]
55- }
56- } )
57-
58- server . get ( '/proxy?uri=https://amazingwebsite.tld/' )
59- . set ( 'test' , 'test1' )
60- . set ( 'accept' , 'text/turtle' )
61- . expect ( 200 )
62- . end ( function ( err , data ) {
63- if ( err ) return done ( err )
64- done ( err )
65- } )
66- } )
67-
68- it ( 'should also work on /proxy/ ?uri' , function ( done ) {
69- nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 )
70- server . get ( '/proxy/?uri=https://amazingwebsite.tld/' )
71- . expect ( function ( a ) {
72- assert . equal ( a . header [ 'link' ] , null )
73- } )
74- . expect ( 200 , done )
75- } )
76-
77- it ( 'should return the same HTTP status code as the uri' , function ( done ) {
78- async . parallel ( [
79- // 500
80- function ( next ) {
81- nock ( 'https://amazingwebsite.tld' ) . get ( '/404' ) . reply ( 404 )
82- server . get ( '/proxy/?uri=https://amazingwebsite.tld/404' )
83- . expect ( 404 , next )
84- } ,
85- function ( next ) {
86- nock ( 'https://amazingwebsite.tld' ) . get ( '/401' ) . reply ( 401 )
87- server . get ( '/proxy/?uri=https://amazingwebsite.tld/401' )
88- . expect ( 401 , next )
89- } ,
90- function ( next ) {
91- nock ( 'https://amazingwebsite.tld' ) . get ( '/500' ) . reply ( 500 )
92- server . get ( '/proxy/?uri=https://amazingwebsite.tld/500' )
93- . expect ( 500 , next )
94- } ,
95- function ( next ) {
96- nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 )
97- server . get ( '/proxy/?uri=https://amazingwebsite.tld/' )
98- . expect ( 200 , next )
99- }
100- ] , done )
101- } )
102-
103- it ( 'should work with cors' , function ( done ) {
104- nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 )
105- server . get ( '/proxy/?uri=https://amazingwebsite.tld/' )
106- . set ( 'Origin' , 'http://example.com' )
107- . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
108- . expect ( 200 , done )
109- } )
110- } )
111-
11213 describe ( 'suffixMeta' , function ( ) {
11314 describe ( 'not passed' , function ( ) {
11415 it ( 'should fallback on .meta' , function ( ) {
0 commit comments