Mercurial > hg > nginx-tests
annotate http_absolute_redirect.t @ 1240:f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
When the testing script is run in verbose mode by prove that redirects stdout,
a garbled verbose mode line from backend can be produced that incorporates TAP
output of an individual test result, which eventually breaks the testing plan.
Notably, this happens when testing sending multiple frames if backend started
to respond before all frames were received. This is possible due to the line
boundary used as an indicator of last bytes to receive before starting to send.
The fix is to amend the only last frame of many specially, for that purpose.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Nov 2017 20:16:09 +0300 |
parents | 2c120aea4362 |
children | 766bcbb632ee |
rev | line source |
---|---|
1103
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for absolute_redirect directive. |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/) |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 absolute_redirect off; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 listen 127.0.0.1:8080; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server_name on; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 absolute_redirect on; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 location / { } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /auto/ { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_pass http://127.0.0.1:8080; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 location /return301 { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 return 301 /redirect; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
1150
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
55 |
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
56 location /i/ { |
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
57 alias %%TESTDIR%%/; |
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
58 } |
1103
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 listen 127.0.0.1:8080; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 server_name off; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 location / { } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 location /auto/ { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_pass http://127.0.0.1:8080; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location /return301 { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 return 301 /redirect; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
1150
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
74 |
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
75 location /i/ { |
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
76 alias %%TESTDIR%%/; |
ccf134a800ae
Tests: added Location tests with alias for dav and static modules.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1103
diff
changeset
|
77 } |
1103
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 EOF |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 mkdir($t->testdir() . '/dir'); |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
1154
2c120aea4362
Tests: added auto redirect tests with args.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1153
diff
changeset
|
85 $t->try_run('no absolute_redirect')->plan(10); |
1103
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 ############################################################################### |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 my $p = port(8080); |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
1153
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
91 like(get('on', '/dir'), qr!Location: http://on:$p/dir/\x0d?$!m, 'directory'); |
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
92 like(get('on', '/i/dir'), qr!Location: http://on:$p/i/dir/\x0d?$!m, |
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
93 'directory alias'); |
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
94 like(get('on', '/auto'), qr!Location: http://on:$p/auto/\x0d?$!m, 'auto'); |
1154
2c120aea4362
Tests: added auto redirect tests with args.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1153
diff
changeset
|
95 like(get('on', '/auto?a=b'), qr!Location: http://on:$p/auto/\?a=b\x0d?$!m, |
2c120aea4362
Tests: added auto redirect tests with args.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1153
diff
changeset
|
96 'auto args'); |
1153
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
97 like(get('on', '/return301'), qr!Location: http://on:$p/redirect\x0d?$!m, |
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
98 'return'); |
1103
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
1153
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
100 like(get('off', '/dir'), qr!Location: /dir/\x0d?$!m, 'off directory'); |
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
101 like(get('off', '/i/dir'), qr!Location: /i/dir/\x0d?$!m, 'off directory alias'); |
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
102 like(get('off', '/auto'), qr!Location: /auto/\x0d?$!m, 'off auto'); |
1154
2c120aea4362
Tests: added auto redirect tests with args.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1153
diff
changeset
|
103 like(get('off', '/auto?a=b'), qr!Location: /auto/\?a=b\x0d?$!m, |
2c120aea4362
Tests: added auto redirect tests with args.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1153
diff
changeset
|
104 'off auto args'); |
1153
818fbc9d1c29
Tests: check Location EoLs in http_absolute_redirect.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1150
diff
changeset
|
105 like(get('off', '/return301'), qr!Location: /redirect\x0d?$!m, 'off return'); |
1103
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 ############################################################################### |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 sub get { |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 my ($host, $uri) = @_; |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 http(<<EOF); |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 GET $uri HTTP/1.0 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 Host: $host |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 EOF |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 } |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
71bba21ea3ed
Tests: absolute_redirect and related tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 ############################################################################### |