~ubuntu-branches/ubuntu/quantal/nginx/quantal-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/014-bugs.t

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Kartik Mistry
  • Date: 2011-09-26 10:17:04 UTC
  • mfrom: (4.2.38 sid)
  • Revision ID: package-import@ubuntu.com-20110926101704-x8pxngiujrmkxnn3
Tags: 1.1.4-2
[Kartik Mistry]
* debian/modules:
  + Updated nginx-upload-progress module, Thanks to upstream for fixing issue
    that FTBFS nginx on kFreeBSD-* archs.
  + Updated nginx-lua module to latest upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#repeat_each(120);
11
11
#repeat_each(3);
12
12
 
13
 
plan tests => blocks() * repeat_each() * 2;
 
13
plan tests => repeat_each() * (blocks() * 2 + 2);
14
14
 
15
15
our $HtmlDir = html_dir;
16
16
#warn $html_dir;
17
17
 
18
 
#$ENV{LUA_PATH} = "$html_dir/?.lua";
 
18
$ENV{LUA_CPATH} = "/home/lz/luax/?.so;;";
19
19
 
20
20
#no_diff();
21
21
#no_long_string();
79
79
 
80
80
 
81
81
=== TEST 3: sanity
82
 
I dunno why this test is not passing. TODO'ing...
83
82
--- config
84
83
    location = /memc {
85
84
        #set $memc_value 'hello';
111
110
--- request
112
111
GET /main
113
112
--- response_body_like: 3: bar$
114
 
--- SKIP
115
113
 
116
114
 
117
115
 
176
174
"
177
175
Hi"
178
176
 
 
177
 
 
178
 
 
179
=== TEST 8: github issue 37: header bug
 
180
https://github.com/chaoslawful/lua-nginx-module/issues/37
 
181
--- config
 
182
    location /sub {
 
183
        content_by_lua '
 
184
            ngx.header["Set-Cookie"] = {"TestCookie1=foo", "TestCookie2=bar"};
 
185
            ngx.say("Hello")
 
186
        ';
 
187
    }
 
188
    location /lua {
 
189
        content_by_lua '
 
190
            -- local yajl = require "yajl"
 
191
            ngx.header["Set-Cookie"] = {}
 
192
            res = ngx.location.capture("/sub")
 
193
 
 
194
            for i,j in pairs(res.header) do
 
195
                ngx.header[i] = j
 
196
            end
 
197
 
 
198
            -- ngx.say("set-cookie: ", yajl.to_string(res.header["Set-Cookie"]))
 
199
 
 
200
            ngx.send_headers()
 
201
            ngx.print("body: ", res.body)
 
202
        ';
 
203
    }
 
204
--- request
 
205
GET /lua
 
206
--- raw_response_headers_like eval
 
207
".*Set-Cookie: TestCookie1=foo\r
 
208
Set-Cookie: TestCookie2=bar.*"
 
209
 
 
210
 
 
211
 
 
212
=== TEST 9: memory leak
 
213
--- config
 
214
    location /foo {
 
215
        content_by_lua_file 'html/foo.lua';
 
216
    }
 
217
--- user_files
 
218
>>> foo.lua
 
219
res = {}
 
220
res = {'good 1', 'good 2', 'good 3'}
 
221
return ngx.redirect("/somedir/" .. ngx.escape_uri(res[math.random(1,#res)]))
 
222
--- request
 
223
    GET /foo
 
224
--- response_body
 
225
--- SKIP
 
226
 
 
227
 
 
228
 
 
229
=== TEST 10: capturing locations with internal redirects (no lua redirect)
 
230
--- config
 
231
    location /bar {
 
232
        echo Bar;
 
233
    }
 
234
    location /foo {
 
235
        #content_by_lua '
 
236
        #ngx.exec("/bar")
 
237
        #';
 
238
        echo_exec /bar;
 
239
    }
 
240
    location /main {
 
241
        content_by_lua '
 
242
            local res = ngx.location.capture("/foo")
 
243
            ngx.print(res.body)
 
244
        ';
 
245
    }
 
246
--- request
 
247
    GET /main
 
248
--- response_body
 
249
Bar
 
250
 
 
251
 
 
252
 
 
253
=== TEST 11: capturing locations with internal redirects (lua redirect)
 
254
--- config
 
255
    location /bar {
 
256
        content_by_lua 'ngx.say("Bar")';
 
257
    }
 
258
    location /foo {
 
259
        content_by_lua '
 
260
            ngx.exec("/bar")
 
261
        ';
 
262
    }
 
263
    location /main {
 
264
        content_by_lua '
 
265
            local res = ngx.location.capture("/foo")
 
266
            ngx.print(res.body)
 
267
        ';
 
268
    }
 
269
--- request
 
270
    GET /main
 
271
--- response_body
 
272
Bar
 
273
 
 
274
 
 
275
 
 
276
=== TEST 12: capturing locations with internal redirects (simple index)
 
277
--- config
 
278
    location /main {
 
279
        content_by_lua '
 
280
            local res = ngx.location.capture("/")
 
281
            ngx.print(res.body)
 
282
        ';
 
283
    }
 
284
--- request
 
285
    GET /main
 
286
--- response_body chop
 
287
<html><head><title>It works!</title></head><body>It works!</body></html>
 
288
 
 
289
 
 
290
 
 
291
=== TEST 13: capturing locations with internal redirects (more lua statements)
 
292
--- config
 
293
    location /bar {
 
294
        content_by_lua '
 
295
            ngx.say("hello")
 
296
            ngx.say("world")
 
297
        ';
 
298
    }
 
299
    location /foo {
 
300
        #content_by_lua '
 
301
        #ngx.exec("/bar")
 
302
        #';
 
303
        echo_exec /bar;
 
304
    }
 
305
    location /main {
 
306
        content_by_lua '
 
307
            local res = ngx.location.capture("/foo")
 
308
            ngx.print(res.body)
 
309
        ';
 
310
    }
 
311
--- request
 
312
    GET /main
 
313
--- response_body
 
314
hello
 
315
world
 
316
 
 
317
 
 
318
 
 
319
=== TEST 14: capturing locations with internal redirects (post subrequest with internal redirect)
 
320
--- config
 
321
    location /bar {
 
322
        lua_need_request_body on;
 
323
        client_body_in_single_buffer on;
 
324
 
 
325
        content_by_lua '
 
326
            ngx.say(ngx.var.request_body)
 
327
        ';
 
328
    }
 
329
    location /foo {
 
330
        #content_by_lua '
 
331
        #ngx.exec("/bar")
 
332
        #';
 
333
        echo_exec /bar;
 
334
    }
 
335
    location /main {
 
336
        content_by_lua '
 
337
            local res = ngx.location.capture("/foo", { method = ngx.HTTP_POST, body = "hello" })
 
338
            ngx.print(res.body)
 
339
        ';
 
340
    }
 
341
--- request
 
342
    GET /main
 
343
--- response_body
 
344
hello
 
345
 
 
346
 
 
347
 
 
348
=== TEST 15: nginx rewrite works in subrequests
 
349
--- config
 
350
    rewrite /foo /foo/ permanent;
 
351
    location = /foo/ {
 
352
        echo hello;
 
353
    }
 
354
    location /main {
 
355
        content_by_lua '
 
356
            local res = ngx.location.capture("/foo")
 
357
            ngx.say("status = ", res.status)
 
358
            ngx.say("Location: ", res.header["Location"] or "nil")
 
359
        ';
 
360
    }
 
361
--- request
 
362
    GET /main
 
363
--- response_body
 
364
status = 301
 
365
Location: /foo/
 
366
 
 
367
 
 
368
 
 
369
=== TEST 16: nginx rewrite works in subrequests
 
370
--- config
 
371
    access_by_lua '
 
372
        local res = ngx.location.capture(ngx.var.uri)
 
373
        ngx.say("status = ", res.status)
 
374
        ngx.say("Location: ", res.header["Location"] or "nil")
 
375
        ngx.exit(200)
 
376
    ';
 
377
--- request
 
378
    GET /foo
 
379
--- user_files
 
380
>>> foo/index.html
 
381
It works!
 
382
--- response_body
 
383
status = 301
 
384
Location: /foo/
 
385
 
 
386
 
 
387
 
 
388
=== TEST 17: set content-type header with charset
 
389
--- config
 
390
    location /lua {
 
391
        charset GBK;
 
392
        content_by_lua '
 
393
            ngx.header.content_type = "text/xml; charset=UTF-8"
 
394
            ngx.say("hi")
 
395
        ';
 
396
    }
 
397
--- request
 
398
    GET /lua
 
399
--- response_body
 
400
hi
 
401
--- response_headers
 
402
Content-Type: text/xml; charset=UTF-8
 
403
 
 
404
 
 
405
 
 
406
=== TEST 18: set response header content-type with charset
 
407
--- config
 
408
    location /lua {
 
409
        charset GBK;
 
410
        content_by_lua '
 
411
            ngx.header.content_type = "text/xml"
 
412
            ngx.say("hi")
 
413
        ';
 
414
    }
 
415
--- request
 
416
    GET /lua
 
417
--- response_body
 
418
hi
 
419
--- response_headers
 
420
Content-Type: text/xml; charset=GBK
 
421
 
 
422
 
 
423
 
 
424
=== TEST 19: get by-position capturing variables
 
425
--- config
 
426
    location ~ '^/lua/(.*)' {
 
427
        content_by_lua '
 
428
            ngx.say(ngx.var[1] or "nil")
 
429
        ';
 
430
    }
 
431
--- request
 
432
    GET /lua/hello
 
433
--- response_body
 
434
hello
 
435
 
 
436
 
 
437
 
 
438
=== TEST 20: get by-position capturing variables ($0)
 
439
--- config
 
440
    location ~ '^/lua/(.*)' {
 
441
        content_by_lua '
 
442
            ngx.say(ngx.var[0] or "nil")
 
443
        ';
 
444
    }
 
445
--- request
 
446
    GET /lua/hello
 
447
--- response_body
 
448
nil
 
449
 
 
450
 
 
451
 
 
452
=== TEST 21: get by-position capturing variables (exceeding captures)
 
453
--- config
 
454
    location ~ '^/lua/(.*)' {
 
455
        content_by_lua '
 
456
            ngx.say(ngx.var[2] or "nil")
 
457
        ';
 
458
    }
 
459
--- request
 
460
    GET /lua/hello
 
461
--- response_body
 
462
nil
 
463
 
 
464
 
 
465
 
 
466
=== TEST 22: get by-position capturing variables ($1, $2)
 
467
--- config
 
468
    location ~ '^/lua/(.*)/(.*)' {
 
469
        content_by_lua '
 
470
            ngx.say(ngx.var[-1] or "nil")
 
471
            ngx.say(ngx.var[0] or "nil")
 
472
            ngx.say(ngx.var[1] or "nil")
 
473
            ngx.say(ngx.var[2] or "nil")
 
474
            ngx.say(ngx.var[3] or "nil")
 
475
            ngx.say(ngx.var[4] or "nil")
 
476
        ';
 
477
    }
 
478
--- request
 
479
    GET /lua/hello/world
 
480
--- response_body
 
481
nil
 
482
nil
 
483
hello
 
484
world
 
485
nil
 
486
nil
 
487