comparison t/auth-request.t @ 4:35f0ee7a3c28

Auth request: fix SIGSEGV on POST.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 05 Mar 2010 21:04:17 +0300
parents dfc5ae42367a
children 70f3d876b569
comparison
equal deleted inserted replaced
3:666c7bf3e009 4:35f0ee7a3c28
7 ############################################################################### 7 ###############################################################################
8 8
9 use warnings; 9 use warnings;
10 use strict; 10 use strict;
11 11
12 use Socket qw/ CRLF /;
13
12 use Test::More; 14 use Test::More;
13 use Test::Nginx; 15 use Test::Nginx;
14 16
15 ############################################################################### 17 ###############################################################################
16 18
17 select STDERR; $| = 1; 19 select STDERR; $| = 1;
18 select STDOUT; $| = 1; 20 select STDOUT; $| = 1;
19 21
20 my $t = Test::Nginx->new()->has(qw/http rewrite proxy fastcgi auth_basic/) 22 my $t = Test::Nginx->new()->has(qw/http rewrite proxy fastcgi auth_basic/)
21 ->plan(14); 23 ->plan(17);
22 24
23 $t->write_file_expand('nginx.conf', <<'EOF'); 25 $t->write_file_expand('nginx.conf', <<'EOF');
24 26
25 master_process off; 27 master_process off;
26 daemon off; 28 daemon off;
81 location /proxy { 83 location /proxy {
82 auth_request /auth-proxy; 84 auth_request /auth-proxy;
83 } 85 }
84 location = /auth-proxy { 86 location = /auth-proxy {
85 proxy_pass http://127.0.0.1:8080/auth-basic; 87 proxy_pass http://127.0.0.1:8080/auth-basic;
88 proxy_pass_request_body off;
89 proxy_set_header Content-Length "";
86 } 90 }
87 location = /auth-basic { 91 location = /auth-basic {
88 auth_basic "restricted"; 92 auth_basic "restricted";
89 auth_basic_user_file %%TESTDIR%%/htpasswd; 93 auth_basic_user_file %%TESTDIR%%/htpasswd;
90 } 94 }
92 location /fastcgi { 96 location /fastcgi {
93 auth_request /auth-fastcgi; 97 auth_request /auth-fastcgi;
94 } 98 }
95 location = /auth-fastcgi { 99 location = /auth-fastcgi {
96 fastcgi_pass 127.0.0.1:8081; 100 fastcgi_pass 127.0.0.1:8081;
101 fastcgi_pass_request_body off;
97 } 102 }
98 } 103 }
99 } 104 }
100 105
101 EOF 106 EOF
113 like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized'); 118 like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized');
114 like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden'); 119 like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden');
115 like(http_get('/error'), qr/ 500 /, 'auth error'); 120 like(http_get('/error'), qr/ 500 /, 'auth error');
116 like(http_get('/off'), qr/ 404 /, 'auth off'); 121 like(http_get('/off'), qr/ 404 /, 'auth off');
117 122
123 like(http_post('/open'), qr/ 404 /, 'auth post open');
124 like(http_post('/unauthorized'), qr/ 401 /, 'auth post unauthorized');
125
118 like(http_get('/open-static'), qr/ 404 /, 'auth open static'); 126 like(http_get('/open-static'), qr/ 404 /, 'auth open static');
119 unlike(http_get('/open-static'), qr/INVISIBLE/, 'auth static no content'); 127 unlike(http_get('/open-static'), qr/INVISIBLE/, 'auth static no content');
120 128
121 like(http_get('/proxy'), qr/ 401 /, 'proxy auth unauthorized'); 129 like(http_get('/proxy'), qr/ 401 /, 'proxy auth unauthorized');
122 like(http_get('/proxy'), qr/WWW-Authenticate: Basic realm="restricted"/, 130 like(http_get('/proxy'), qr/WWW-Authenticate: Basic realm="restricted"/,
123 'proxy auth has www-authenticate'); 131 'proxy auth has www-authenticate');
124 like(http_get_auth('/proxy'), qr/ 404 /, 'proxy auth pass'); 132 like(http_get_auth('/proxy'), qr/ 404 /, 'proxy auth pass');
125 unlike(http_get_auth('/proxy'), qr/INVISIBLE/, 'proxy auth no content'); 133 unlike(http_get_auth('/proxy'), qr/INVISIBLE/, 'proxy auth no content');
134
135 like(http_post('/proxy'), qr/ 401 /, 'proxy auth post');
126 136
127 SKIP: { 137 SKIP: {
128 eval { require FCGI; }; 138 eval { require FCGI; };
129 skip 'FCGI not installed', 2 if $@; 139 skip 'FCGI not installed', 2 if $@;
130 140
145 Authorization: Basic dXNlcjpzZWNyZXQ= 155 Authorization: Basic dXNlcjpzZWNyZXQ=
146 156
147 EOF 157 EOF
148 } 158 }
149 159
160 sub http_post {
161 my ($url, %extra) = @_;
162
163 my $p = "POST $url HTTP/1.0" . CRLF .
164 "Host: localhost" . CRLF .
165 "Content-Length: 10" . CRLF .
166 CRLF .
167 "1234567890";
168
169 return http($p, %extra);
170 }
171
150 ############################################################################### 172 ###############################################################################
151 173
152 sub fastcgi_daemon { 174 sub fastcgi_daemon {
153 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); 175 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5);
154 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, 176 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,