comparison access.t @ 291:03d5be12bc3b

Tests: basic tests for access module.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 31 May 2013 14:07:15 +0400
parents
children 2da774b0fc7d
comparison
equal deleted inserted replaced
290:f781b087b7aa 291:03d5be12bc3b
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4
5 # Tests for nginx access module.
6
7 # At the moment only the new "unix:" syntax is tested (cf "all").
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 my $t = Test::Nginx->new()->has(qw/http proxy access ipv6/);
27
28 plan(skip_all => 'new syntax "unix:"') unless $t->has_version('1.5.1');
29 plan(skip_all => 'win32') if $^O eq 'MSWin32';
30
31 $t->plan(12)->write_file_expand('nginx.conf', <<'EOF');
32
33 %%TEST_GLOBALS%%
34
35 daemon off;
36
37 events {
38 }
39
40 http {
41 %%TEST_GLOBALS_HTTP%%
42
43 server {
44 listen 127.0.0.1:8080;
45 server_name localhost;
46
47 location /inet/ {
48 proxy_pass http://127.0.0.1:8081/;
49 }
50
51 location /inet6/ {
52 proxy_pass http://[::1]:8081/;
53 }
54
55 location /unix/ {
56 proxy_pass http://unix:%%TESTDIR%%/unix.sock:/;
57 }
58
59 }
60
61 server {
62 listen 127.0.0.1:8081;
63 listen [::1]:8081;
64 listen unix:%%TESTDIR%%/unix.sock;
65
66 location /allow_all {
67 allow all;
68 }
69
70 location /allow_unix {
71 allow unix:;
72 }
73
74 location /deny_all {
75 deny all;
76 }
77
78 location /deny_unix {
79 deny unix:;
80 }
81 }
82 }
83
84 EOF
85
86 $t->run();
87
88 ###############################################################################
89
90 # tests with inet socket
91
92 like(http_get('/inet/allow_all'), qr/404 Not Found/, 'inet allow all');
93 like(http_get('/inet/allow_unix'), qr/404 Not Found/, 'inet allow unix');
94 like(http_get('/inet/deny_all'), qr/403 Forbidden/, 'inet deny all');
95 like(http_get('/inet/deny_unix'), qr/404 Not Found/, 'inet deny unix');
96
97 # tests with inet6 socket
98
99 like(http_get('/inet6/allow_all'), qr/404 Not Found/, 'inet6 allow all');
100 like(http_get('/inet6/allow_unix'), qr/404 Not Found/, 'inet6 allow unix');
101 like(http_get('/inet6/deny_all'), qr/403 Forbidden/, 'inet6 deny all');
102 like(http_get('/inet6/deny_unix'), qr/404 Not Found/, 'inet6 deny unix');
103
104 # tests with unix socket
105
106 like(http_get('/unix/allow_all'), qr/404 Not Found/, 'unix allow all');
107 like(http_get('/unix/allow_unix'), qr/404 Not Found/, 'unix allow unix');
108 like(http_get('/unix/deny_all'), qr/403 Forbidden/, 'unix deny all');
109 like(http_get('/unix/deny_unix'), qr/403 Forbidden/, 'unix deny unix');
110
111 ###############################################################################