Mercurial > hg > nginx-tests
annotate realip_remote_port.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 766bcbb632ee |
children |
rev | line source |
---|---|
1057
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx realip module, $realip_remote_port variable. |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT http_end /; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http realip/) |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 events { |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 http { |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 set_real_ip_from 127.0.0.1/32; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 real_ip_header X-Forwarded-For; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 server { |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 location / { |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 add_header X-IP $remote_addr; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 add_header X-Real-Port $realip_remote_port; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 EOF |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 $t->write_file('index.html', ''); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 $t->write_file('1', ''); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1057
diff
changeset
|
56 $t->run(); |
1057
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 plan(skip_all => 'no 127.0.0.1 on host') |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 if http_get('/') !~ /X-IP: 127.0.0.1/m; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 $t->plan(4); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 my ($sp, $data) = http_sp_get('/1'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 like($data, qr/X-Real-Port: $sp/, 'request'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 ($sp, $data) = http_sp_get('/'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 like($data, qr/X-Real-Port: $sp/, 'request redirect'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 ($sp, $data) = http_sp_xff('/1', '127.0.0.1:123'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 like($data, qr/X-Real-Port: $sp/, 'realip'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 ($sp, $data) = http_sp_xff('/', '127.0.0.1:123'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 like($data, qr/X-Real-Port: $sp/, 'realip redirect'); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 sub http_sp_get { |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 my $s = http_get(shift, start => 1); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 return ($s->sockport(), http_end($s)); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 sub http_sp_xff { |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 my ($url, $xff) = @_; |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 my $s = http(<<EOF, start => 1); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 GET $url HTTP/1.0 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 Host: localhost |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 X-Forwarded-For: $xff |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 EOF |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 return ($s->sockport(), http_end($s)); |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 } |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 |
e19d41512e22
Tests: added tests for $realip_remote_port variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 ############################################################################### |