File: bug.t

package info (click to toggle)
libnginx-mod-http-headers-more-filter 1%3A0.39-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 316 kB
  • sloc: ansic: 2,000; sh: 108; makefile: 3
file content (461 lines) | stat: -rw-r--r-- 9,065 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# vi:filetype=

use Test::Nginx::Socket; # 'no_plan';

repeat_each(2);

plan tests => 62 * repeat_each();

no_diff;

run_tests();

__DATA__

=== TEST 1: set Server
--- config
    #more_set_headers 'Last-Modified: x';
    more_clear_headers 'Last-Modified';
--- request
    GET /index.html
--- response_headers
! Last-Modified
--- response_body_like: It works!



=== TEST 2: variables in the Ranges header
--- config
    location /index.html {
        set $rfrom 1;
        set $rto 3;
        more_set_input_headers 'Range: bytes=$rfrom - $rto';
        #more_set_input_headers 'Range: bytes=1 - 3';
        #echo $http_range;
    }
--- request
GET /index.html
--- error_code: 206
--- response_body chomp
htm



=== TEST 3: mime type overriding (inlined types)
--- config
    more_clear_headers 'X-Powered-By' 'X-Runtime' 'ETag';

    types {
        text/html                             html htm shtml;
        text/css                              css;
    }
--- user_files
>>> a.css
hello
--- request
GET /a.css
--- error_code: 200
--- response_headers
Content-Type: text/css
--- response_body
hello



=== TEST 4: mime type overriding (included types file)
--- config
    more_clear_headers 'X-Powered-By' 'X-Runtime' 'ETag';
    include mime.types;
--- user_files
>>> a.css
hello
>>> ../conf/mime.types
types {
    text/html                             html htm shtml;
    text/css                              css;
}
--- request
GET /a.css
--- error_code: 200
--- response_headers
Content-Type: text/css
--- response_body
hello



=== TEST 5: empty variable as the header value
--- config
    location /foo {
        more_set_headers 'X-Foo: $arg_foo';
        echo hi;
    }
--- request
    GET /foo
--- response_headers
! X-Foo
--- response_body
hi



=== TEST 6: range bug
--- config
    location /index.html {
        more_clear_input_headers "Range*" ;
        more_clear_input_headers "Content-Range*" ;

        more_set_input_headers 'Range: bytes=1-5';
        more_set_headers  'Content-Range: bytes 1-5/1000';
    }
--- request
    GET /index.html
--- more_headers
Range: bytes=1-3
--- raw_response_headers_like: Content-Range: bytes 1-5/1000$
--- response_body chop
html>
--- error_code: 206
--- SKIP



=== TEST 7: Allow-Ranges
--- config
    location /index.html {
        more_clear_headers 'Accept-Ranges';
    }
--- request
    GET /index.html
--- response_headers
! Accept-Ranges
--- response_body_like: It works



=== TEST 8: clear hand-written Allow-Ranges headers
--- config
    location /index.html {
        more_set_headers 'Accept-Ranges: bytes';
        more_clear_headers 'Accept-Ranges';
    }
--- request
    GET /index.html
--- response_headers
! Accept-Ranges
--- response_body_like: It works



=== TEST 9: clear first, then add
--- config
    location /bug {
        more_clear_headers 'Foo';
        more_set_headers 'Foo: a';
        echo hello;
    }
--- request
    GET /bug
--- raw_response_headers_like eval
".*Foo: a.*"
--- response_body
hello



=== TEST 10: first add, then clear, then add again
--- config
    location /bug {
        more_set_headers 'Foo: a';
        more_clear_headers 'Foo';
        more_set_headers 'Foo: b';
        echo hello;
    }
--- request
    GET /bug
--- raw_response_headers_like eval
".*Foo: b.*"
--- response_body
hello



=== TEST 11: override charset
--- config
    location /foo {
        charset iso-8859-1;
        default_type "text/html";
        echo hiya;
    }

    location /bug {
        more_set_headers "Content-Type: text/html; charset=UTF-8";
        proxy_pass http://127.0.0.1:$server_port/foo;
    }
--- request
    GET /bug
--- response_body
hiya
--- response_headers
Content-Type: text/html; charset=UTF-8



=== TEST 12: set multi-value header to a single value
--- config
    location /main {
        set $footer '';
        proxy_pass http://127.0.0.1:$server_port/foo;
        more_set_headers 'Foo: b';
        header_filter_by_lua '
            ngx.var.footer = ngx.header.Foo
        ';
        echo_after_body $footer;
    }
    location /foo {
        echo foo;
        add_header Foo a;
        add_header Foo c;
    }
--- request
    GET /main
--- response_headers
Foo: b
--- response_body
foo
b



