@@ -284,37 +284,40 @@ func TestExecuteServers_IPFamily(t *testing.T) {
284
284
}
285
285
286
286
func TestExecuteServers_RewriteClientIP (t * testing.T ) {
287
+ httpServers := []dataplane.VirtualServer {
288
+ {
289
+ IsDefault : true ,
290
+ Port : 8080 ,
291
+ },
292
+ {
293
+ Hostname : "example.com" ,
294
+ Port : 8080 ,
295
+ },
296
+ }
297
+
298
+ sslServers := []dataplane.VirtualServer {
299
+ {
300
+ IsDefault : true ,
301
+ Port : 8443 ,
302
+ },
303
+ {
304
+ Hostname : "example.com" ,
305
+ SSL : & dataplane.SSL {
306
+ KeyPairID : "test-keypair" ,
307
+ },
308
+ Port : 8443 ,
309
+ },
310
+ }
287
311
tests := []struct {
288
312
msg string
289
313
expectedHTTPConfig map [string ]int
290
314
config dataplane.Configuration
291
315
}{
292
316
{
293
- msg : "http and ssl servers with rewrite client IP settings" ,
317
+ msg : "rewrite client IP settings configured with proxy protocol " ,
294
318
config : dataplane.Configuration {
295
- HTTPServers : []dataplane.VirtualServer {
296
- {
297
- IsDefault : true ,
298
- Port : 8080 ,
299
- },
300
- {
301
- Hostname : "example.com" ,
302
- Port : 8080 ,
303
- },
304
- },
305
- SSLServers : []dataplane.VirtualServer {
306
- {
307
- IsDefault : true ,
308
- Port : 8443 ,
309
- },
310
- {
311
- Hostname : "example.com" ,
312
- SSL : & dataplane.SSL {
313
- KeyPairID : "test-keypair" ,
314
- },
315
- Port : 8443 ,
316
- },
317
- },
319
+ HTTPServers : httpServers ,
320
+ SSLServers : sslServers ,
318
321
BaseHTTPConfig : dataplane.BaseHTTPConfig {
319
322
IPFamily : dataplane .Dual ,
320
323
RewriteClientIPSettings : dataplane.RewriteClientIPSettings {
@@ -328,6 +331,7 @@ func TestExecuteServers_RewriteClientIP(t *testing.T) {
328
331
"set_real_ip_from 0.0.0.0/0;" : 4 ,
329
332
"real_ip_header proxy_protocol;" : 4 ,
330
333
"real_ip_recursive on;" : 4 ,
334
+ "proxy_protocol on;" : 4 ,
331
335
"listen 8080 default_server proxy_protocol;" : 1 ,
332
336
"listen 8080 proxy_protocol;" : 1 ,
333
337
"listen 8443 ssl default_server proxy_protocol;" : 1 ,
@@ -342,6 +346,39 @@ func TestExecuteServers_RewriteClientIP(t *testing.T) {
342
346
"listen [::]:8443 ssl proxy_protocol;" : 1 ,
343
347
},
344
348
},
349
+ {
350
+ msg : "rewrite client IP settings configured with x-forwarded-for" ,
351
+ config : dataplane.Configuration {
352
+ HTTPServers : httpServers ,
353
+ SSLServers : sslServers ,
354
+ BaseHTTPConfig : dataplane.BaseHTTPConfig {
355
+ IPFamily : dataplane .Dual ,
356
+ RewriteClientIPSettings : dataplane.RewriteClientIPSettings {
357
+ Mode : dataplane .RewriteIPModeXForwardedFor ,
358
+ TrustedCIDRs : []string {"0.0.0.0/0" },
359
+ IPRecursive : true ,
360
+ },
361
+ },
362
+ },
363
+ expectedHTTPConfig : map [string ]int {
364
+ "set_real_ip_from 0.0.0.0/0;" : 4 ,
365
+ "real_ip_header X-Forwarded-For;" : 4 ,
366
+ "real_ip_recursive on;" : 4 ,
367
+ "proxy_protocol on;" : 0 ,
368
+ "listen 8080 default_server;" : 1 ,
369
+ "listen 8080;" : 1 ,
370
+ "listen 8443 ssl default_server;" : 1 ,
371
+ "listen 8443 ssl;" : 1 ,
372
+ "server_name example.com;" : 2 ,
373
+ "ssl_certificate /etc/nginx/secrets/test-keypair.pem;" : 1 ,
374
+ "ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;" : 1 ,
375
+ "ssl_reject_handshake on;" : 1 ,
376
+ "listen [::]:8080 default_server;" : 1 ,
377
+ "listen [::]:8080;" : 1 ,
378
+ "listen [::]:8443 ssl default_server;" : 1 ,
379
+ "listen [::]:8443 ssl;" : 1 ,
380
+ },
381
+ },
345
382
}
346
383
347
384
for _ , test := range tests {
@@ -355,6 +392,7 @@ func TestExecuteServers_RewriteClientIP(t *testing.T) {
355
392
httpMatchConf := string (results [1 ].data )
356
393
g .Expect (httpMatchConf ).To (Equal ("{}" ))
357
394
395
+ fmt .Println (serverConf )
358
396
for expSubStr , expCount := range test .expectedHTTPConfig {
359
397
g .Expect (strings .Count (serverConf , expSubStr )).To (Equal (expCount ))
360
398
}
0 commit comments