annotate realip_remote_addr.t @ 1248:70192b1baf01

Tests: added exception test to stream_js.t using 'require'. The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't currently provide an easy way to check its version, whilst we are obligated to gracefully handle such cases somehow. With such an addition of 'require', now the tests are skipped instead on the previous versions.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 21 Nov 2017 13:16:39 +0300
parents 9b8e13e2ee67
children 766bcbb632ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ###############################################################################