@@ -105,26 +105,46 @@ describe('Ingress', () => {
105105 expect ( cookieValue [ '_iidt' ] ) . toBe ( 'test' )
106106 } )
107107
108- it ( 'should not add proxy integration headers if PROXY_SECRET env not set' , async ( ) => {
109- const request = makeRequest ( new URL ( 'https://test/result' ) , { method : 'POST' } )
108+ it ( 'should add all proxy integration headers if PROXY_SECRET is present, preserving existing headers' , async ( ) => {
109+ const existingHeaderValue = 'testValue'
110+ const secret = '42'
111+ const secretStore = new SecretStore ( 'Fingerprint' )
112+ // @ts -ignore
113+ secretStore . set ( 'PROXY_SECRET' , secret )
114+
115+ const request = makeRequest ( new URL ( 'https://test/result' ) , {
116+ method : 'POST' ,
117+ headers : { 'X-Test' : existingHeaderValue } ,
118+ } )
110119 await handleRequest ( request )
111120
112- expect ( requestHeaders . has ( 'FPJS-Proxy-Secret' ) ) . toBe ( false )
113- expect ( requestHeaders . has ( 'FPJS-Proxy-Client-IP' ) ) . toBe ( false )
114- expect ( requestHeaders . has ( 'FPJS-Proxy-Forwarded-Host' ) ) . toBe ( false )
121+ expect ( requestHeaders . has ( 'FPJS-Proxy-Secret' ) ) . toBe ( true )
122+ expect ( requestHeaders . has ( 'FPJS-Proxy-Client-IP' ) ) . toBe ( true )
123+ expect ( requestHeaders . has ( 'FPJS-Proxy-Forwarded-Host' ) ) . toBe ( true )
124+
125+ expect ( requestHeaders . get ( 'X-Test' ) ) . toBe ( existingHeaderValue )
126+ expect ( requestHeaders . get ( 'FPJS-Proxy-Secret' ) ) . toBe ( secret )
115127 } )
116128
117- it ( 'should add proxy integration headers if PROXY_SECRET is present' , async ( ) => {
129+ // So Fingerprint server can know the request is coming from a proxy integration, even if the proxy secret is missing
130+ it ( 'should add the other proxy integration headers even if PROXY_SECRET is not set, preserving existing headers' , async ( ) => {
131+ const existingHeaderValue = 'testValue'
118132 const secretStore = new SecretStore ( 'Fingerprint' )
119133 // @ts -ignore
120- secretStore . set ( 'PROXY_SECRET' , 'secret' )
134+ // Reset the secret to undefined in case a previous test defined it
135+ secretStore . set ( 'PROXY_SECRET' , undefined )
121136
122- const request = makeRequest ( new URL ( 'https://test/result' ) , { method : 'POST' } )
137+ const request = makeRequest ( new URL ( 'https://test/result' ) , {
138+ method : 'POST' ,
139+ headers : { 'X-Test' : existingHeaderValue } ,
140+ } )
123141 await handleRequest ( request )
124142
125- expect ( requestHeaders . has ( 'FPJS-Proxy-Secret' ) ) . toBe ( true )
143+ expect ( requestHeaders . has ( 'FPJS-Proxy-Secret' ) ) . toBe ( false )
126144 expect ( requestHeaders . has ( 'FPJS-Proxy-Client-IP' ) ) . toBe ( true )
127145 expect ( requestHeaders . has ( 'FPJS-Proxy-Forwarded-Host' ) ) . toBe ( true )
146+
147+ expect ( requestHeaders . get ( 'X-Test' ) ) . toBe ( existingHeaderValue )
128148 } )
129149
130150 it ( 'should set client ip if request has header Fastly-Client-IP' , async ( ) => {
0 commit comments