-
Notifications
You must be signed in to change notification settings - Fork 2k
/
014-bugs.t
692 lines (581 loc) · 13.4 KB
/
014-bugs.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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# vim:set ft= ts=4 sw=4 et fdm=marker:
use lib 'lib';
use Test::Nginx::Socket;
#worker_connections(1014);
#master_on();
log_level('debug');
repeat_each(3);
plan tests => repeat_each() * (blocks() * 2 + 20);
our $HtmlDir = html_dir;
#warn $html_dir;
#no_diff();
#no_long_string();
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
run_tests();
__DATA__
=== TEST 1: sanity
--- http_config eval
"lua_package_path '$::HtmlDir/?.lua;./?.lua';"
--- config
location /load {
content_by_lua '
package.loaded.foo = nil;
local foo = require "foo";
foo.hi()
';
}
--- request
GET /load
--- user_files
>>> foo.lua
module(..., package.seeall);
function foo ()
return 1
return 2
end
--- error_code: 500
--- response_body_like: 500 Internal Server Error
=== TEST 2: sanity
--- http_config
lua_package_path '/home/agentz/rpm/BUILD/lua-yajl-1.1/build/?.so;/home/lz/luax/?.so;./?.so';
--- config
location = '/report/listBidwordPrices4lzExtra.htm' {
content_by_lua '
local yajl = require "yajl"
local w = ngx.var.arg_words
w = ngx.unescape_uri(w)
local r = {}
print("start for")
for id in string.gmatch(w, "%d+") do
r[id] = -1
end
print("end for, start yajl")
ngx.print(yajl.to_string(r))
print("end yajl")
';
}
--- request
GET /report/listBidwordPrices4lzExtra.htm?words=123,156,2532
--- response_body
--- SKIP
=== TEST 3: sanity
--- config
location = /memc {
#set $memc_value 'hello';
set $memc_value $arg_v;
set $memc_cmd $arg_c;
set $memc_key $arg_k;
#set $memc_value hello;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
#echo $memc_value;
}
location = /echo {
echo_location '/memc?c=get&k=foo';
echo_location '/memc?c=set&k=foo&v=hello';
echo_location '/memc?c=get&k=foo';
}
location = /main {
content_by_lua '
res = ngx.location.capture("/memc?c=get&k=foo&v=")
ngx.say("1: ", res.body)
res = ngx.location.capture("/memc?c=set&k=foo&v=bar");
ngx.say("2: ", res.body);
res = ngx.location.capture("/memc?c=get&k=foo")
ngx.say("3: ", res.body);
';
}
--- request
GET /main
--- response_body_like: 3: bar$
=== TEST 4: capture works for subrequests with internal redirects
--- config
location /lua {
content_by_lua '
local res = ngx.location.capture("/")
ngx.say(res.status)
ngx.print(res.body)
';
}
--- request
GET /lua
--- response_body_like chop
200
.*It works
--- SKIP
=== TEST 5: disk file bufs not working
--- config
location /lua {
content_by_lua '
local res = ngx.location.capture("/test.lua")
ngx.say(res.status)
ngx.print(res.body)
';
}
--- user_files
>>> test.lua
print("Hello, world")
--- request
GET /lua
--- response_body
200
print("Hello, world")
=== TEST 6: print lua empty strings
--- config
location /lua {
content_by_lua 'ngx.print("") ngx.flush() ngx.print("Hi")';
}
--- request
GET /lua
--- response_body chop
Hi
=== TEST 7: say lua empty strings
--- config
location /lua {
content_by_lua 'ngx.say("") ngx.flush() ngx.print("Hi")';
}
--- request
GET /lua
--- response_body eval
"
Hi"
=== TEST 8: github issue 37: header bug
https://github.com/chaoslawful/lua-nginx-module/issues/37
--- config
location /sub {
content_by_lua '
ngx.header["Set-Cookie"] = {"TestCookie1=foo", "TestCookie2=bar"};
ngx.say("Hello")
';
}
location /lua {
content_by_lua '
-- local yajl = require "yajl"
ngx.header["Set-Cookie"] = {}
res = ngx.location.capture("/sub")
for i,j in pairs(res.header) do
ngx.header[i] = j
end
-- ngx.say("set-cookie: ", yajl.to_string(res.header["Set-Cookie"]))
ngx.send_headers()
ngx.print("body: ", res.body)
';
}
--- request
GET /lua
--- raw_response_headers_like eval
".*Set-Cookie: TestCookie1=foo\r
Set-Cookie: TestCookie2=bar.*"
=== TEST 9: memory leak
--- config
location /foo {
content_by_lua_file 'html/foo.lua';
}
--- user_files
>>> foo.lua
res = {}
res = {'good 1', 'good 2', 'good 3'}
return ngx.redirect("/somedir/" .. ngx.escape_uri(res[math.random(1,#res)]))
--- request
GET /foo
--- response_body
--- SKIP
=== TEST 10: capturing locations with internal redirects (no lua redirect)
--- config
location /bar {
echo Bar;
}
location /foo {
#content_by_lua '
#ngx.exec("/bar")
#';
echo_exec /bar;
}
location /main {
content_by_lua '
local res = ngx.location.capture("/foo")
ngx.print(res.body)
';
}
--- request
GET /main
--- response_body
Bar
=== TEST 11: capturing locations with internal redirects (lua redirect)
--- config
location /bar {
content_by_lua 'ngx.say("Bar")';
}
location /foo {
content_by_lua '
ngx.exec("/bar")
';
}
location /main {
content_by_lua '
local res = ngx.location.capture("/foo")
ngx.print(res.body)
';
}
--- request
GET /main
--- response_body
Bar
=== TEST 12: capturing locations with internal redirects (simple index)
--- config
location /main {
content_by_lua '
local res = ngx.location.capture("/")
ngx.print(res.body)
';
}
--- request
GET /main
--- response_body chop
<html><head><title>It works!</title></head><body>It works!</body></html>
=== TEST 13: capturing locations with internal redirects (more lua statements)
--- config
location /bar {
content_by_lua '
ngx.say("hello")
ngx.say("world")
';
}
location /foo {
#content_by_lua '
#ngx.exec("/bar")
#';
echo_exec /bar;
}
location /main {
content_by_lua '
local res = ngx.location.capture("/foo")
ngx.print(res.body)
';
}
--- request
GET /main
--- response_body
hello
world
=== TEST 14: capturing locations with internal redirects (post subrequest with internal redirect)
--- config
location /bar {
lua_need_request_body on;
client_body_in_single_buffer on;
content_by_lua '
ngx.say(ngx.var.request_body)
';
}
location /foo {
#content_by_lua '
#ngx.exec("/bar")
#';
echo_exec /bar;
}
location /main {
content_by_lua '
local res = ngx.location.capture("/foo", { method = ngx.HTTP_POST, body = "hello" })
ngx.print(res.body)
';
}
--- request
GET /main
--- response_body
hello
=== TEST 15: nginx rewrite works in subrequests
--- config
rewrite /foo /foo/ permanent;
location = /foo/ {
echo hello;
}
location /main {
content_by_lua '
local res = ngx.location.capture("/foo")
ngx.say("status = ", res.status)
ngx.say("Location: ", res.header["Location"] or "nil")
';
}
--- request
GET /main
--- response_body
status = 301
Location: /foo/
=== TEST 16: nginx rewrite works in subrequests
--- config
access_by_lua '
local res = ngx.location.capture(ngx.var.uri)
ngx.say("status = ", res.status)
ngx.say("Location: ", res.header["Location"] or "nil")
ngx.exit(200)
';
--- request
GET /foo
--- user_files
>>> foo/index.html
It works!
--- response_body
status = 301
Location: /foo/
=== TEST 17: set content-type header with charset
--- config
location /lua {
charset GBK;
content_by_lua '
ngx.header.content_type = "text/xml; charset=UTF-8"
ngx.say("hi")
';
}
--- request
GET /lua
--- response_body
hi
--- response_headers
Content-Type: text/xml; charset=UTF-8
=== TEST 18: set response header content-type with charset
--- config
location /lua {
charset GBK;
content_by_lua '
ngx.header.content_type = "text/xml"
ngx.say("hi")
';
}
--- request
GET /lua
--- response_body
hi
--- response_headers
Content-Type: text/xml; charset=GBK
=== TEST 19: get by-position capturing variables
--- config
location ~ '^/lua/(.*)' {
content_by_lua '
ngx.say(ngx.var[1] or "nil")
';
}
--- request
GET /lua/hello
--- response_body
hello
=== TEST 20: get by-position capturing variables ($0)
--- config
location ~ '^/lua/(.*)' {
content_by_lua '
ngx.say(ngx.var[0] or "nil")
';
}
--- request
GET /lua/hello
--- response_body
nil
=== TEST 21: get by-position capturing variables (exceeding captures)
--- config
location ~ '^/lua/(.*)' {
content_by_lua '
ngx.say(ngx.var[2] or "nil")
';
}
--- request
GET /lua/hello
--- response_body
nil
=== TEST 22: get by-position capturing variables ($1, $2)
--- config
location ~ '^/lua/(.*)/(.*)' {
content_by_lua '
ngx.say(ngx.var[-1] or "nil")
ngx.say(ngx.var[0] or "nil")
ngx.say(ngx.var[1] or "nil")
ngx.say(ngx.var[2] or "nil")
ngx.say(ngx.var[3] or "nil")
ngx.say(ngx.var[4] or "nil")
';
}
--- request
GET /lua/hello/world
--- response_body
nil
nil
hello
world
nil
nil
=== TEST 23: set special variables
--- config
location /main {
#set_unescape_uri $cookie_a "hello";
set $http_a "hello";
content_by_lua '
ngx.say(ngx.var.http_a)
';
}
--- request
GET /main
--- response_body
hello
--- SKIP
=== TEST 24: set special variables
--- config
location /main {
content_by_lua '
dofile(ngx.var.realpath_root .. "/a.lua")
';
}
location /echo {
echo hi;
}
--- request
GET /main
--- user_files
>>> a.lua
ngx.location.capture("/echo")
--- response_body
--- SKIP
=== TEST 25: set 20+ headers
--- config
location /test {
rewrite_by_lua '
ngx.req.clear_header("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 26: unexpected globals sharing by using _G
--- config
location /test {
content_by_lua '
if _G.t then
_G.t = _G.t + 1
else
_G.t = 0
end
ngx.print(t)
';
}
--- pipelined_requests eval
["GET /test", "GET /test", "GET /test"]
--- response_body eval
["0", "0", "0"]
=== TEST 27: unexpected globals sharing by using _G (set_by_lua*)
--- config
location /test {
set_by_lua $a '
if _G.t then
_G.t = _G.t + 1
else
_G.t = 0
end
return t
';
echo -n $a;
}
--- pipelined_requests eval
["GET /test", "GET /test", "GET /test"]
--- response_body eval
["0", "0", "0"]
=== TEST 28: unexpected globals sharing by using _G (log_by_lua*)
--- http_config
lua_shared_dict log_dict 100k;
--- config
location /test {
content_by_lua '
local log_dict = ngx.shared.log_dict
ngx.print(log_dict:get("cnt") or 0)
';
log_by_lua '
local log_dict = ngx.shared.log_dict
if _G.t then
_G.t = _G.t + 1
else
_G.t = 0
end
log_dict:set("cnt", t)
';
}
--- pipelined_requests eval
["GET /test", "GET /test", "GET /test"]
--- response_body eval
["0", "0", "0"]
=== TEST 29: unexpected globals sharing by using _G (header_filter_by_lua*)
--- config
location /test {
header_filter_by_lua '
if _G.t then
_G.t = _G.t + 1
else
_G.t = 0
end
ngx.ctx.cnt = tostring(t)
';
content_by_lua '
ngx.send_headers()
ngx.print(ngx.ctx.cnt or 0)
';
}
--- pipelined_requests eval
["GET /test", "GET /test", "GET /test"]
--- response_body eval
["0", "0", "0"]
=== TEST 30: unexpected globals sharing by using _G (body_filter_by_lua*)
--- config
location /test {
body_filter_by_lua '
if _G.t then
_G.t = _G.t + 1
else
_G.t = 0
end
ngx.ctx.cnt = _G.t
';
content_by_lua '
ngx.print("a")
ngx.say(ngx.ctx.cnt or 0)
';
}
--- request
GET /test
--- response_body
a0
--- no_error_log
[error]
=== TEST 31: set content-type header with charset and default_type
--- http_config
--- config
location /lua {
default_type application/json;
charset utf-8;
charset_types application/json;
content_by_lua 'ngx.say("hi")';
}
--- request
GET /lua
--- response_body
hi
--- response_headers
Content-Type: application/json; charset=utf-8