=== TEST 13: set multi values to cache-control and override it with multiple values (to reproduce a bug)
--- config
    location /lua {
        content_by_lua '
            ngx.header.cache_control = { "private", "no-store", "foo", "bar", "baz" }
            ngx.send_headers()
            ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
        ';
        more_clear_headers Cache-Control;
        add_header Cache-Control "blah";
    }
--- request
    GET /lua
--- response_headers
Cache-Control: blah
--- response_body
Cache-Control: blah



=== TEST 14: set 20+ headers
--- config
    location /test {
        more_clear_input_headers "Authorization";
        echo $http_a1;
        echo $http_authorization;
        echo $http_a2;
        echo $http_a3;
        echo $http_a23;
        echo $http_a24;
        echo $http_a25;
    }
--- request
    GET /test
--- more_headers eval
my $i = 1;
my $s;
while ($i <= 25) {
    $s .= "A$i: $i\n";
    if ($i == 22) {
        $s .= "Authorization: blah\n";
    }
    $i++;
}
#warn $s;
$s
--- response_body
1

2
3
23
24
25



=== TEST 15: github #20: segfault caused by the nasty optimization in the nginx core (set)
--- config
    location = /t/ {
        more_set_headers "Foo: 1";
        proxy_pass http://127.0.0.1:$server_port;
    }
--- request
GET /t
--- more_headers
Foo: bar
Bah: baz
--- response_body_like: 301 Moved Permanently
--- error_code: 301
--- no_error_log
[error]



=== TEST 16: github #20: segfault caused by the nasty optimization in the nginx core (clear)
--- config
    location = /t/ {
        more_clear_headers Foo;
        proxy_pass http://127.0.0.1:$server_port;
    }
--- request
GET /t
--- more_headers
Foo: bar
Bah: baz
--- response_body_like: 301 Moved Permanently
--- error_code: 301
--- no_error_log
[error]



=== TEST 17: Content-Type response headers with a charset param (correct -t values)
--- config
    location = /t {
        more_set_headers -t 'text/html' 'X-Foo: Bar';
        proxy_pass http://127.0.0.1:$server_port/fake;
    }

    location = /fake {
        default_type text/html;
        charset utf-8;
        echo ok;
    }
--- request
GET /t
--- response_headers
X-Foo: Bar
--- response_body
ok



=== TEST 18: Content-Type response headers with a charset param (WRONG -t values)
--- config
    location = /t {
        more_set_headers -t 'text/html; charset=utf-8' 'X-Foo: Bar';
        proxy_pass http://127.0.0.1:$server_port/fake;
    }

    location = /fake {
        default_type text/html;
        charset utf-8;
        echo ok;
    }
--- request
GET /t
--- response_headers
X-Foo: Bar
--- response_body
ok



=== TEST 19: for bad requests (bad request method letter case)
--- config
    error_page 400 = /err;

    location = /err {
        more_set_input_headers "Foo: bar";
        echo ok;
    }
--- raw_request
GeT / HTTP/1.1
--- response_body
ok
--- no_check_leak



=== TEST 20: for bad requests (bad request method names)
--- config
    error_page 400 = /err;

    location = /err {
        more_set_input_headers "Foo: bar";
        echo ok;
    }
--- raw_request
GET x HTTP/1.1
--- response_body
ok
--- no_check_leak



=== TEST 21: override Cache-Control header sent by proxy module
--- config
    location = /back {
        content_by_lua_block {
            ngx.header['Cache-Control'] = 'max-age=0, no-cache'
            ngx.send_headers()
            ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
        }
    }

    location = /t {
        more_set_headers "Cache-Control: max-age=1800";
        proxy_pass http://127.0.0.1:$server_port/back;
    }
--- request
    GET /t
--- response_headers
Cache-Control: max-age=1800
--- response_body
Cache-Control: max-age=0, no-cache



=== TEST 22: 401 from upstream without WWW-Authenticate header
--- config
    location = /back {
        content_by_lua_block {
            ngx.exit(401)
        }
    }

    location = /t {
        more_set_headers -s "401" 'WWW-Authenticate: Bearer realm="https://my.org/auth"';
        proxy_pass http://127.0.0.1:$server_port/back;
    }
--- request
    GET /t
--- error_code: 401
--- response_headers
WWW-Authenticate: Bearer realm="https://my.org/auth"
--- response_body eval
qr/401 Authorization Required/



=== TEST 22: 401 from upstream with WWW-Authenticate header
--- config
    location = /back {
        more_set_headers -s "401" 'WWW-Authenticate: Bearer realm="https://my.org/auth1"';
        content_by_lua_block {
            ngx.exit(401)
        }
    }

    location = /t {
        more_set_headers -s "401" 'WWW-Authenticate: Bearer realm="https://my.org/auth"';
        proxy_pass http://127.0.0.1:$server_port/back;
    }
--- request
    GET /t
--- error_code: 401
--- response_headers
WWW-Authenticate: Bearer realm="https://my.org/auth"
--- response_body eval
qr/401 Authorization Required/