-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathsanity.t
628 lines (513 loc) · 11.4 KB
/
sanity.t
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(2);
plan tests => repeat_each() * 123;
#master_on();
#workers(2);
log_level("warn");
no_diff;
run_tests();
__DATA__
=== TEST 1: simple set (1 arg)
--- config
location /foo {
echo hi;
more_set_headers 'X-Foo: Blah';
}
--- request
GET /foo
--- response_headers
X-Foo: Blah
--- response_body
hi
=== TEST 2: simple set (2 args)
--- config
location /foo {
echo hi;
more_set_headers 'X-Foo: Blah' 'X-Bar: hi';
}
--- request
GET /foo
--- response_headers
X-Foo: Blah
X-Bar: hi
--- response_body
hi
=== TEST 3: two sets in a single location
--- config
location /two {
echo hi;
more_set_headers 'X-Foo: Blah'
more_set_headers 'X-Bar: hi';
}
--- request
GET /two
--- response_headers
X-Foo: Blah
X-Bar: hi
--- response_body
hi
=== TEST 4: two sets in a single location (for 404 too)
--- config
location /two {
more_set_headers 'X-Foo: Blah'
more_set_headers 'X-Bar: hi';
return 404;
}
--- request
GET /two
--- response_headers
X-Foo: Blah
X-Bar: hi
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 5: set a header then clears it (500)
--- config
location /two {
more_set_headers 'X-Foo: Blah';
more_set_headers 'X-Foo:';
return 500;
}
--- request
GET /two
--- response_headers
! X-Foo
! X-Bar
--- response_body_like: 500 Internal Server Error
--- error_code: 500
=== TEST 6: set a header only when 500 (matched)
--- config
location /bad {
more_set_headers -s 500 'X-Mine: Hiya';
more_set_headers -s 404 'X-Yours: Blah';
return 500;
}
--- request
GET /bad
--- response_headers
X-Mine: Hiya
! X-Yours
--- response_body_like: 500 Internal Server Error
--- error_code: 500
=== TEST 7: set a header only when 500 (not matched with 200)
--- config
location /bad {
more_set_headers -s 500 'X-Mine: Hiya';
more_set_headers -s 404 'X-Yours: Blah';
echo hello;
}
--- request
GET /bad
--- response_headers
! X-Mine
! X-Yours
--- response_body
hello
--- error_code: 200
=== TEST 8: set a header only when 500 (not matched with 404)
--- config
location /bad {
more_set_headers -s 500 'X-Mine: Hiya';
more_set_headers -s 404 'X-Yours: Blah';
return 404;
}
--- request
GET /bad
--- response_headers
! X-Mine
X-Yours: Blah
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 9: more conditions
--- config
location /bad {
more_set_headers -s '503 404' 'X-Mine: Hiya';
more_set_headers -s ' 404 413 ' 'X-Yours: Blah';
return 503;
}
--- request
GET /bad
--- response_headers
X-Mine: Hiya
! X-Yours
--- response_body_like: 503 Service
--- error_code: 503
=== TEST 10: more conditions
--- config
location /bad {
more_set_headers -s '503 404' 'X-Mine: Hiya';
more_set_headers -s ' 404 413 ' 'X-Yours: Blah';
return 404;
}
--- request
GET /bad
--- response_headers
X-Mine: Hiya
X-Yours: Blah
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 11: more conditions
--- config
location /bad {
more_set_headers -s '503 404' 'X-Mine: Hiya';
more_set_headers -s ' 404 413 ' 'X-Yours: Blah';
return 413;
}
--- request
GET /bad
--- response_headers
! X-Mine
X-Yours: Blah
--- response_body_like: 413 Request Entity Too Large
--- error_code: 413
=== TEST 12: simple -t
--- config
location /bad {
default_type 'text/css';
more_set_headers -t 'text/css' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
X-CSS: yes
--- response_body
hi
=== TEST 13: simple -t (not matched)
--- config
location /bad {
default_type 'text/plain';
more_set_headers -t 'text/css' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
! X-CSS
--- response_body
hi
=== TEST 14: multiple -t (not matched)
--- config
location /bad {
default_type 'text/plain';
more_set_headers -t 'text/javascript' -t 'text/css' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
! X-CSS
--- response_body
hi
=== TEST 15: multiple -t (matched)
--- config
location /bad {
default_type 'text/plain';
more_set_headers -t 'text/javascript' -t 'text/plain' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
X-CSS: yes
--- response_body
hi
=== TEST 16: multiple -t (matched)
--- config
location /bad {
default_type 'text/javascript';
more_set_headers -t 'text/javascript' -t 'text/plain' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
X-CSS: yes
--- response_body
hi
=== TEST 17: multiple -t (matched) with extra spaces
--- config
location /bad {
default_type 'text/javascript';
more_set_headers -t ' text/javascript ' -t 'text/plain' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
X-CSS: yes
--- response_body
hi
=== TEST 18: multiple -t merged
--- config
location /bad {
default_type 'text/javascript';
more_set_headers -t ' text/javascript text/plain' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
X-CSS: yes
--- response_body
hi
=== TEST 19: multiple -t merged (2)
--- config
location /bad {
default_type 'text/plain';
more_set_headers -t ' text/javascript text/plain' 'X-CSS: yes';
echo hi;
}
--- request
GET /bad
--- response_headers
X-CSS: yes
--- response_body
hi
=== TEST 20: multiple -s option in a directive (not matched)
--- config
location /bad {
more_set_headers -s 404 -s 500 'X-status: howdy';
echo hi;
}
--- request
GET /bad
--- response_headers
! X-status
--- response_body
hi
=== TEST 21: multiple -s option in a directive (matched 404)
--- config
location /bad {
more_set_headers -s 404 -s 500 'X-status: howdy';
return 404;
}
--- request
GET /bad
--- response_headers
X-status: howdy
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 22: multiple -s option in a directive (matched 500)
--- config
location /bad {
more_set_headers -s 404 -s 500 'X-status: howdy';
return 500;
}
--- request
GET /bad
--- response_headers
X-status: howdy
--- response_body_like: 500 Internal Server Error
--- error_code: 500
=== TEST 23: -s mixed with -t
--- config
location /bad {
default_type 'text/html';
more_set_headers -s 404 -s 200 -t 'text/html' 'X-status: howdy2';
return 404;
}
--- request
GET /bad
--- response_headers
X-status: howdy2
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 24: -s mixed with -t
--- config
location /bad {
default_type 'text/html';
more_set_headers -s 404 -s 200 -t 'text/plain' 'X-status: howdy2';
return 404;
}
--- request
GET /bad
--- response_headers
! X-status
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 25: -s mixed with -t
--- config
location /bad {
default_type 'text/html';
more_set_headers -s 404 -s 200 -t 'text/html' 'X-status: howdy2';
echo hi;
}
--- request
GET /bad
--- response_headers
X-status: howdy2
--- response_body
hi
--- error_code: 200
=== TEST 26: -s mixed with -t
--- config
location /bad {
default_type 'text/html';
more_set_headers -s 500 -s 200 -t 'text/html' 'X-status: howdy2';
return 404;
}
--- request
GET /bad
--- response_headers
! X-status
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 27: merge from the upper level
--- config
more_set_headers -s 404 -t 'text/html' 'X-status2: howdy3';
location /bad {
default_type 'text/html';
more_set_headers -s 500 -s 200 -t 'text/html' 'X-status: howdy2';
return 404;
}
--- request
GET /bad
--- response_headers
X-status2: howdy3
! X-status
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 28: merge from the upper level
--- config
more_set_headers -s 404 -t 'text/html' 'X-status2: howdy3';
location /bad {
default_type 'text/html';
more_set_headers -s 500 -s 200 -t 'text/html' 'X-status: howdy2';
echo yeah;
}
--- request
GET /bad
--- response_headers
! X-status2
X-status: howdy2
--- response_body
yeah
--- error_code: 200
=== TEST 29: override settings by inheritance
--- config
more_set_headers -s 404 -t 'text/html' 'X-status: yeah';
location /bad {
default_type 'text/html';
more_set_headers -s 404 -t 'text/html' 'X-status: nope';
return 404;
}
--- request
GET /bad
--- response_headers
X-status: nope
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 30: append settings by inheritance
--- config
more_set_headers -s 404 -t 'text/html' 'X-status: yeah';
location /bad {
default_type 'text/html';
more_set_headers -s 404 -t 'text/html' 'X-status2: nope';
return 404;
}
--- request
GET /bad
--- response_headers
X-status: yeah
X-status2: nope
--- response_body_like: 404 Not Found
--- error_code: 404
=== TEST 31: clear headers with wildcard
--- config
location = /backend {
add_header X-Hidden-One "i am hidden";
add_header X-Hidden-Two "me 2";
echo hi;
}
location /hello {
more_clear_headers 'X-Hidden-*';
proxy_pass http://127.0.0.1:$server_port/backend;
}
--- request
GET /hello
--- response_headers
! X-Hidden-One
! X-Hidden-Two
--- response_body
hi
=== TEST 32: clear duplicate headers
--- config
location = /backend {
add_header pragma no-cache;
add_header pragma no-cache;
echo hi;
}
location /hello {
more_clear_headers 'pragma';
proxy_pass http://127.0.0.1:$server_port/backend;
}
--- request
GET /hello
--- response_headers
!pragma
--- response_body
hi
=== TEST 33: HTTP 0.9 (set)
--- config
location /foo {
more_set_headers 'X-Foo: howdy';
echo ok;
}
--- raw_request eval
"GET /foo\r\n"
--- response_headers
! X-Foo
--- response_body
ok
--- http09
=== TEST 34: use the -a option to append the cookie field
--- config
location /cookie {
more_set_headers -a 'Set-Cookie: name=lynch';
echo ok;
}
--- request
GET /cookie
--- response_headers
Set-Cookie: name=lynch
--- response_body
ok
=== TEST 35: the original Set-Cookie fields will not be overwritten, when using the -a option
--- config
location /cookie {
more_set_headers 'Set-Cookie: name=lynch';
more_set_headers -a 'Set-Cookie: born=1981';
echo ok;
}
--- request
GET /cookie
--- raw_response_headers_like eval
"Set-Cookie: name=lynch\r\nSet-Cookie: born=1981\r\n"
--- response_body
ok
=== TEST 36: The behavior of builtin headers can not be changed
--- config
location /foo {
more_set_headers -a "Server: myServer";
echo ok;
}
--- request
GET /foo
--- must_die
--- error_log chomp
can not append builtin headers
--- suppress_stderr
=== TEST 37: can not use -a option with more_clear_headers
--- config
location /foo {
more_clear_headers -a 'Content-Type';
echo ok;
}
--- request
GET /foo
--- must_die
--- error_log chomp
invalid option name: "-a"
--- suppress_stderr