~ubuntu-branches/ubuntu/raring/nginx/raring-security

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/099-c-api.t

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Kartik Mistry, Cyril Lavier, Michael Lustfield
  • Date: 2012-12-18 10:29:18 UTC
  • mfrom: (4.2.56 sid)
  • Revision ID: package-import@ubuntu.com-20121218102918-dxtwj9vj89sbj8dz
Tags: 1.2.6-1
[ Kartik Mistry ]
* New upstream release.
* debian/nginx-common.nginx.init:
  + Used log_*_msg instead of echo for better init messages.
  + Added patch to check start-stop-daemon exit status, Thanks to
    Sergey B Kirpichev <skirpichev@gmail.com> (Closes: #695374).
* debian/po/ja.po:
  + Added new Japanese translation. Thanks to victory <victory.deb@gmail.com>
    (Closes: #692481).
* debian/po/pt_BR.po:
  + Added new Brazilian Portuguese translation. Thanks to
    Adriano Rafael Gomes <adrianorg@gmail.com> (Closes: #692481).

[ Cyril Lavier ]
* debian/rules
  + Added RealIP module in nginx-naxsi (Closes: #693302).
* debian/modules/nginx-cache-purge/
  + Updated nginx-cache-purge module with the 2.0 version.
* debian/modules/nginx-lua/
  + Updated nginx-lua module with the 0.7.8 version.
* debian/modules/nginx-echo/
  + Updated the nginx-echo module with the 0.41 version.
* debian/modules/headers-more-nginx-module/
  + Updated the Headers-more module with the 0.19 version.
* debian/modules/README.Modules-versions
  + Updated the current version of modules following the updates.

[ Michael Lustfield ]
* debian/conf/sites-available/default
  + Uncommented listen lines to make server block default.

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(3);
 
10
 
 
11
plan tests => repeat_each() * (blocks() * 3);
 
12
 
 
13
#no_diff();
 
14
no_long_string();
 
15
#master_on();
 
16
#workers(2);
 
17
 
 
18
run_tests();
 
19
 
 
20
__DATA__
 
21
 
 
22
=== TEST 1: find zone
 
23
--- http_config
 
24
    lua_shared_dict dogs 1m;
 
25
--- config
 
26
    location = /test {
 
27
        content_by_lua '
 
28
            local ffi = require "ffi"
 
29
 
 
30
            ffi.cdef[[
 
31
                void *ngx_http_lua_find_zone(char *data, size_t len);
 
32
            ]]
 
33
 
 
34
            local buf = ffi.new("char[?]", 4)
 
35
            ffi.copy(buf, "foo", 3)
 
36
            local zone = ffi.C.ngx_http_lua_find_zone(buf, 3)
 
37
            ngx.say("foo zone: ", tonumber(ffi.cast("long", zone)) ~= 0 and "defined" or "undef")
 
38
 
 
39
            ffi.copy(buf, "dogs", 4)
 
40
            zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
 
41
            ngx.say("dogs zone: ", tonumber(ffi.cast("long", zone)) ~= 0 and "defined" or "undef")
 
42
        ';
 
43
    }
 
44
--- request
 
45
GET /test
 
46
--- response_body
 
47
foo zone: undef
 
48
dogs zone: defined
 
49
--- no_error_log
 
50
[error]
 
51
 
 
52
 
 
53
 
 
54
=== TEST 2: number typed value
 
55
--- http_config
 
56
    lua_shared_dict dogs 1m;
 
57
--- config
 
58
    location = /test {
 
59
        content_by_lua '
 
60
            local ffi = require "ffi"
 
61
 
 
62
            ffi.cdef[[
 
63
                typedef struct {
 
64
                    size_t  len;
 
65
                    char   *data;
 
66
                } ngx_str_t;
 
67
 
 
68
                typedef struct {
 
69
                    uint8_t         type;
 
70
 
 
71
                    union {
 
72
                        int         b; /* boolean */
 
73
                        double      n; /* number */
 
74
                        ngx_str_t   s; /* string */
 
75
                    } value;
 
76
 
 
77
                } ngx_http_lua_value_t;
 
78
 
 
79
                void *ngx_http_lua_find_zone(char *data, size_t len);
 
80
                intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
 
81
            ]]
 
82
 
 
83
            local dogs = ngx.shared.dogs
 
84
            dogs:set("foo", 1234567)
 
85
            dogs:set("bar", 3.14159)
 
86
 
 
87
            local buf = ffi.new("char[?]", 4)
 
88
 
 
89
            ffi.copy(buf, "dogs", 4)
 
90
            zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
 
91
 
 
92
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
93
 
 
94
            ffi.copy(buf, "foo", 3)
 
95
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
96
            ngx.say("foo: rc=", tonumber(rc),
 
97
                ", type=", val[0].type,
 
98
                ", val=", tonumber(val[0].value.n))
 
99
 
 
100
            ffi.copy(buf, "bar", 3)
 
101
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
102
            ngx.say("bar: rc=", tonumber(rc),
 
103
                ", type=", val[0].type,
 
104
                ", val=", tonumber(val[0].value.n))
 
105
        ';
 
106
    }
 
107
--- request
 
108
GET /test
 
109
--- response_body
 
110
foo: rc=0, type=3, val=1234567
 
111
bar: rc=0, type=3, val=3.14159
 
112
--- no_error_log
 
113
[error]
 
114
 
 
115
 
 
116
 
 
117
=== TEST 3: boolean typed value
 
118
--- http_config
 
119
    lua_shared_dict dogs 1m;
 
120
--- config
 
121
    location = /test {
 
122
        content_by_lua '
 
123
            local ffi = require "ffi"
 
124
 
 
125
            ffi.cdef[[
 
126
                typedef struct {
 
127
                    size_t  len;
 
128
                    char   *data;
 
129
                } ngx_str_t;
 
130
 
 
131
                typedef struct {
 
132
                    uint8_t         type;
 
133
 
 
134
                    union {
 
135
                        int         b; /* boolean */
 
136
                        double      n; /* number */
 
137
                        ngx_str_t   s; /* string */
 
138
                    } value;
 
139
 
 
140
                } ngx_http_lua_value_t;
 
141
 
 
142
                void *ngx_http_lua_find_zone(char *data, size_t len);
 
143
                intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
 
144
            ]]
 
145
 
 
146
            local dogs = ngx.shared.dogs
 
147
            dogs:set("foo", true)
 
148
            dogs:set("bar", false)
 
149
 
 
150
            local buf = ffi.new("char[?]", 4)
 
151
 
 
152
            ffi.copy(buf, "dogs", 4)
 
153
            zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
 
154
 
 
155
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
156
 
 
157
            ffi.copy(buf, "foo", 3)
 
158
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
159
            ngx.say("foo: rc=", tonumber(rc),
 
160
                ", type=", tonumber(val[0].type),
 
161
                ", val=", tonumber(val[0].value.b))
 
162
 
 
163
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
164
            ffi.copy(buf, "bar", 3)
 
165
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
166
            ngx.say("bar: rc=", tonumber(rc),
 
167
                ", type=", tonumber(val[0].type),
 
168
                ", val=", tonumber(val[0].value.b))
 
169
        ';
 
170
    }
 
171
--- request
 
172
GET /test
 
173
--- response_body
 
174
foo: rc=0, type=1, val=1
 
175
bar: rc=0, type=1, val=0
 
176
--- no_error_log
 
177
[error]
 
178
 
 
179
 
 
180
 
 
181
=== TEST 4: key not found
 
182
--- http_config
 
183
    lua_shared_dict dogs 1m;
 
184
--- config
 
185
    location = /test {
 
186
        content_by_lua '
 
187
            local ffi = require "ffi"
 
188
 
 
189
            ffi.cdef[[
 
190
                typedef struct {
 
191
                    size_t  len;
 
192
                    char   *data;
 
193
                } ngx_str_t;
 
194
 
 
195
                typedef struct {
 
196
                    uint8_t         type;
 
197
 
 
198
                    union {
 
199
                        int         b; /* boolean */
 
200
                        double      n; /* number */
 
201
                        ngx_str_t   s; /* string */
 
202
                    } value;
 
203
 
 
204
                } ngx_http_lua_value_t;
 
205
 
 
206
                void *ngx_http_lua_find_zone(char *data, size_t len);
 
207
                intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
 
208
            ]]
 
209
 
 
210
            local dogs = ngx.shared.dogs
 
211
            dogs:flush_all()
 
212
 
 
213
            local buf = ffi.new("char[?]", 4)
 
214
 
 
215
            ffi.copy(buf, "dogs", 4)
 
216
            zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
 
217
 
 
218
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
219
 
 
220
            ffi.copy(buf, "foo", 3)
 
221
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
222
            ngx.say("foo: rc=", tonumber(rc))
 
223
 
 
224
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
225
            ffi.copy(buf, "bar", 3)
 
226
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
227
            ngx.say("bar: rc=", tonumber(rc))
 
228
        ';
 
229
    }
 
230
--- request
 
231
GET /test
 
232
--- response_body
 
233
foo: rc=-5
 
234
bar: rc=-5
 
235
--- no_error_log
 
236
[error]
 
237
 
 
238
 
 
239
 
 
240
=== TEST 5: string typed value
 
241
--- http_config
 
242
    lua_shared_dict dogs 1m;
 
243
--- config
 
244
    location = /test {
 
245
        content_by_lua '
 
246
            local ffi = require "ffi"
 
247
 
 
248
            ffi.cdef[[
 
249
                typedef struct {
 
250
                    size_t  len;
 
251
                    char   *data;
 
252
                } ngx_str_t;
 
253
 
 
254
                typedef struct {
 
255
                    uint8_t         type;
 
256
 
 
257
                    union {
 
258
                        int         b; /* boolean */
 
259
                        double      n; /* number */
 
260
                        ngx_str_t   s; /* string */
 
261
                    } value;
 
262
 
 
263
                } ngx_http_lua_value_t;
 
264
 
 
265
                void *ngx_http_lua_find_zone(char *data, size_t len);
 
266
                intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
 
267
            ]]
 
268
 
 
269
            local dogs = ngx.shared.dogs
 
270
            dogs:set("foo", "hello world")
 
271
            dogs:set("bar", "")
 
272
 
 
273
            local buf = ffi.new("char[?]", 4)
 
274
 
 
275
            ffi.copy(buf, "dogs", 4)
 
276
            zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
 
277
 
 
278
            local s = ffi.new("char[?]", 20)
 
279
 
 
280
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
281
            val[0].value.s.len = 20
 
282
            val[0].value.s.data = s
 
283
 
 
284
            ffi.copy(buf, "foo", 3)
 
285
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
286
            ngx.say("foo: rc=", tonumber(rc),
 
287
                ", type=", tonumber(val[0].type),
 
288
                ", val=", ffi.string(val[0].value.s.data, val[0].value.s.len),
 
289
                ", len=", tonumber(val[0].value.s.len))
 
290
 
 
291
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
292
            val[0].value.s.len = 20
 
293
            val[0].value.s.data = s
 
294
 
 
295
            ffi.copy(buf, "bar", 3)
 
296
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
297
            ngx.say("bar: rc=", tonumber(rc),
 
298
                ", type=", tonumber(val[0].type),
 
299
                ", val=", ffi.string(val[0].value.s.data, val[0].value.s.len),
 
300
                ", len=", tonumber(val[0].value.s.len))
 
301
        ';
 
302
    }
 
303
--- request
 
304
GET /test
 
305
--- response_body
 
306
foo: rc=0, type=4, val=hello world, len=11
 
307
bar: rc=0, type=4, val=, len=0
 
308
--- no_error_log
 
309
[error]
 
310
 
 
311
 
 
312
 
 
313
=== TEST 6: nil typed value
 
314
--- http_config
 
315
    lua_shared_dict dogs 1m;
 
316
--- config
 
317
    location = /test {
 
318
        content_by_lua '
 
319
            local ffi = require "ffi"
 
320
 
 
321
            ffi.cdef[[
 
322
                typedef struct {
 
323
                    size_t  len;
 
324
                    char   *data;
 
325
                } ngx_str_t;
 
326
 
 
327
                typedef struct {
 
328
                    uint8_t         type;
 
329
 
 
330
                    union {
 
331
                        int         b; /* boolean */
 
332
                        double      n; /* number */
 
333
                        ngx_str_t   s; /* string */
 
334
                    } value;
 
335
 
 
336
                } ngx_http_lua_value_t;
 
337
 
 
338
                void *ngx_http_lua_find_zone(char *data, size_t len);
 
339
                intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
 
340
            ]]
 
341
 
 
342
            local dogs = ngx.shared.dogs
 
343
            dogs:set("foo", nil)
 
344
 
 
345
            local buf = ffi.new("char[?]", 4)
 
346
 
 
347
            ffi.copy(buf, "dogs", 4)
 
348
            zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
 
349
 
 
350
            local val = ffi.new("ngx_http_lua_value_t[?]", 1)
 
351
 
 
352
            ffi.copy(buf, "foo", 3)
 
353
            local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
 
354
            ngx.say("foo: rc=", tonumber(rc))
 
355
        ';
 
356
    }
 
357
--- request
 
358
GET /test
 
359
--- response_body
 
360
foo: rc=-5
 
361
--- no_error_log
 
362
[error]
 
363