Mercurial > hg > nginx-tests
comparison proxy_bind_transparent_capability.t @ 1262:b35037b3a9d0
Tests: added "proxy_bind transparent" test with Linux capabilities.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 19 Dec 2017 19:51:19 +0300 |
parents | proxy_bind_transparent.t@5da72eaa893f |
children | 97c8280de681 |
comparison
equal
deleted
inserted
replaced
1261:5da72eaa893f | 1262:b35037b3a9d0 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http proxy_bind transparent with Linux CAP_NET_RAW capability. | |
7 # Ensure that such configuration isn't broken under a non-priveleged user. | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 plan(skip_all => 'no linux capability') if $^O ne 'linux'; | |
27 plan(skip_all => 'must be root') if $> != 0; | |
28 plan(skip_all => '127.0.0.2 local address required') | |
29 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); | |
30 | |
31 my $t = Test::Nginx->new()->has(qw/http proxy/) | |
32 ->write_file_expand('nginx.conf', <<'EOF'); | |
33 | |
34 %%TEST_GLOBALS%% | |
35 | |
36 daemon off; | |
37 | |
38 events { | |
39 } | |
40 | |
41 http { | |
42 %%TEST_GLOBALS_HTTP%% | |
43 | |
44 server { | |
45 listen 127.0.0.1:8080; | |
46 server_name localhost; | |
47 | |
48 location / { | |
49 proxy_bind 127.0.0.2 transparent; | |
50 proxy_pass http://127.0.0.1:8081/; | |
51 } | |
52 } | |
53 | |
54 server { | |
55 listen 127.0.0.1:8081; | |
56 server_name localhost; | |
57 | |
58 location / { | |
59 add_header X-IP $remote_addr always; | |
60 } | |
61 } | |
62 } | |
63 | |
64 EOF | |
65 | |
66 plan(skip_all => 'no capability support yet') unless $t->has_version('1.13.8'); | |
67 | |
68 $t->run()->plan(1); | |
69 | |
70 ############################################################################### | |
71 | |
72 like(http_get('/'), qr/X-IP: 127.0.0.2/, 'transparent'); | |
73 | |
74 ############################################################################### |