11var assert = require ( 'chai' ) . assert ;
22var supertest = require ( 'supertest' ) ;
3+ var nock = require ( 'nock' ) ;
4+ var async = require ( 'async' ) ;
35// Helper functions for the FS
46var rm = require ( './test-utils' ) . rm ;
57var write = require ( './test-utils' ) . write ;
@@ -11,7 +13,6 @@ var ldnode = require('../index');
1113describe ( 'LDNODE params' , function ( ) {
1214
1315 describe ( 'proxy' , function ( ) {
14- this . timeout ( 10000 ) ;
1516
1617 var ldp = ldnode ( {
1718 root : __dirname + '/resources' ,
@@ -20,14 +21,46 @@ describe('LDNODE params', function () {
2021 var server = supertest ( ldp ) ;
2122
2223 it ( 'should return the website in /proxy?uri' , function ( done ) {
23- server . get ( '/proxy?uri=https://google.com' )
24- . set ( 'Origin' , 'http://example.com' )
25- . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
24+ nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 ) ;
25+ server . get ( '/proxy?uri=https://amazingwebsite.tld/' )
2626 . expect ( 200 , done ) ;
2727 } ) ;
2828
2929 it ( 'should also work on /proxy/ ?uri' , function ( done ) {
30- server . get ( '/proxy/?uri=https://google.com' )
30+ nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 ) ;
31+ server . get ( '/proxy/?uri=https://amazingwebsite.tld/' )
32+ . expect ( 200 , done ) ;
33+ } ) ;
34+
35+ it ( 'should return the same HTTP status code as the uri' , function ( done ) {
36+ async . parallel ( [
37+ // 500
38+ function ( next ) {
39+ nock ( 'https://amazingwebsite.tld' ) . get ( '/404' ) . reply ( 404 ) ;
40+ server . get ( '/proxy/?uri=https://amazingwebsite.tld/404' )
41+ . expect ( 404 , next ) ;
42+ } ,
43+ function ( next ) {
44+ nock ( 'https://amazingwebsite.tld' ) . get ( '/401' ) . reply ( 401 ) ;
45+ server . get ( '/proxy/?uri=https://amazingwebsite.tld/401' )
46+ . expect ( 401 , next ) ;
47+ } ,
48+ function ( next ) {
49+ nock ( 'https://amazingwebsite.tld' ) . get ( '/500' ) . reply ( 500 ) ;
50+ server . get ( '/proxy/?uri=https://amazingwebsite.tld/500' )
51+ . expect ( 500 , next ) ;
52+ } ,
53+ function ( next ) {
54+ nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 ) ;
55+ server . get ( '/proxy/?uri=https://amazingwebsite.tld/' )
56+ . expect ( 200 , next ) ;
57+ }
58+ ] , done ) ;
59+ } ) ;
60+
61+ it ( 'should work with cors' , function ( done ) {
62+ nock ( 'https://amazingwebsite.tld' ) . get ( '/' ) . reply ( 200 ) ;
63+ server . get ( '/proxy/?uri=https://amazingwebsite.tld/' )
3164 . set ( 'Origin' , 'http://example.com' )
3265 . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
3366 . expect ( 200 , done ) ;
0 commit comments