@@ -16,6 +16,13 @@ app.get('/test', function (req, res) {
1616} ) ;
1717
1818describe ( 'https-redirect' , function ( ) {
19+ var prod = AV . Cloud . __prod
20+
21+ afterEach ( function ( ) {
22+ // rollback changes on AV.Cloud.__prod
23+ AV . Cloud . __prod = prod
24+ } )
25+
1926 it ( 'should redirect' , function ( done ) {
2027 request ( app )
2128 . get ( '/test' )
@@ -43,4 +50,42 @@ describe('https-redirect', function() {
4350 . expect ( 200 )
4451 . expect ( "Hello World!" , done ) ;
4552 } ) ;
53+
54+ it ( 'should redirect (Forwarded, custom domain on staging)' , function ( done ) {
55+ AV . Cloud . __prod = 0
56+
57+ request ( app )
58+ . get ( '/test' )
59+ . set ( 'Host' , 'stg-custom.domain.com' )
60+ . set ( 'Forwarded' , 'for=1.2.3.4; proto=http, for=10.0.0.1' )
61+ . expect ( 302 )
62+ . end ( function ( err , res ) {
63+ res . headers . location . should . equal ( 'https://stg-custom.domain.com/test' ) ;
64+ done ( ) ;
65+ } )
66+ } ) ;
67+
68+ it ( 'should not redirect (Forwarded, intranet)' , function ( done ) {
69+ AV . Cloud . __prod = 0
70+
71+ request ( app )
72+ . get ( '/test' )
73+ . set ( 'Host' , 'stg-custom.domain.com' )
74+ . set ( 'Forwarded' , 'for=10.0.0.1; proto=http' )
75+ . set ( 'X-Forwarded-Proto' , 'http' )
76+ . expect ( 200 )
77+ . expect ( "Hello World!" , done ) ;
78+ } ) ;
79+
80+ it ( 'should not redirect (Forwarded overwrite X-Forwarded-Proto)' , function ( done ) {
81+ AV . Cloud . __prod = 0
82+
83+ request ( app )
84+ . get ( '/test' )
85+ . set ( 'Host' , 'stg-custom.domain.com' )
86+ . set ( 'Forwarded' , 'for=1.2.3.4; proto=https, for=10.0.0.1; proto=http' )
87+ . set ( 'X-Forwarded-Proto' , 'http' )
88+ . expect ( 200 )
89+ . expect ( "Hello World!" , done ) ;
90+ } ) ;
4691} ) ;
0 commit comments