1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
use Test::Nginx::Socket::Lua;
repeat_each(2);
plan tests => repeat_each() * (blocks() * 3);
our $HtmlDir = html_dir;
no_long_string();
run_tests();
__DATA__
=== TEST 1: decoded url contains '\0' and '\r\n'
--- config
server_tokens off;
location = /t {
rewrite_by_lua_block {
ngx.req.read_body();
local args, _ = ngx.req.get_post_args();
ngx.req.set_uri(args["url"], true, true);
}
}
--- request
POST /t
url=%00%0a%0dset-cookie:1234567
--- error_code: 301
--- response_headers
Location: %00%0A%0Dset-cookie:1234567/
--- response_body_like
.*301 Moved Permanently.*
=== TEST 2: uri contain chinese characters
--- config
server_tokens off;
--- user_files
>>> t/中文/foo.txt
Hello, world
--- request
GET /t/中文
--- more_headers
host: localhost
--- error_code: 301
--- response_headers_like
Location: https?:\/\/localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/
--- response_body_like
.*301 Moved Permanently.*
=== TEST 3: uri contain chinese characters with args
--- config
server_tokens off;
--- user_files
>>> t/中文/foo.txt
Hello, world
--- request
GET /t/中文?q=name
--- more_headers
host: localhost
--- error_code: 301
--- response_headers_like
Location: https?:\/\/localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/\?q=name
--- response_body_like
.*301 Moved Permanently.*
=== TEST 4: uri already encoded
--- config
server_tokens off;
--- user_files
>>> t/中文/foo.txt
Hello, world
--- request
GET /t/%E4%B8%AD%E6%96%87
--- more_headers
host: localhost
--- error_code: 301
--- response_headers_like
Location: https?:\/\/localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/
--- response_body_like
.*301 Moved Permanently.*
=== TEST 5: uri already encoded with args
--- config
server_tokens off;
--- user_files
>>> t/中文/foo.txt
Hello, world
--- request
GET /t/%E4%B8%AD%E6%96%87?q=name
--- more_headers
host: localhost
--- error_code: 301
--- response_headers_like
Location: https?://localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/\?q=name
--- response_body_like
.*301 Moved Permanently.*
|