@@ -15,8 +15,8 @@ describe('proxy', () => {
1515 var server = supertest ( ldp )
1616
1717 it ( 'should return the website in /proxy?uri' , ( done ) => {
18- nock ( 'https://amazingwebsite.tld ' ) . get ( '/' ) . reply ( 200 )
19- server . get ( '/proxy?uri=https://amazingwebsite.tld /' )
18+ nock ( 'https://example.org ' ) . get ( '/' ) . reply ( 200 )
19+ server . get ( '/proxy?uri=https://example.org /' )
2020 . expect ( 200 , done )
2121 } )
2222
@@ -28,10 +28,21 @@ describe('proxy', () => {
2828 . end ( done )
2929 } )
3030
31- it ( 'should return 400 on local network requests' , ( done ) => {
32- nock ( 'https://192.168.0.0' ) . get ( '/' ) . reply ( 200 )
33- server . get ( '/proxy?uri=https://192.168.0.0/' )
34- . expect ( 'Cannot proxy https://192.168.0.0/' )
31+ const LOCAL_IPS = [ '127.0.0.0' , '10.0.0.0' , '172.16.0.0' , '192.168.0.0' ]
32+ LOCAL_IPS . forEach ( ip => {
33+ it ( `should return 400 for a ${ ip } address` , ( done ) => {
34+ nock ( `https://${ ip } ` ) . get ( '/' ) . reply ( 200 )
35+ server . get ( `/proxy?uri=https://${ ip } /` )
36+ . expect ( `Cannot proxy https://${ ip } /` )
37+ . expect ( 400 )
38+ . end ( done )
39+ } )
40+ } )
41+
42+ it ( 'should return 400 with a local hostname' , ( done ) => {
43+ nock ( 'https://nic.localhost' ) . get ( '/' ) . reply ( 200 )
44+ server . get ( '/proxy?uri=https://nic.localhost/' )
45+ . expect ( 'Cannot proxy https://nic.localhost/' )
3546 . expect ( 400 )
3647 . end ( done )
3748 } )
@@ -51,7 +62,7 @@ describe('proxy', () => {
5162 } )
5263
5364 it ( 'should return the same headers of proxied request' , ( done ) => {
54- nock ( 'https://amazingwebsite.tld ' )
65+ nock ( 'https://example.org ' )
5566 . get ( '/' )
5667 . reply ( function ( uri , req ) {
5768 if ( this . req . headers [ 'accept' ] !== 'text/turtle' ) {
@@ -64,7 +75,7 @@ describe('proxy', () => {
6475 }
6576 } )
6677
67- server . get ( '/proxy?uri=https://amazingwebsite.tld /' )
78+ server . get ( '/proxy?uri=https://example.org /' )
6879 . set ( 'test' , 'test1' )
6980 . set ( 'accept' , 'text/turtle' )
7081 . expect ( 200 )
@@ -75,8 +86,8 @@ describe('proxy', () => {
7586 } )
7687
7788 it ( 'should also work on /proxy/ ?uri' , ( done ) => {
78- nock ( 'https://amazingwebsite.tld ' ) . get ( '/' ) . reply ( 200 )
79- server . get ( '/proxy/?uri=https://amazingwebsite.tld /' )
89+ nock ( 'https://example.org ' ) . get ( '/' ) . reply ( 200 )
90+ server . get ( '/proxy/?uri=https://example.org /' )
8091 . expect ( ( a ) => {
8192 assert . equal ( a . header [ 'link' ] , null )
8293 } )
@@ -87,31 +98,31 @@ describe('proxy', () => {
8798 async . parallel ( [
8899 // 500
89100 ( next ) => {
90- nock ( 'https://amazingwebsite.tld ' ) . get ( '/404' ) . reply ( 404 )
91- server . get ( '/proxy/?uri=https://amazingwebsite.tld /404' )
101+ nock ( 'https://example.org ' ) . get ( '/404' ) . reply ( 404 )
102+ server . get ( '/proxy/?uri=https://example.org /404' )
92103 . expect ( 404 , next )
93104 } ,
94105 ( next ) => {
95- nock ( 'https://amazingwebsite.tld ' ) . get ( '/401' ) . reply ( 401 )
96- server . get ( '/proxy/?uri=https://amazingwebsite.tld /401' )
106+ nock ( 'https://example.org ' ) . get ( '/401' ) . reply ( 401 )
107+ server . get ( '/proxy/?uri=https://example.org /401' )
97108 . expect ( 401 , next )
98109 } ,
99110 ( next ) => {
100- nock ( 'https://amazingwebsite.tld ' ) . get ( '/500' ) . reply ( 500 )
101- server . get ( '/proxy/?uri=https://amazingwebsite.tld /500' )
111+ nock ( 'https://example.org ' ) . get ( '/500' ) . reply ( 500 )
112+ server . get ( '/proxy/?uri=https://example.org /500' )
102113 . expect ( 500 , next )
103114 } ,
104115 ( next ) => {
105- nock ( 'https://amazingwebsite.tld ' ) . get ( '/' ) . reply ( 200 )
106- server . get ( '/proxy/?uri=https://amazingwebsite.tld /' )
116+ nock ( 'https://example.org ' ) . get ( '/' ) . reply ( 200 )
117+ server . get ( '/proxy/?uri=https://example.org /' )
107118 . expect ( 200 , next )
108119 }
109120 ] , done )
110121 } )
111122
112123 it ( 'should work with cors' , ( done ) => {
113- nock ( 'https://amazingwebsite.tld ' ) . get ( '/' ) . reply ( 200 )
114- server . get ( '/proxy/?uri=https://amazingwebsite.tld /' )
124+ nock ( 'https://example.org ' ) . get ( '/' ) . reply ( 200 )
125+ server . get ( '/proxy/?uri=https://example.org /' )
115126 . set ( 'Origin' , 'http://example.com' )
116127 . expect ( 'Access-Control-Allow-Origin' , 'http://example.com' )
117128 . expect ( 200 , done )
0 commit comments