Mercurial > hg > nginx-tests
annotate realip_remote_addr.t @ 1542:451e787aad76
Tests: reworked libgd version detection.
The "libgd-config" binary is deprecated in recent versions and may not exist
or have unexpected output. More, it may not present within older versions,
as well, if installed separately, which previously broke test assumptions.
The fix is change the fallback to skip tests. In addition, recent Perl GD
module (2.57) started to export libgd version, which is now also consulted.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 13 Jan 2020 18:15:35 +0300 |
parents | 766bcbb632ee |
children |
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'); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 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
|
72 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ############################################################################### |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 sub http_xff { |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 my ($uri, $xff) = @_; |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 return http(<<EOF); |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 GET $uri HTTP/1.0 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 Host: localhost |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 X-Forwarded-For: $xff |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 EOF |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |