@@ -50,7 +50,7 @@ func TestListenAndServe(t *testing.T) {
50
50
verifyStatus (t , s , StatusClosed )
51
51
}
52
52
53
- func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled (t * testing.T ) {
53
+ func TestListenAndServe_proxyProtocolEnabled (t * testing.T ) {
54
54
target , err := net .ResolveTCPAddr ("tcp" , serverUrl )
55
55
require .NoError (t , err )
56
56
@@ -70,10 +70,11 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin
70
70
}()
71
71
72
72
testCases := []struct {
73
- desc string
74
- proxyPolicy string
75
- header * proxyproto.Header
76
- isRejected bool
73
+ desc string
74
+ proxyPolicy string
75
+ proxyAllowed []string
76
+ header * proxyproto.Header
77
+ isRejected bool
77
78
}{
78
79
{
79
80
desc : "USE (default) without a header" ,
@@ -123,11 +124,65 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin
123
124
header : header ,
124
125
isRejected : false ,
125
126
},
127
+ {
128
+ desc : "Allow-listed IP with a header" ,
129
+ proxyAllowed : []string {"127.0.0.1" },
130
+ header : header ,
131
+ isRejected : false ,
132
+ },
133
+ {
134
+ desc : "Allow-listed IP without a header" ,
135
+ proxyAllowed : []string {"127.0.0.1" },
136
+ header : nil ,
137
+ isRejected : false ,
138
+ },
139
+ {
140
+ desc : "Allow-listed range with a header" ,
141
+ proxyAllowed : []string {"127.0.0.0/24" },
142
+ header : header ,
143
+ isRejected : false ,
144
+ },
145
+ {
146
+ desc : "Allow-listed range without a header" ,
147
+ proxyAllowed : []string {"127.0.0.0/24" },
148
+ header : nil ,
149
+ isRejected : false ,
150
+ },
151
+ {
152
+ desc : "Not allow-listed IP with a header" ,
153
+ proxyAllowed : []string {"192.168.1.1" },
154
+ header : header ,
155
+ isRejected : true ,
156
+ },
157
+ {
158
+ desc : "Not allow-listed IP without a header" ,
159
+ proxyAllowed : []string {"192.168.1.1" },
160
+ header : nil ,
161
+ isRejected : false ,
162
+ },
163
+ {
164
+ desc : "Not allow-listed range with a header" ,
165
+ proxyAllowed : []string {"192.168.1.0/24" },
166
+ header : header ,
167
+ isRejected : true ,
168
+ },
169
+ {
170
+ desc : "Not allow-listed range without a header" ,
171
+ proxyAllowed : []string {"192.168.1.0/24" },
172
+ header : nil ,
173
+ isRejected : false ,
174
+ },
126
175
}
127
176
128
177
for _ , tc := range testCases {
129
178
t .Run (tc .desc , func (t * testing.T ) {
130
- setupServerWithConfig (t , & config.Config {Server : config.ServerConfig {ProxyProtocol : true , ProxyPolicy : tc .proxyPolicy }})
179
+ setupServerWithConfig (t , & config.Config {
180
+ Server : config.ServerConfig {
181
+ ProxyProtocol : true ,
182
+ ProxyPolicy : tc .proxyPolicy ,
183
+ ProxyAllowed : tc .proxyAllowed ,
184
+ },
185
+ })
131
186
132
187
conn , err := net .DialTCP ("tcp" , nil , target )
133
188
require .NoError (t , err )
0 commit comments