comparison realip.t @ 1354:c0075a0a2ba9

Tests: added realip test on http post read phase.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 04 Jul 2018 23:46:29 +0300
parents 882267679006
children afe541649054
comparison
equal deleted inserted replaced
1353:65730ba03b42 1354:c0075a0a2ba9
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 my $t = Test::Nginx->new()->has(qw/http realip/); 24 my $t = Test::Nginx->new()->has(qw/http realip rewrite/);
25 25
26 $t->write_file_expand('nginx.conf', <<'EOF'); 26 $t->write_file_expand('nginx.conf', <<'EOF');
27 27
28 %%TEST_GLOBALS%% 28 %%TEST_GLOBALS%%
29 29
39 set_real_ip_from 127.0.0.1/32; 39 set_real_ip_from 127.0.0.1/32;
40 set_real_ip_from 10.0.1.0/24; 40 set_real_ip_from 10.0.1.0/24;
41 41
42 server { 42 server {
43 listen 127.0.0.1:8080; 43 listen 127.0.0.1:8080;
44 listen 127.0.0.1:8081;
44 server_name localhost; 45 server_name localhost;
46
47 if ($server_port = 8081) {
48 return 204;
49 }
45 50
46 location / { } 51 location / { }
47 location /custom { 52 location /custom {
48 real_ip_header X-Real-IP-Custom; 53 real_ip_header X-Real-IP-Custom;
49 } 54 }
69 $t->run(); 74 $t->run();
70 75
71 plan(skip_all => 'no 127.0.0.1 on host') 76 plan(skip_all => 'no 127.0.0.1 on host')
72 if http_get('/') !~ /X-IP: 127.0.0.1/m; 77 if http_get('/') !~ /X-IP: 127.0.0.1/m;
73 78
74 $t->plan(7); 79 $t->plan(8);
75 80
76 ############################################################################### 81 ###############################################################################
77 82
78 like(http(<<EOF), qr/^X-IP: 192.0.2.1/m, 'realip'); 83 like(http(<<EOF), qr/^X-IP: 192.0.2.1/m, 'realip');
79 GET / HTTP/1.0 84 GET / HTTP/1.0
111 X-Forwarded-For: 192.0.2.1 116 X-Forwarded-For: 192.0.2.1
112 X-Forwarded-For: 127.0.0.1 117 X-Forwarded-For: 127.0.0.1
113 118
114 EOF 119 EOF
115 120
121 my $s = IO::Socket::INET->new('127.0.0.1:' . port(8081));
122 like(http(<<EOF, socket => $s), qr/ 204 .*192.0.2.1/s, 'realip post read');
123 GET / HTTP/1.0
124 Host: localhost
125 X-Real-IP: 192.0.2.1
126
127 EOF
128
116 ############################################################################### 129 ###############################################################################
117 130
118 sub http_xff { 131 sub http_xff {
119 my ($uri, $xff) = @_; 132 my ($uri, $xff) = @_;
120 return http(<<EOF); 133 return http(<<EOF);