@@ -209,6 +209,62 @@ func TestMultipleIpAddressesReverse(t *testing.T) {
209
209
assertStatusCode (t , recorder .Result (), http .StatusForbidden )
210
210
}
211
211
212
+ func TestMultipleIpAddressesProxy (t * testing.T ) {
213
+ cfg := createTesterConfig ()
214
+
215
+ cfg .Countries = append (cfg .Countries , "CA" )
216
+ cfg .XForwardedForReverseProxy = true
217
+
218
+ ctx := context .Background ()
219
+ next := http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {})
220
+
221
+ handler , err := geoblock .New (ctx , next , cfg , "GeoBlock" )
222
+ if err != nil {
223
+ t .Fatal (err )
224
+ }
225
+
226
+ recorder := httptest .NewRecorder ()
227
+
228
+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , "http://localhost" , nil )
229
+ if err != nil {
230
+ t .Fatal (err )
231
+ }
232
+
233
+ req .Header .Add (xForwardedFor , strings .Join ([]string {caExampleIP , chExampleIP }, "," ))
234
+
235
+ handler .ServeHTTP (recorder , req )
236
+
237
+ assertStatusCode (t , recorder .Result (), http .StatusOK )
238
+ }
239
+
240
+ func TestMultipleIpAddressesProxyReverse (t * testing.T ) {
241
+ cfg := createTesterConfig ()
242
+
243
+ cfg .Countries = append (cfg .Countries , "CA" )
244
+ cfg .XForwardedForReverseProxy = true
245
+
246
+ ctx := context .Background ()
247
+ next := http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {})
248
+
249
+ handler , err := geoblock .New (ctx , next , cfg , "GeoBlock" )
250
+ if err != nil {
251
+ t .Fatal (err )
252
+ }
253
+
254
+ recorder := httptest .NewRecorder ()
255
+
256
+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , "http://localhost" , nil )
257
+ if err != nil {
258
+ t .Fatal (err )
259
+ }
260
+
261
+ req .Header .Add (xForwardedFor , strings .Join ([]string {chExampleIP , caExampleIP }, "," ))
262
+
263
+ handler .ServeHTTP (recorder , req )
264
+
265
+ assertStatusCode (t , recorder .Result (), http .StatusForbidden )
266
+ }
267
+
212
268
func TestAllowedUnknownCountry (t * testing.T ) {
213
269
cfg := createTesterConfig ()
214
270
0 commit comments