~ubuntu-branches/ubuntu/natty/nginx/natty-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/002-content.t

  • Committer: Bazaar Package Importer
  • Author(s): Michael Lustfield, Micheal Lustfield, Kartik Mistry
  • Date: 2011-03-03 23:39:07 UTC
  • mfrom: (4.2.29 sid)
  • Revision ID: james.westby@ubuntu.com-20110303233907-y48yifhfnn5qjuxz
Tags: 0.8.54-4
[Micheal Lustfield]
* debian/nginx-{full,light,extras}.default:
  + Added comment about alternative to ULIMIT.
* debian/nginx-{full,light,extras}.init.d:
  + Added quotes around a test variable. (Closes: #610946, LP: #699736)
* debian/patches/609343-log-time-iso8601.diff:
  + Added patch to add $time_iso8601 variable to logs. (Closes: #609343)
* Clean up old logrotate files. (Closes: #608983, Closes: #610289)
  + Added Files:
    - debian/nginx-common.preinst
  + Modified Files:
    - debian/rules
  + Moved debian/nginx-common.logrotate to debian/logrotate.
* Added common files to nginx-common package. (Closes: #610290)
  + Removed Files:
    - debian/nginx-full.dirs
    - debian/nginx-light.dirs
    - debian/nginx-full.install
    - debian/nginx-light.install
    - debian/nginx-extras.install
    - debian/nginx.*
  + Added Files:
    - debian/nginx-common.default
    - debian/nginx-common.dirs
    - debian/nginx-common.init.d
    - debian/nginx-common.install
    - debian/nginx-common.manpages
    - debian/logrotate
  + Modified Files:
    - debian/nginx-extras.dirs
    - debian/control
    - debian/rules
* debian/nginx-*.install: (Closes: #609797)
  + Removed NEWS.Debian from nginx-{full,light,extras}.install.
  + Added NEWS.Debian to nginx-common.install.
* nginx-common.postinst:
  + Enforce /var/log/nginx mode and user:group. (Closes: #610983)
  + Enforce /var/log/nginx/*.log mode and user:group. (Closes: #612832)
* debian/rules:
  + Added --with-file-aio to nginx-extras. (Closes: #613175)
  + Removed split clients and user id modules from nginx-light.
* debian/conf/sites-available/default:
  + Fixed a minor typo ( s/Quickstart/QuickStart/ ). (Closes: #613355)
* debian/conf/mime.types:
  + Changed xml type to application/xhtml+xml. (Closes: #613851)
* debian/help/docs/fcgiwrap:
  + Removed Ubuntu specific line in docs. (Closes: #614987)
* debian/conf/sites-available/default:
  + Fixed a pointer to a file. (Closes: #614980)

[Kartik Mistry]
* debian/*.lintian-overrides:
  + Add Lintian overrides for nginx man page. We've manpage in nginx-common
    binary

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 + 1);
 
13
 
 
14
#no_diff();
 
15
#no_long_string();
 
16
run_tests();
 
17
 
 
18
__DATA__
 
19
 
 
20
=== TEST 1: basic print
 
21
--- config
 
22
    location /lua {
 
23
        # NOTE: the newline escape sequence must be double-escaped, as nginx config
 
24
        # parser will unescape first!
 
25
        content_by_lua 'ngx.print("Hello, Lua!\\n")';
 
26
    }
 
27
--- request
 
28
GET /lua
 
29
--- response_body
 
30
Hello, Lua!
 
31
 
 
32
 
 
33
 
 
34
=== TEST 2: basic say
 
35
--- config
 
36
    location /say {
 
37
        # NOTE: the newline escape sequence must be double-escaped, as nginx config
 
38
        # parser will unescape first!
 
39
        content_by_lua '
 
40
            ngx.say("Hello, Lua!")
 
41
            ngx.say("Yay! ", 123)';
 
42
    }
 
43
--- request
 
44
GET /say
 
45
--- response_body
 
46
Hello, Lua!
 
47
Yay! 123
 
48
 
 
49
 
 
50
 
 
51
=== TEST 3: no ngx.echo
 
52
--- config
 
53
    location /lua {
 
54
        content_by_lua 'ngx.echo("Hello, Lua!\\n")';
 
55
    }
 
56
--- request
 
57
GET /lua
 
58
--- response_body_like: 500 Internal Server Error
 
59
--- error_code: 500
 
60
 
 
61
 
 
62
 
 
63
=== TEST 4: variable
 
64
--- config
 
65
    location /lua {
 
66
        # NOTE: the newline escape sequence must be double-escaped, as nginx config
 
67
        # parser will unescape first!
 
68
        content_by_lua 'v = ngx.var["request_uri"] ngx.print("request_uri: ", v, "\\n")';
 
69
    }
 
70
--- request
 
71
GET /lua?a=1&b=2
 
72
--- response_body
 
73
request_uri: /lua?a=1&b=2
 
74
 
 
75
 
 
76
 
 
77
=== TEST 5: variable (file)
 
78
--- config
 
79
    location /lua {
 
80
        content_by_lua_file html/test.lua;
 
81
    }
 
82
--- user_files
 
83
>>> test.lua
 
84
v = ngx.var["request_uri"]
 
85
ngx.print("request_uri: ", v, "\n")
 
86
--- request
 
87
GET /lua?a=1&b=2
 
88
--- response_body
 
89
request_uri: /lua?a=1&b=2
 
90
 
 
91
 
 
92
 
 
93
=== TEST 6: calc expression
 
94
--- config
 
95
    location /lua {
 
96
        content_by_lua_file html/calc.lua;
 
97
    }
 
98
--- user_files
 
99
>>> calc.lua
 
100
local function uri_unescape(uri)
 
101
    local function convert(hex)
 
102
        return string.char(tonumber("0x"..hex))
 
103
    end
 
104
    local s = string.gsub(uri, "%%([0-9a-fA-F][0-9a-fA-F])", convert)
 
105
    return s
 
106
end
 
107
 
 
108
local function eval_exp(str)
 
109
    return loadstring("return "..str)()
 
110
end
 
111
 
 
112
local exp_str = ngx.var["arg_exp"]
 
113
-- print("exp: '", exp_str, "'\n")
 
114
local status, res
 
115
status, res = pcall(uri_unescape, exp_str)
 
116
if not status then
 
117
    ngx.print("error: ", res, "\n")
 
118
    return
 
119
end
 
120
status, res = pcall(eval_exp, res)
 
121
if status then
 
122
    ngx.print("result: ", res, "\n")
 
123
else
 
124
    ngx.print("error: ", res, "\n")
 
125
end
 
126
--- request
 
127
GET /lua?exp=1%2B2*math.sin(3)%2Fmath.exp(4)-math.sqrt(2)
 
128
--- response_body
 
129
result: -0.4090441561579
 
130
 
 
131
 
 
132
 
 
133
=== TEST 7: read $arg_xxx
 
134
--- config
 
135
    location = /lua {
 
136
        content_by_lua 'who = ngx.var.arg_who
 
137
            ngx.print("Hello, ", who, "!")';
 
138
    }
 
139
--- request
 
140
GET /lua?who=agentzh
 
141
--- response_body chomp
 
142
Hello, agentzh!
 
143
 
 
144
 
 
145
 
 
146
=== TEST 8: capture location
 
147
--- config
 
148
    location /other {
 
149
        echo "hello, world";
 
150
    }
 
151
 
 
152
    location /lua {
 
153
        content_by_lua 'res = ngx.location.capture("/other"); ngx.print("status=", res.status, " "); ngx.print("body=", res.body)';
 
154
    }
 
155
--- request
 
156
GET /lua
 
157
--- response_body
 
158
status=200 body=hello, world
 
159
 
 
160
 
 
161
 
 
162
=== TEST 9: capture non-existed location
 
163
--- config
 
164
    location /lua {
 
165
        content_by_lua 'res = ngx.location.capture("/other"); ngx.print("status=", res.status)';
 
166
    }
 
167
--- request
 
168
GET /lua
 
169
--- response_body: status=404
 
170
 
 
171
 
 
172
 
 
173
=== TEST 10: invalid capture location (not as expected...)
 
174
--- config
 
175
    location /lua {
 
176
        content_by_lua 'res = ngx.location.capture("*(#*"); ngx.say("res=", res.status)';
 
177
    }
 
178
--- request
 
179
GET /lua
 
180
--- response_body
 
181
res=404
 
182
 
 
183
 
 
184
 
 
185
=== TEST 11: nil is "nil"
 
186
--- config
 
187
    location /lua {
 
188
        content_by_lua 'ngx.print(nil)';
 
189
    }
 
190
--- request
 
191
GET /lua
 
192
--- response_body_like: 500 Internal Server Error
 
193
--- error_code: 500
 
194
 
 
195
 
 
196
 
 
197
=== TEST 12: bad argument type to ngx.location.capture
 
198
--- config
 
199
    location /lua {
 
200
        content_by_lua 'ngx.location.capture(nil)';
 
201
    }
 
202
--- request
 
203
GET /lua
 
204
--- response_body_like: 500 Internal Server Error
 
205
--- error_code: 500
 
206
 
 
207
 
 
208
 
 
209
=== TEST 13: capture location (default 0);
 
210
--- config
 
211
 location /recur {
 
212
       content_by_lua '
 
213
           local num = tonumber(ngx.var.arg_num) or 0;
 
214
           ngx.print("num is: ", num, "\\n");
 
215
 
 
216
           if (num > 0) then
 
217
               res = ngx.location.capture("/recur?num="..tostring(num - 1));
 
218
               ngx.print("status=", res.status, " ");
 
219
               ngx.print("body=", res.body, "\\n");
 
220
           else
 
221
               ngx.print("end\\n");
 
222
           end
 
223
           ';
 
224
   }
 
225
--- request
 
226
GET /recur
 
227
--- response_body
 
228
num is: 0
 
229
end
 
230
 
 
231
 
 
232
 
 
233
=== TEST 14: capture location
 
234
--- config
 
235
 location /recur {
 
236
       content_by_lua '
 
237
           local num = tonumber(ngx.var.arg_num) or 0;
 
238
           ngx.print("num is: ", num, "\\n");
 
239
 
 
240
           if (num > 0) then
 
241
               res = ngx.location.capture("/recur?num="..tostring(num - 1));
 
242
               ngx.print("status=", res.status, " ");
 
243
               ngx.print("body=", res.body);
 
244
           else
 
245
               ngx.print("end\\n");
 
246
           end
 
247
           ';
 
248
   }
 
249
--- request
 
250
GET /recur?num=3
 
251
--- response_body
 
252
num is: 3
 
253
status=200 body=num is: 2
 
254
status=200 body=num is: 1
 
255
status=200 body=num is: 0
 
256
end
 
257
 
 
258
 
 
259
 
 
260
=== TEST 15: setting nginx variables from within Lua
 
261
--- config
 
262
 location /set {
 
263
       set $a "";
 
264
       content_by_lua 'ngx.var.a = 32; ngx.say(ngx.var.a)';
 
265
       add_header Foo $a;
 
266
   }
 
267
--- request
 
268
GET /set
 
269
--- response_headers
 
270
Foo: 32
 
271
--- response_body
 
272
32
 
273
 
 
274
 
 
275
 
 
276
=== TEST 16: nginx quote sql string 1
 
277
--- config
 
278
 location /set {
 
279
       set $a 'hello\n\r\'"\\';
 
280
       content_by_lua 'ngx.say(ngx.quote_sql_str(ngx.var.a))';
 
281
   }
 
282
--- request
 
283
GET /set
 
284
--- response_body
 
285
'hello\n\r\'\"\\'
 
286
 
 
287
 
 
288
 
 
289
=== TEST 17: nginx quote sql string 2
 
290
--- config
 
291
location /set {
 
292
    set $a "hello\n\r'\"\\";
 
293
    content_by_lua 'ngx.say(ngx.quote_sql_str(ngx.var.a))';
 
294
}
 
295
--- request
 
296
GET /set
 
297
--- response_body
 
298
'hello\n\r\'\"\\'
 
299
 
 
300
 
 
301
 
 
302
=== TEST 18: use dollar
 
303
--- config
 
304
location /set {
 
305
    content_by_lua '
 
306
        local s = "hello 112";
 
307
        ngx.say(string.find(s, "%d+$"))';
 
308
}
 
309
--- request
 
310
GET /set
 
311
--- response_body
 
312
79
 
313
 
 
314
 
 
315
 
 
316
=== TEST 19: subrequests do not share variables of main requests by default
 
317
--- config
 
318
location /sub {
 
319
    echo $a;
 
320
}
 
321
location /parent {
 
322
    set $a 12;
 
323
    content_by_lua 'res = ngx.location.capture("/sub"); ngx.print(res.body)';
 
324
}
 
325
--- request
 
326
GET /parent
 
327
--- response_body eval: "\n"
 
328
 
 
329
 
 
330
 
 
331
=== TEST 20: subrequests can share variables of main requests
 
332
--- config
 
333
location /sub {
 
334
    echo $a;
 
335
}
 
336
location /parent {
 
337
    set $a 12;
 
338
    content_by_lua '
 
339
        res = ngx.location.capture(
 
340
            "/sub",
 
341
            { share_all_vars = true }
 
342
        );
 
343
        ngx.print(res.body)
 
344
    ';
 
345
}
 
346
--- request
 
347
GET /parent
 
348
--- response_body
 
349
12
 
350
 
 
351
 
 
352
 
 
353
=== TEST 21: main requests use subrequests' variables
 
354
--- config
 
355
location /sub {
 
356
    set $a 12;
 
357
}
 
358
location /parent {
 
359
    content_by_lua '
 
360
        res = ngx.location.capture("/sub", { share_all_vars = true });
 
361
        ngx.say(ngx.var.a)
 
362
    ';
 
363
}
 
364
--- request
 
365
GET /parent
 
366
--- response_body
 
367
12
 
368
 
 
369
 
 
370
 
 
371
=== TEST 22: main requests do NOT use subrequests' variables
 
372
--- config
 
373
location /sub {
 
374
    set $a 12;
 
375
}
 
376
location /parent {
 
377
    content_by_lua '
 
378
        res = ngx.location.capture("/sub", { share_all_vars = false });
 
379
        ngx.say(ngx.var.a)
 
380
    ';
 
381
}
 
382
--- request
 
383
GET /parent
 
384
--- response_body_like eval: "\n"
 
385
 
 
386
 
 
387
 
 
388
=== TEST 23: capture location headers
 
389
--- config
 
390
    location /other {
 
391
        default_type 'foo/bar';
 
392
        echo "hello, world";
 
393
    }
 
394
 
 
395
    location /lua {
 
396
        content_by_lua '
 
397
            res = ngx.location.capture("/other");
 
398
            ngx.say("type: ", res.header["Content-Type"]);
 
399
        ';
 
400
    }
 
401
--- request
 
402
GET /lua
 
403
--- response_body
 
404
type: foo/bar
 
405
 
 
406
 
 
407
 
 
408
=== TEST 24: capture location headers
 
409
--- config
 
410
    location /other {
 
411
        default_type 'foo/bar';
 
412
        content_by_lua '
 
413
            ngx.header.Bar = "Bah";
 
414
        ';
 
415
    }
 
416
 
 
417
    location /lua {
 
418
        content_by_lua '
 
419
            res = ngx.location.capture("/other");
 
420
            ngx.say("type: ", res.header["Content-Type"]);
 
421
            ngx.say("Bar: ", res.header["Bar"]);
 
422
        ';
 
423
    }
 
424
--- request
 
425
GET /lua
 
426
--- response_body
 
427
type: foo/bar
 
428
Bar: Bah
 
429
 
 
430
 
 
431
 
 
432
=== TEST 25: capture location headers
 
433
--- config
 
434
    location /other {
 
435
        default_type 'foo/bar';
 
436
        content_by_lua '
 
437
            ngx.header.Bar = "Bah";
 
438
            ngx.header.Bar = nil;
 
439
        ';
 
440
    }
 
441
 
 
442
    location /lua {
 
443
        content_by_lua '
 
444
            res = ngx.location.capture("/other");
 
445
            ngx.say("type: ", res.header["Content-Type"]);
 
446
            ngx.say("Bar: ", res.header["Bar"] or "nil");
 
447
        ';
 
448
    }
 
449
--- request
 
450
GET /lua
 
451
--- response_body
 
452
type: foo/bar
 
453
Bar: nil
 
454