Mercurial > hg > nginx-tests
changeset 1343:2ff483941037
Tests: added njs http internalRedirect() method tests.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Wed, 13 Jun 2018 14:53:43 +0300 |
parents | 5833f3b7a884 |
children | 856ab7671404 |
files | auth_request.t js_internal_redirect.t |
diffstat | 2 files changed, 100 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/auth_request.t Wed Jun 13 13:57:38 2018 +0300 +++ b/auth_request.t Wed Jun 13 14:53:43 2018 +0300 @@ -57,6 +57,15 @@ 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 @@ $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');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/js_internal_redirect.t Wed Jun 13 14:53:43 2018 +0300 @@ -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', <<EOF); + function test_redirect(req, res) { + if (req.variables.arg_dest.startsWith('named')) { + req.internalRedirect('\@named'); + + } else { + if (req.variables.arg_a) { + req.internalRedirect('/redirect?b=' + req.variables.arg_a); + + } else { + req.internalRedirect('/redirect'); + } + } + } + +EOF + +$t->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'); + +###############################################################################