@@ -38,6 +38,35 @@ describe('Validation Utils', () => {
3838 } ) ;
3939 } ) ;
4040
41+ describe ( 'normalizeTrustProxyHeaders' , ( ) => {
42+ it ( 'should return an empty set when input is undefined' , ( ) => {
43+ expect ( normalizeTrustProxyHeaders ( undefined ) ) . toEqual ( new Set ( ) ) ;
44+ } ) ;
45+
46+ it ( 'should return an empty set when input is false' , ( ) => {
47+ expect ( normalizeTrustProxyHeaders ( false ) ) . toEqual ( new Set ( ) ) ;
48+ } ) ;
49+
50+ it ( 'should return a set containing "*" when input is true' , ( ) => {
51+ expect ( normalizeTrustProxyHeaders ( true ) ) . toEqual ( new Set ( [ '*' ] ) ) ;
52+ } ) ;
53+
54+ it ( 'should return a set of lowercased header names when input is an array of strings' , ( ) => {
55+ expect ( normalizeTrustProxyHeaders ( [ 'X-Forwarded-Host' , 'X-Forwarded-Proto' ] ) ) . toEqual (
56+ new Set ( [ 'x-forwarded-host' , 'x-forwarded-proto' ] ) ,
57+ ) ;
58+ } ) ;
59+
60+ it ( 'should throw an error if input array contains "*"' , ( ) => {
61+ expect ( ( ) => normalizeTrustProxyHeaders ( [ '*' ] ) ) . toThrowError (
62+ '"*" is not allowed as a value for the "trustProxyHeaders" option.' ,
63+ ) ;
64+ expect ( ( ) => normalizeTrustProxyHeaders ( [ 'X-Forwarded-Host' , '*' ] ) ) . toThrowError (
65+ '"*" is not allowed as a value for the "trustProxyHeaders" option.' ,
66+ ) ;
67+ } ) ;
68+ } ) ;
69+
4170 describe ( 'validateUrl' , ( ) => {
4271 const allowedHosts = new Set ( [ 'example.com' , '*.google.com' ] ) ;
4372
0 commit comments