Mercurial > hg > nginx-tests
annotate realip_remote_addr.t @ 1240:f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
When the testing script is run in verbose mode by prove that redirects stdout,
a garbled verbose mode line from backend can be produced that incorporates TAP
output of an individual test result, which eventually breaks the testing plan.
Notably, this happens when testing sending multiple frames if backend started
to respond before all frames were received. This is possible due to the line
boundary used as an indicator of last bytes to receive before starting to send.
The fix is to amend the only last frame of many specially, for that purpose.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Nov 2017 20:16:09 +0300 |
parents | 9b8e13e2ee67 |
children | 766bcbb632ee |
rev | line source |
---|---|
786
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx realip module, realip_remote_addr variable. |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http realip/); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 set_real_ip_from 127.0.0.1/32; |
1054
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
40 set_real_ip_from 192.0.2.1/32; |
786
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 real_ip_header X-Forwarded-For; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 listen 127.0.0.1:8080; |
786
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server_name localhost; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location / { |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 add_header X-IP $remote_addr; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 add_header X-Real-IP $realip_remote_addr; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 EOF |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 $t->write_file('index.html', ''); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 $t->write_file('1', ''); |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
58 $t->run(); |
786
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 plan(skip_all => 'no 127.0.0.1 on host') |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 if http_get('/') !~ /X-IP: 127.0.0.1/m; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 $t->plan(4); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 ############################################################################### |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 like(http_get('/1'), qr/X-Real-IP: 127.0.0.1/m, 'request'); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 like(http_get('/'), qr/X-Real-IP: 127.0.0.1/m, 'request redirect'); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 like(http_xff('/1', '192.0.2.1'), qr/X-Real-IP: 127.0.0.1/m, 'realip'); |
1054
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
71 |
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
72 TODO: { |
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
73 local $TODO = 'not yet' unless $t->has_version('1.11.5'); |
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
74 |
786
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like(http_xff('/', '192.0.2.1'), qr/X-Real-IP: 127.0.0.1/m, 'realip redirect'); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
1054
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
77 } |
9b8e13e2ee67
Tests: one more $realip_remote_addr test case on internal redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
78 |
786
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 sub http_xff { |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 my ($uri, $xff) = @_; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 return http(<<EOF); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 GET $uri HTTP/1.0 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 Host: localhost |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 X-Forwarded-For: $xff |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 EOF |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 ############################################################################### |