comparison auth_request.t @ 323:d48de852157c

Tests: auth_request assorted fixes.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 21 Aug 2013 19:56:00 +0400
parents 67c348ba1768
children 241acee85fd1
comparison
equal deleted inserted replaced
322:67c348ba1768 323:d48de852157c
7 ############################################################################### 7 ###############################################################################
8 8
9 use warnings; 9 use warnings;
10 use strict; 10 use strict;
11 11
12 use Test::More;
13
12 use Socket qw/ CRLF /; 14 use Socket qw/ CRLF /;
13
14 use Test::More;
15 15
16 BEGIN { use FindBin; chdir($FindBin::Bin); } 16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17 17
18 use lib 'lib'; 18 use lib 'lib';
19 use Test::Nginx; 19 use Test::Nginx;
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new() 26 my $t = Test::Nginx->new()
27 ->has(qw/http rewrite proxy fastcgi auth_basic auth_request/) 27 ->has(qw/http rewrite proxy fastcgi auth_basic auth_request/)
28 ->plan(18); 28 ->plan(17);
29 29
30 $t->write_file_expand('nginx.conf', <<'EOF'); 30 $t->write_file_expand('nginx.conf', <<'EOF');
31 31
32 %%TEST_GLOBALS%% 32 %%TEST_GLOBALS%%
33 33
34 master_process off; 34 daemon off;
35 daemon off;
36 35
37 events { 36 events {
38 } 37 }
39 38
40 http { 39 http {
132 $t->write_file('auth-basic', 'INVISIBLE'); 131 $t->write_file('auth-basic', 'INVISIBLE');
133 $t->write_file('auth-open-static', 'INVISIBLE'); 132 $t->write_file('auth-open-static', 'INVISIBLE');
134 $t->run(); 133 $t->run();
135 134
136 ############################################################################### 135 ###############################################################################
137
138 pass('runs');
139 136
140 like(http_get('/open'), qr/ 404 /, 'auth open'); 137 like(http_get('/open'), qr/ 404 /, 'auth open');
141 like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized'); 138 like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized');
142 like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden'); 139 like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden');
143 like(http_get('/error'), qr/ 500 /, 'auth error'); 140 like(http_get('/error'), qr/ 500 /, 'auth error');
185 } 182 }
186 183
187 ############################################################################### 184 ###############################################################################
188 185
189 sub http_get_auth { 186 sub http_get_auth {
190 my ($url, %extra) = @_; 187 my ($url, %extra) = @_;
191 return http(<<EOF, %extra); 188 return http(<<EOF, %extra);
192 GET $url HTTP/1.0 189 GET $url HTTP/1.0
193 Host: localhost 190 Host: localhost
194 Authorization: Basic dXNlcjpzZWNyZXQ= 191 Authorization: Basic dXNlcjpzZWNyZXQ=
195 192
196 EOF 193 EOF
201 198
202 my $p = "POST $url HTTP/1.0" . CRLF . 199 my $p = "POST $url HTTP/1.0" . CRLF .
203 "Host: localhost" . CRLF . 200 "Host: localhost" . CRLF .
204 "Content-Length: 10" . CRLF . 201 "Content-Length: 10" . CRLF .
205 CRLF . 202 CRLF .
206 "1234567890"; 203 "1234567890";
207 204
208 return http($p, %extra); 205 return http($p, %extra);
209 } 206 }
210 207
211 sub http_post_big { 208 sub http_post_big {
213 210
214 my $p = "POST $url HTTP/1.0" . CRLF . 211 my $p = "POST $url HTTP/1.0" . CRLF .
215 "Host: localhost" . CRLF . 212 "Host: localhost" . CRLF .
216 "Content-Length: 10240" . CRLF . 213 "Content-Length: 10240" . CRLF .
217 CRLF . 214 CRLF .
218 ("1234567890" x 1024); 215 ("1234567890" x 1024);
219 216
220 return http($p, %extra); 217 return http($p, %extra);
221 } 218 }
222 219
223 ############################################################################### 220 ###############################################################################