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

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/024-access/subrequest.t

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2011-04-16 13:47:58 UTC
  • mfrom: (4.2.31 sid)
  • Revision ID: james.westby@ubuntu.com-20110416134758-yqca2qp5crh2hw2f
Tags: 1.0.0-2
* debian/rules:
  + Removed --with-file-aio support. Fixed FTBFS on kFreeBSD-* arch
    (Closes: #621882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim:set ft= ts=4 sw=4 et fdm=marker:
 
2
use lib 'lib';
 
3
use Test::Nginx::Socket;
 
4
 
 
5
#worker_connections(1014);
 
6
#master_process_enabled(1);
 
7
#log_level('warn');
 
8
 
 
9
#repeat_each(2);
 
10
#repeat_each(1);
 
11
 
 
12
plan tests => repeat_each() * (blocks() * 2);
 
13
 
 
14
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
 
15
 
 
16
#no_diff();
 
17
#no_long_string();
 
18
run_tests();
 
19
 
 
20
__DATA__
 
21
 
 
22
=== TEST 1: DELETE
 
23
--- config
 
24
    location /other {
 
25
        default_type 'foo/bar';
 
26
        echo $echo_request_method;
 
27
    }
 
28
 
 
29
    location /lua {
 
30
        access_by_lua '
 
31
            res = ngx.location.capture("/other",
 
32
                { method = ngx.HTTP_DELETE });
 
33
 
 
34
            ngx.print(res.body)
 
35
        ';
 
36
        content_by_lua 'ngx.exit(ngx.OK)';
 
37
    }
 
38
--- request
 
39
GET /lua
 
40
--- response_body
 
41
DELETE
 
42
 
 
43
 
 
44
 
 
45
=== TEST 2: DELETE (proxy method)
 
46
--- config
 
47
    location /other {
 
48
        default_type 'foo/bar';
 
49
        echo $echo_request_method;
 
50
    }
 
51
 
 
52
    location /foo {
 
53
        proxy_pass http://127.0.0.1:$server_port/other;
 
54
    }
 
55
 
 
56
    location /lua {
 
57
        access_by_lua '
 
58
            res = ngx.location.capture("/foo",
 
59
                { method = ngx.HTTP_DELETE });
 
60
 
 
61
            ngx.print(res.body)
 
62
        ';
 
63
 
 
64
        content_by_lua 'ngx.exit(ngx.OK)';
 
65
    }
 
66
--- request
 
67
GET /lua
 
68
--- response_body
 
69
DELETE
 
70
 
 
71
 
 
72
 
 
73
=== TEST 3: POST (nobody, proxy method)
 
74
--- config
 
75
    location /other {
 
76
        default_type 'foo/bar';
 
77
        echo $echo_request_method;
 
78
    }
 
79
 
 
80
    location /foo {
 
81
        proxy_pass http://127.0.0.1:$server_port/other;
 
82
    }
 
83
 
 
84
    location /lua {
 
85
        access_by_lua '
 
86
            res = ngx.location.capture("/foo",
 
87
                { method = ngx.HTTP_POST });
 
88
 
 
89
            ngx.print(res.body)
 
90
        ';
 
91
        content_by_lua 'ngx.exit(ngx.OK)';
 
92
    }
 
93
--- request
 
94
GET /lua
 
95
--- response_body
 
96
POST
 
97
 
 
98
 
 
99
 
 
100
=== TEST 4: HEAD
 
101
--- config
 
102
    location /other {
 
103
        default_type 'foo/bar';
 
104
        echo $echo_request_method;
 
105
    }
 
106
 
 
107
    location /lua {
 
108
        access_by_lua '
 
109
            res = ngx.location.capture("/other",
 
110
                { method = ngx.HTTP_HEAD });
 
111
 
 
112
            ngx.print(res.body)
 
113
        ';
 
114
        content_by_lua 'ngx.exit(ngx.OK)';
 
115
    }
 
116
--- request
 
117
GET /lua
 
118
--- response_body
 
119
HEAD
 
120
 
 
121
 
 
122
 
 
123
=== TEST 5: explicit GET
 
124
--- config
 
125
    location /other {
 
126
        default_type 'foo/bar';
 
127
        echo $echo_request_method;
 
128
    }
 
129
 
 
130
    location /foo {
 
131
        proxy_pass http://127.0.0.1:$server_port/other;
 
132
    }
 
133
 
 
134
    location /lua {
 
135
        access_by_lua '
 
136
            res = ngx.location.capture("/foo",
 
137
                { method = ngx.HTTP_GET });
 
138
 
 
139
            ngx.print(res.body)
 
140
        ';
 
141
        content_by_lua 'ngx.exit(ngx.OK)';
 
142
    }
 
143
--- request
 
144
GET /lua
 
145
--- response_body
 
146
GET
 
147
 
 
148
 
 
149
 
 
150
=== TEST 6: implicit GET
 
151
--- config
 
152
    location /other {
 
153
        default_type 'foo/bar';
 
154
        echo $echo_request_method;
 
155
    }
 
156
 
 
157
    location /foo {
 
158
        proxy_pass http://127.0.0.1:$server_port/other;
 
159
    }
 
160
 
 
161
    location /lua {
 
162
        access_by_lua '
 
163
            res = ngx.location.capture("/foo")
 
164
 
 
165
            ngx.print(res.body)
 
166
        ';
 
167
        content_by_lua 'ngx.exit(ngx.OK)';
 
168
    }
 
169
--- request
 
170
GET /lua
 
171
--- response_body
 
172
GET
 
173
 
 
174
 
 
175
 
 
176
=== TEST 7: implicit GET (empty option table)
 
177
--- config
 
178
    location /other {
 
179
        default_type 'foo/bar';
 
180
        echo $echo_request_method;
 
181
    }
 
182
 
 
183
    location /foo {
 
184
        proxy_pass http://127.0.0.1:$server_port/other;
 
185
    }
 
186
 
 
187
    location /lua {
 
188
        access_by_lua '
 
189
            res = ngx.location.capture("/foo", {})
 
190
 
 
191
            ngx.print(res.body)
 
192
        ';
 
193
        content_by_lua 'ngx.exit(ngx.OK)';
 
194
    }
 
195
--- request
 
196
GET /lua
 
197
--- response_body
 
198
GET
 
199
 
 
200
 
 
201
 
 
202
=== TEST 8: PUT (nobody, proxy method)
 
203
--- config
 
204
    location /other {
 
205
        default_type 'foo/bar';
 
206
        echo_read_request_body;
 
207
 
 
208
        echo $echo_request_method;
 
209
        echo_request_body;
 
210
    }
 
211
 
 
212
    location /foo {
 
213
        proxy_pass http://127.0.0.1:$server_port/other;
 
214
    }
 
215
 
 
216
    location /lua {
 
217
        access_by_lua '
 
218
            res = ngx.location.capture("/foo",
 
219
                { method = ngx.HTTP_PUT, body = "hello" });
 
220
 
 
221
            ngx.print(res.body)
 
222
        ';
 
223
        content_by_lua 'ngx.exit(ngx.OK)';
 
224
    }
 
225
--- request
 
226
GET /lua
 
227
--- response_body chomp
 
228
PUT
 
229
hello
 
230
 
 
231
 
 
232
 
 
233
=== TEST 9: PUT (nobody, no proxy method)
 
234
--- config
 
235
    location /other {
 
236
        default_type 'foo/bar';
 
237
        #echo_read_request_body;
 
238
 
 
239
        echo $echo_request_method;
 
240
        #echo $echo_request_body;
 
241
        echo_request_body;
 
242
    }
 
243
 
 
244
    location /lua {
 
245
        access_by_lua '
 
246
            res = ngx.location.capture("/other",
 
247
                { method = ngx.HTTP_PUT, body = "hello" });
 
248
 
 
249
            ngx.print(res.body)
 
250
        ';
 
251
        content_by_lua 'ngx.exit(ngx.OK)';
 
252
    }
 
253
--- request
 
254
GET /lua
 
255
--- response_body chomp
 
256
PUT
 
257
hello
 
258
 
 
259
 
 
260
 
 
261
=== TEST 10: PUT (nobody, no proxy method)
 
262
--- config
 
263
    location /other {
 
264
        default_type 'foo/bar';
 
265
        #echo_read_request_body;
 
266
 
 
267
        echo $echo_request_method;
 
268
        #echo $echo_request_body;
 
269
        echo_request_body;
 
270
        #echo "[$http_content_length]";
 
271
        echo;
 
272
    }
 
273
 
 
274
    location /foo {
 
275
        echo $echo_request_method;
 
276
        echo -n "[$http_content_length]";
 
277
    }
 
278
 
 
279
    location /lua {
 
280
        access_by_lua '
 
281
            res = ngx.location.capture("/other",
 
282
                { method = ngx.HTTP_PUT, body = "hello" });
 
283
 
 
284
            ngx.print(res.body)
 
285
 
 
286
            res = ngx.location.capture("/foo")
 
287
            ngx.say(res.body)
 
288
 
 
289
        ';
 
290
        content_by_lua 'ngx.exit(ngx.OK)';
 
291
    }
 
292
--- request
 
293
GET /lua
 
294
--- response_body
 
295
PUT
 
296
hello
 
297
GET
 
298
[]
 
299
 
 
300
 
 
301
 
 
302
=== TEST 11: POST (with body, proxy method)
 
303
--- config
 
304
    location /other {
 
305
        default_type 'foo/bar';
 
306
        echo_read_request_body;
 
307
 
 
308
        echo $echo_request_method;
 
309
        echo_request_body;
 
310
    }
 
311
 
 
312
    location /foo {
 
313
        proxy_pass http://127.0.0.1:$server_port/other;
 
314
    }
 
315
 
 
316
    location /lua {
 
317
        access_by_lua '
 
318
            res = ngx.location.capture("/foo",
 
319
                { method = ngx.HTTP_POST, body = "hello" });
 
320
 
 
321
            ngx.print(res.body)
 
322
        ';
 
323
        content_by_lua 'ngx.exit(ngx.OK)';
 
324
    }
 
325
--- request
 
326
GET /lua
 
327
--- response_body chomp
 
328
POST
 
329
hello
 
330
 
 
331
 
 
332
 
 
333
=== TEST 12: POST (with body, memc method)
 
334
--- config
 
335
    location /flush {
 
336
        set $memc_cmd flush_all;
 
337
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
 
338
    }
 
339
 
 
340
    location /memc {
 
341
        set $memc_key $echo_request_uri;
 
342
        set $memc_exptime 600;
 
343
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
 
344
    }
 
345
 
 
346
    location /lua {
 
347
        access_by_lua '
 
348
            ngx.location.capture("/flush");
 
349
 
 
350
            res = ngx.location.capture("/memc");
 
351
            ngx.say("GET: " .. res.status);
 
352
 
 
353
            res = ngx.location.capture("/memc",
 
354
                { method = ngx.HTTP_PUT, body = "hello" });
 
355
            ngx.say("PUT: " .. res.status);
 
356
 
 
357
            res = ngx.location.capture("/memc");
 
358
            ngx.say("cached: " .. res.body);
 
359
 
 
360
        ';
 
361
        content_by_lua 'ngx.exit(ngx.OK)';
 
362
    }
 
363
--- request
 
364
GET /lua
 
365
--- response_body
 
366
GET: 404
 
367
PUT: 201
 
368
cached: hello
 
369
 
 
370
 
 
371
 
 
372
=== TEST 13: POST (with body, memc method)
 
373
--- config
 
374
    location /flush {
 
375
        set $memc_cmd flush_all;
 
376
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
 
377
    }
 
378
 
 
379
    location /memc {
 
380
        set $memc_cmd "";
 
381
        set $memc_key $echo_request_uri;
 
382
        set $memc_exptime 600;
 
383
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
 
384
    }
 
385
 
 
386
    location /lua {
 
387
        access_by_lua '
 
388
            ngx.location.capture("/flush",
 
389
                { share_all_vars = true });
 
390
 
 
391
            res = ngx.location.capture("/memc",
 
392
                { share_all_vars = true });
 
393
            ngx.say("GET: " .. res.status);
 
394
 
 
395
            res = ngx.location.capture("/memc",
 
396
                { method = ngx.HTTP_PUT, body = "hello", share_all_vars = true });
 
397
            ngx.say("PUT: " .. res.status);
 
398
 
 
399
            res = ngx.location.capture("/memc", { share_all_vars = true });
 
400
            ngx.say("cached: " .. res.body);
 
401
 
 
402
        ';
 
403
        content_by_lua 'ngx.exit(ngx.OK)';
 
404
    }
 
405
--- request
 
406
GET /lua
 
407
--- response_body
 
408
GET: 404
 
409
PUT: 201
 
410
cached: hello
 
411
 
 
412
 
 
413
 
 
414
=== TEST 14: emtpy args option table
 
415
--- config
 
416
    location /foo {
 
417
        echo $query_string;
 
418
    }
 
419
 
 
420
    location /lua {
 
421
        access_by_lua '
 
422
            res = ngx.location.capture("/foo",
 
423
                { args = {} })
 
424
            ngx.print(res.body)
 
425
        ';
 
426
        content_by_lua 'ngx.exit(ngx.OK)';
 
427
    }
 
428
--- request
 
429
GET /lua
 
430
--- response_body eval: "\n"
 
431
 
 
432
 
 
433
 
 
434
=== TEST 15: non-empty args option table (1 pair)
 
435
--- config
 
436
    location /foo {
 
437
        echo $query_string;
 
438
    }
 
439
 
 
440
    location /lua {
 
441
        access_by_lua '
 
442
            res = ngx.location.capture("/foo",
 
443
                { args = { ["fo="] = "=>" } })
 
444
            ngx.print(res.body)
 
445
        ';
 
446
        content_by_lua 'ngx.exit(ngx.OK)';
 
447
    }
 
448
--- request
 
449
GET /lua
 
450
--- response_body
 
451
fo%3d=%3d%3e
 
452
 
 
453
 
 
454
 
 
455
=== TEST 16: non-empty args option table (2 pairs)
 
456
--- config
 
457
    location /foo {
 
458
        echo $query_string;
 
459
    }
 
460
 
 
461
    location /lua {
 
462
        access_by_lua '
 
463
            res = ngx.location.capture("/foo",
 
464
                { args = { ["fo="] = "=>",
 
465
                    ["="] = ":" } })
 
466
            ngx.print(res.body)
 
467
        ';
 
468
        content_by_lua 'ngx.exit(ngx.OK)';
 
469
    }
 
470
--- request
 
471
GET /lua
 
472
--- response_body
 
473
fo%3d=%3d%3e&%3d=%3a
 
474
 
 
475
 
 
476
 
 
477
=== TEST 17: non-empty args option table (2 pairs, no special chars)
 
478
--- config
 
479
    location /foo {
 
480
        echo $query_string;
 
481
    }
 
482
 
 
483
    location /lua {
 
484
        access_by_lua '
 
485
            res = ngx.location.capture("/foo",
 
486
                { args = { foo = 3,
 
487
                    bar = "hello" } })
 
488
            ngx.print(res.body)
 
489
        ';
 
490
        content_by_lua 'ngx.exit(ngx.OK)';
 
491
    }
 
492
--- request
 
493
GET /lua
 
494
--- response_body
 
495
bar=hello&foo=3
 
496
 
 
497
 
 
498
 
 
499
=== TEST 18: non-empty args option table (number key)
 
500
--- config
 
501
    location /foo {
 
502
        echo $query_string;
 
503
    }
 
504
 
 
505
    location /lua {
 
506
        access_by_lua '
 
507
            res = ngx.location.capture("/foo",
 
508
                { args = { [57] = "hi" } })
 
509
            ngx.print(res.body)
 
510
        ';
 
511
        content_by_lua 'ngx.exit(ngx.OK)';
 
512
    }
 
513
--- request
 
514
GET /lua
 
515
--- response_body_like: 500 Internal Server Error
 
516
--- error_code: 500
 
517
 
 
518
 
 
519
 
 
520
=== TEST 19: non-empty args option table (plain arrays)
 
521
--- config
 
522
    location /foo {
 
523
        echo $query_string;
 
524
    }
 
525
 
 
526
    location /lua {
 
527
        access_by_lua '
 
528
            res = ngx.location.capture("/foo",
 
529
                { args = { "hi" } })
 
530
            ngx.print(res.body)
 
531
        ';
 
532
        content_by_lua 'ngx.exit(ngx.OK)';
 
533
    }
 
534
--- request
 
535
GET /lua
 
536
--- response_body_like: 500 Internal Server Error
 
537
--- error_code: 500
 
538
 
 
539
 
 
540
 
 
541
=== TEST 20: more args
 
542
--- config
 
543
    location /foo {
 
544
        echo $query_string;
 
545
    }
 
546
 
 
547
    location /lua {
 
548
        access_by_lua '
 
549
            res = ngx.location.capture("/foo?a=3",
 
550
                { args = { b = 4 } })
 
551
            ngx.print(res.body)
 
552
        ';
 
553
        content_by_lua 'ngx.exit(ngx.OK)';
 
554
    }
 
555
--- request
 
556
GET /lua
 
557
--- response_body
 
558
a=3&b=4
 
559
 
 
560
 
 
561
 
 
562
=== TEST 21: more args
 
563
--- config
 
564
    location /foo {
 
565
        echo $query_string;
 
566
    }
 
567
 
 
568
    location /lua {
 
569
        access_by_lua '
 
570
            res = ngx.location.capture("/foo?a=3",
 
571
                { args = "b=4" })
 
572
            ngx.print(res.body)
 
573
        ';
 
574
        content_by_lua 'ngx.exit(ngx.OK)';
 
575
    }
 
576
--- request
 
577
GET /lua
 
578
--- response_body
 
579
a=3&b=4
 
580