Mercurial > hg > nginx-tests
annotate access.t @ 1896:8b74936ff2ac
Tests: added has_feature() test for CryptX.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 29 May 2023 17:04:36 +0400 |
parents | fcd65708672d |
children |
rev | line source |
---|---|
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # Tests for nginx access module. |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # At the moment only the new "unix:" syntax is tested (cf "all"). |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http proxy access unix/); |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
292
2da774b0fc7d
Tests: skip access.t on platforms without ipv6 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
291
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 http { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server_name localhost; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 location /inet/ { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 proxy_pass http://127.0.0.1:8081/; |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /inet6/ { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 proxy_pass http://[::1]:%%PORT_8081%%/; |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 location /unix/ { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass http://unix:%%TESTDIR%%/unix.sock:/; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 listen [::1]:%%PORT_8081%%; |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 listen unix:%%TESTDIR%%/unix.sock; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 location /allow_all { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 allow all; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 location /allow_unix { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 allow unix:; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location /deny_all { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 deny all; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 location /deny_unix { |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 deny unix:; |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 } |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 EOF |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1190
fcd65708672d
Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1171
diff
changeset
|
83 $t->try_run('no inet6 support')->plan(12); |
291
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 # tests with inet socket |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 like(http_get('/inet/allow_all'), qr/404 Not Found/, 'inet allow all'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 like(http_get('/inet/allow_unix'), qr/404 Not Found/, 'inet allow unix'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 like(http_get('/inet/deny_all'), qr/403 Forbidden/, 'inet deny all'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/inet/deny_unix'), qr/404 Not Found/, 'inet deny unix'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 # tests with inet6 socket |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 like(http_get('/inet6/allow_all'), qr/404 Not Found/, 'inet6 allow all'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 like(http_get('/inet6/allow_unix'), qr/404 Not Found/, 'inet6 allow unix'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 like(http_get('/inet6/deny_all'), qr/403 Forbidden/, 'inet6 deny all'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 like(http_get('/inet6/deny_unix'), qr/404 Not Found/, 'inet6 deny unix'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 # tests with unix socket |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 like(http_get('/unix/allow_all'), qr/404 Not Found/, 'unix allow all'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 like(http_get('/unix/allow_unix'), qr/404 Not Found/, 'unix allow unix'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 like(http_get('/unix/deny_all'), qr/403 Forbidden/, 'unix deny all'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 like(http_get('/unix/deny_unix'), qr/403 Forbidden/, 'unix deny unix'); |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
03d5be12bc3b
Tests: basic tests for access module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 ############################################################################### |