# HG changeset patch # User Dmitry Volyntsev # Date 1528890823 -10800 # Node ID 2ff483941037ecb3acda8f812a31cf5f2eb93d9d # Parent 5833f3b7a88423c38d0ab3ab2224f39ef9d88617 Tests: added njs http internalRedirect() method tests. diff --git a/auth_request.t b/auth_request.t --- a/auth_request.t +++ b/auth_request.t @@ -57,6 +57,15 @@ http { return 204; } + location /auth_file { + auth_request /file/t; + } + + location /file/ { + alias %%TESTDIR%%/; + } + + location /open-static { auth_request /auth-open-static; } @@ -144,16 +153,19 @@ EOF $t->write_file('htpasswd', 'user:{PLAIN}secret' . "\n"); $t->write_file('auth-basic', 'INVISIBLE'); $t->write_file('auth-open-static', 'INVISIBLE'); +$t->write_file('t', '["SEE-THIS"]'); $t->run(); ############################################################################### +like(http_get('/auth_file'), qr/ 200 /, 'auth file'); like(http_get('/open'), qr/ 404 /, 'auth open'); like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized'); like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden'); 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'); diff --git a/js_internal_redirect.t b/js_internal_redirect.t new file mode 100644 --- /dev/null +++ b/js_internal_redirect.t @@ -0,0 +1,88 @@ +#!/usr/bin/perl + +# (C) Dmitry Volyntsev +# (C) Nginx, Inc. + +# Tests for http njs module, internalRedirect method. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +use Config; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->has(qw/http/) + ->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + js_include test.js; + + server { + listen 127.0.0.1:8080; + server_name localhost; + + location /test { + js_content test_redirect; + } + + location /redirect { + internal; + return 200 redirect$arg_b; + } + + location @named { + return 200 named; + } + } +} + +EOF + +$t->write_file('test.js', <try_run('no njs internalRedirect')->plan(3); + +############################################################################### + +like(http_get('/test'), qr/redirect/s, 'redirect'); +like(http_get('/test?a=A'), qr/redirectA/s, 'redirect with args'); +like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location'); + +###############################################################################