Commits

Anonymous committed 35f0ee7

Auth request: fix SIGSEGV on POST.

Comments (0)

Files changed (2)

ngx_http_auth_request_module.c

         return NGX_ERROR;
     }
 
+    sr->discard_body = 1;
     sr->header_only = 1;
 
     ctx->subrequest = sr;
 use warnings;
 use strict;
 
+use Socket qw/ CRLF /;
+
 use Test::More;
 use Test::Nginx;
 
 select STDOUT; $| = 1;
 
 my $t = Test::Nginx->new()->has(qw/http rewrite proxy fastcgi auth_basic/)
-	->plan(14);
+	->plan(17);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
         }
         location = /auth-proxy {
             proxy_pass http://127.0.0.1:8080/auth-basic;
+            proxy_pass_request_body off;
+            proxy_set_header Content-Length "";
         }
         location = /auth-basic {
             auth_basic "restricted";
         }
         location = /auth-fastcgi {
             fastcgi_pass 127.0.0.1:8081;
+            fastcgi_pass_request_body off;
         }
     }
 }
 like(http_get('/error'), qr/ 500 /, 'auth error');
 like(http_get('/off'), qr/ 404 /, 'auth off');
 
+like(http_post('/open'), qr/ 404 /, 'auth post open');
+like(http_post('/unauthorized'), qr/ 401 /, 'auth post unauthorized');
+
 like(http_get('/open-static'), qr/ 404 /, 'auth open static');
 unlike(http_get('/open-static'), qr/INVISIBLE/, 'auth static no content');
 
 like(http_get_auth('/proxy'), qr/ 404 /, 'proxy auth pass');
 unlike(http_get_auth('/proxy'), qr/INVISIBLE/, 'proxy auth no content');
 
+like(http_post('/proxy'), qr/ 401 /, 'proxy auth post');
+
 SKIP: {
 	eval { require FCGI; };
 	skip 'FCGI not installed', 2 if $@;
 EOF
 }
 
+sub http_post {
+	my ($url, %extra) = @_;
+
+	my $p = "POST $url HTTP/1.0" . CRLF .
+		"Host: localhost" . CRLF .
+		"Content-Length: 10" . CRLF .
+		CRLF .
+		"1234567890"; 
+
+	return http($p, %extra);
+}
+
 ###############################################################################
 
 sub fastcgi_daemon {