immunio 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +234 -0
  3. data/README.md +147 -0
  4. data/bin/immunio +5 -0
  5. data/lib/immunio.rb +29 -0
  6. data/lib/immunio/agent.rb +260 -0
  7. data/lib/immunio/authentication.rb +96 -0
  8. data/lib/immunio/blocked_app.rb +38 -0
  9. data/lib/immunio/channel.rb +432 -0
  10. data/lib/immunio/cli.rb +39 -0
  11. data/lib/immunio/context.rb +114 -0
  12. data/lib/immunio/errors.rb +43 -0
  13. data/lib/immunio/immunio_ca.crt +45 -0
  14. data/lib/immunio/logger.rb +87 -0
  15. data/lib/immunio/plugins/action_dispatch.rb +45 -0
  16. data/lib/immunio/plugins/action_view.rb +431 -0
  17. data/lib/immunio/plugins/active_record.rb +707 -0
  18. data/lib/immunio/plugins/active_record_relation.rb +370 -0
  19. data/lib/immunio/plugins/authlogic.rb +80 -0
  20. data/lib/immunio/plugins/csrf.rb +24 -0
  21. data/lib/immunio/plugins/devise.rb +40 -0
  22. data/lib/immunio/plugins/environment_reporter.rb +69 -0
  23. data/lib/immunio/plugins/eval.rb +51 -0
  24. data/lib/immunio/plugins/exception_handler.rb +55 -0
  25. data/lib/immunio/plugins/gems_tracker.rb +5 -0
  26. data/lib/immunio/plugins/haml.rb +36 -0
  27. data/lib/immunio/plugins/http_finisher.rb +50 -0
  28. data/lib/immunio/plugins/http_tracker.rb +203 -0
  29. data/lib/immunio/plugins/io.rb +96 -0
  30. data/lib/immunio/plugins/redirect.rb +42 -0
  31. data/lib/immunio/plugins/warden.rb +66 -0
  32. data/lib/immunio/processor.rb +234 -0
  33. data/lib/immunio/rails.rb +26 -0
  34. data/lib/immunio/request.rb +139 -0
  35. data/lib/immunio/rufus_lua_ext/ref.rb +27 -0
  36. data/lib/immunio/rufus_lua_ext/state.rb +157 -0
  37. data/lib/immunio/rufus_lua_ext/table.rb +137 -0
  38. data/lib/immunio/rufus_lua_ext/utils.rb +13 -0
  39. data/lib/immunio/version.rb +5 -0
  40. data/lib/immunio/vm.rb +291 -0
  41. data/lua-hooks/ext/all.c +78 -0
  42. data/lua-hooks/ext/bitop/README +22 -0
  43. data/lua-hooks/ext/bitop/bit.c +189 -0
  44. data/lua-hooks/ext/extconf.rb +38 -0
  45. data/lua-hooks/ext/libinjection/COPYING +37 -0
  46. data/lua-hooks/ext/libinjection/libinjection.h +65 -0
  47. data/lua-hooks/ext/libinjection/libinjection_html5.c +847 -0
  48. data/lua-hooks/ext/libinjection/libinjection_html5.h +54 -0
  49. data/lua-hooks/ext/libinjection/libinjection_sqli.c +2301 -0
  50. data/lua-hooks/ext/libinjection/libinjection_sqli.h +295 -0
  51. data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +9349 -0
  52. data/lua-hooks/ext/libinjection/libinjection_xss.c +531 -0
  53. data/lua-hooks/ext/libinjection/libinjection_xss.h +21 -0
  54. data/lua-hooks/ext/libinjection/lualib.c +109 -0
  55. data/lua-hooks/ext/lpeg/HISTORY +90 -0
  56. data/lua-hooks/ext/lpeg/lpcap.c +537 -0
  57. data/lua-hooks/ext/lpeg/lpcap.h +43 -0
  58. data/lua-hooks/ext/lpeg/lpcode.c +986 -0
  59. data/lua-hooks/ext/lpeg/lpcode.h +34 -0
  60. data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
  61. data/lua-hooks/ext/lpeg/lpeg.html +1429 -0
  62. data/lua-hooks/ext/lpeg/lpprint.c +244 -0
  63. data/lua-hooks/ext/lpeg/lpprint.h +35 -0
  64. data/lua-hooks/ext/lpeg/lptree.c +1238 -0
  65. data/lua-hooks/ext/lpeg/lptree.h +77 -0
  66. data/lua-hooks/ext/lpeg/lptypes.h +149 -0
  67. data/lua-hooks/ext/lpeg/lpvm.c +355 -0
  68. data/lua-hooks/ext/lpeg/lpvm.h +58 -0
  69. data/lua-hooks/ext/lpeg/makefile +55 -0
  70. data/lua-hooks/ext/lpeg/re.html +498 -0
  71. data/lua-hooks/ext/lpeg/test.lua +1409 -0
  72. data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +45 -0
  73. data/lua-hooks/ext/lua-cmsgpack/README.md +115 -0
  74. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +957 -0
  75. data/lua-hooks/ext/lua-cmsgpack/test.lua +570 -0
  76. data/lua-hooks/ext/lua-snapshot/LICENSE +7 -0
  77. data/lua-hooks/ext/lua-snapshot/Makefile +12 -0
  78. data/lua-hooks/ext/lua-snapshot/README.md +18 -0
  79. data/lua-hooks/ext/lua-snapshot/dump.lua +15 -0
  80. data/lua-hooks/ext/lua-snapshot/snapshot.c +455 -0
  81. data/lua-hooks/ext/lua/COPYRIGHT +34 -0
  82. data/lua-hooks/ext/lua/lapi.c +1087 -0
  83. data/lua-hooks/ext/lua/lapi.h +16 -0
  84. data/lua-hooks/ext/lua/lauxlib.c +652 -0
  85. data/lua-hooks/ext/lua/lauxlib.h +174 -0
  86. data/lua-hooks/ext/lua/lbaselib.c +659 -0
  87. data/lua-hooks/ext/lua/lcode.c +831 -0
  88. data/lua-hooks/ext/lua/lcode.h +76 -0
  89. data/lua-hooks/ext/lua/ldblib.c +398 -0
  90. data/lua-hooks/ext/lua/ldebug.c +638 -0
  91. data/lua-hooks/ext/lua/ldebug.h +33 -0
  92. data/lua-hooks/ext/lua/ldo.c +519 -0
  93. data/lua-hooks/ext/lua/ldo.h +57 -0
  94. data/lua-hooks/ext/lua/ldump.c +164 -0
  95. data/lua-hooks/ext/lua/lfunc.c +174 -0
  96. data/lua-hooks/ext/lua/lfunc.h +34 -0
  97. data/lua-hooks/ext/lua/lgc.c +710 -0
  98. data/lua-hooks/ext/lua/lgc.h +110 -0
  99. data/lua-hooks/ext/lua/linit.c +38 -0
  100. data/lua-hooks/ext/lua/liolib.c +556 -0
  101. data/lua-hooks/ext/lua/llex.c +463 -0
  102. data/lua-hooks/ext/lua/llex.h +81 -0
  103. data/lua-hooks/ext/lua/llimits.h +128 -0
  104. data/lua-hooks/ext/lua/lmathlib.c +263 -0
  105. data/lua-hooks/ext/lua/lmem.c +86 -0
  106. data/lua-hooks/ext/lua/lmem.h +49 -0
  107. data/lua-hooks/ext/lua/loadlib.c +705 -0
  108. data/lua-hooks/ext/lua/loadlib_rel.c +760 -0
  109. data/lua-hooks/ext/lua/lobject.c +214 -0
  110. data/lua-hooks/ext/lua/lobject.h +381 -0
  111. data/lua-hooks/ext/lua/lopcodes.c +102 -0
  112. data/lua-hooks/ext/lua/lopcodes.h +268 -0
  113. data/lua-hooks/ext/lua/loslib.c +243 -0
  114. data/lua-hooks/ext/lua/lparser.c +1339 -0
  115. data/lua-hooks/ext/lua/lparser.h +82 -0
  116. data/lua-hooks/ext/lua/lstate.c +214 -0
  117. data/lua-hooks/ext/lua/lstate.h +169 -0
  118. data/lua-hooks/ext/lua/lstring.c +111 -0
  119. data/lua-hooks/ext/lua/lstring.h +31 -0
  120. data/lua-hooks/ext/lua/lstrlib.c +871 -0
  121. data/lua-hooks/ext/lua/ltable.c +588 -0
  122. data/lua-hooks/ext/lua/ltable.h +40 -0
  123. data/lua-hooks/ext/lua/ltablib.c +287 -0
  124. data/lua-hooks/ext/lua/ltm.c +75 -0
  125. data/lua-hooks/ext/lua/ltm.h +54 -0
  126. data/lua-hooks/ext/lua/lua.c +392 -0
  127. data/lua-hooks/ext/lua/lua.def +131 -0
  128. data/lua-hooks/ext/lua/lua.h +388 -0
  129. data/lua-hooks/ext/lua/lua.rc +28 -0
  130. data/lua-hooks/ext/lua/lua_dll.rc +26 -0
  131. data/lua-hooks/ext/lua/luac.c +200 -0
  132. data/lua-hooks/ext/lua/luac.rc +1 -0
  133. data/lua-hooks/ext/lua/luaconf.h +763 -0
  134. data/lua-hooks/ext/lua/luaconf.h.in +724 -0
  135. data/lua-hooks/ext/lua/luaconf.h.orig +763 -0
  136. data/lua-hooks/ext/lua/lualib.h +53 -0
  137. data/lua-hooks/ext/lua/lundump.c +227 -0
  138. data/lua-hooks/ext/lua/lundump.h +36 -0
  139. data/lua-hooks/ext/lua/lvm.c +767 -0
  140. data/lua-hooks/ext/lua/lvm.h +36 -0
  141. data/lua-hooks/ext/lua/lzio.c +82 -0
  142. data/lua-hooks/ext/lua/lzio.h +67 -0
  143. data/lua-hooks/ext/lua/print.c +227 -0
  144. data/lua-hooks/ext/luautf8/README.md +152 -0
  145. data/lua-hooks/ext/luautf8/lutf8lib.c +1274 -0
  146. data/lua-hooks/ext/luautf8/unidata.h +3064 -0
  147. data/lua-hooks/lib/boot.lua +254 -0
  148. data/lua-hooks/lib/encode.lua +4 -0
  149. data/lua-hooks/lib/lexers/LICENSE +21 -0
  150. data/lua-hooks/lib/lexers/bash.lua +134 -0
  151. data/lua-hooks/lib/lexers/bash_dqstr.lua +62 -0
  152. data/lua-hooks/lib/lexers/css.lua +216 -0
  153. data/lua-hooks/lib/lexers/html.lua +106 -0
  154. data/lua-hooks/lib/lexers/javascript.lua +68 -0
  155. data/lua-hooks/lib/lexers/lexer.lua +1575 -0
  156. data/lua-hooks/lib/lexers/markers.lua +33 -0
  157. metadata +308 -0
@@ -0,0 +1,570 @@
1
+ -- lua_cmsgpack.c lib tests
2
+ -- Copyright(C) 2012 Salvatore Sanfilippo, All Rights Reserved.
3
+ -- See the copyright notice at the end of lua_cmsgpack.c for more information.
4
+
5
+ local cmsgpack = require "cmsgpack"
6
+ local ok, cmsgpack_safe = pcall(require, 'cmsgpack.safe')
7
+ if not ok then cmsgpack_safe = nil end
8
+
9
+ print("------------------------------------")
10
+ print("Lua version: " .. (_G.jit and _G.jit.version or _G._VERSION))
11
+ print("------------------------------------")
12
+
13
+ local unpack = unpack or table.unpack
14
+
15
+ passed = 0
16
+ failed = 0
17
+ skipped = 0
18
+
19
+ function hex(s)
20
+ local i
21
+ local h = ""
22
+
23
+ for i = 1, #s do
24
+ h = h .. string.format("%02x",string.byte(s,i))
25
+ end
26
+ return h
27
+ end
28
+
29
+ function ascii_to_num(c)
30
+ if (c >= string.byte("0") and c <= string.byte("9")) then
31
+ return c - string.byte("0")
32
+ elseif (c >= string.byte("A") and c <= string.byte("F")) then
33
+ return (c - string.byte("A"))+10
34
+ elseif (c >= string.byte("a") and c <= string.byte("f")) then
35
+ return (c - string.byte("a"))+10
36
+ else
37
+ error "Wrong input for ascii to num convertion."
38
+ end
39
+ end
40
+
41
+ function unhex(h)
42
+ local i
43
+ local s = ""
44
+ for i = 1, #h, 2 do
45
+ high = ascii_to_num(string.byte(h,i))
46
+ low = ascii_to_num(string.byte(h,i+1))
47
+ s = s .. string.char((high*16)+low)
48
+ end
49
+ return s
50
+ end
51
+
52
+ function test_error(name, fn)
53
+ io.write("Testing generate error '",name,"' ...")
54
+ local ok, ret, err = pcall(fn)
55
+ -- 'ok' is an error because we are testing for expicit *failure*
56
+ if ok then
57
+ print("ERROR: result ", ret, err)
58
+ failed = failed+1
59
+ else
60
+ print("ok")
61
+ passed = passed+1
62
+ end
63
+ end
64
+
65
+ local function test_multiple(name, ...)
66
+ io.write("Multiple test '",name,"' ...")
67
+ if not compare_objects({...},{cmsgpack.unpack(cmsgpack.pack(...))}) then
68
+ print("ERROR:", {...}, cmsgpack.unpack(cmsgpack.pack(...)))
69
+ failed = failed+1
70
+ else
71
+ print("ok")
72
+ passed = passed+1
73
+ end
74
+ end
75
+
76
+ function test_noerror(name, fn)
77
+ io.write("Testing safe calling '",name,"' ...")
78
+ if not cmsgpack_safe then
79
+ print("skip: no `cmsgpack.safe` module")
80
+ skipped = skipped + 1
81
+ return
82
+ end
83
+ local ok, ret, err = pcall(fn)
84
+ if not ok then
85
+ print("ERROR: result ", ret, err)
86
+ failed = failed+1
87
+ else
88
+ print("ok")
89
+ passed = passed+1
90
+ end
91
+ end
92
+
93
+ function compare_objects(a,b,depth)
94
+ if (type(a) == "table") then
95
+ local count = 0
96
+ if not depth then
97
+ depth = 1
98
+ elseif depth == 10 then
99
+ return true -- assume if match down 10 levels, the rest is okay too
100
+ end
101
+ for k,v in pairs(a) do
102
+ if not compare_objects(b[k],v, depth + 1) then return false end
103
+ count = count + 1
104
+ end
105
+ -- All the 'a' keys are equal to their 'b' equivalents.
106
+ -- Now we can check if there are extra fields in 'b'.
107
+ for k,v in pairs(b) do count = count - 1 end
108
+ if count == 0 then return true else return false end
109
+ else
110
+ return a == b
111
+ end
112
+ end
113
+
114
+ function test_circular(name,obj)
115
+ io.write("Circular test '",name,"' ...")
116
+ if not compare_objects(obj,cmsgpack.unpack(cmsgpack.pack(obj))) then
117
+ print("ERROR:", obj, cmsgpack.unpack(cmsgpack.pack(obj)))
118
+ failed = failed+1
119
+ else
120
+ print("ok")
121
+ passed = passed+1
122
+ end
123
+ end
124
+
125
+ function test_stream(mod, name, ...)
126
+ io.write("Stream test '", name, "' ...\n")
127
+ if not mod then
128
+ print("skip: no `cmsgpack.safe` module")
129
+ skipped = skipped + 1
130
+ return
131
+ end
132
+ local argc = select('#', ...)
133
+ for i=1, argc do
134
+ test_circular(name, select(i, ...))
135
+ end
136
+ local ret = {mod.unpack(mod.pack(unpack({...})))}
137
+ for i=1, argc do
138
+ local origin = select(i, ...)
139
+ if (type(origin) == "table") then
140
+ for k,v in pairs(origin) do
141
+ local fail = not compare_objects(v, ret[i][k])
142
+ if fail then
143
+ print("ERRORa:", k, v, " not match ", ret[i][k])
144
+ failed = failed + 1
145
+ elseif not fail then
146
+ print("ok; matched stream table member")
147
+ passed = passed + 1
148
+ end
149
+ end
150
+ else
151
+ local fail = not compare_objects(origin, ret[i])
152
+ if fail then
153
+ print("ERRORc:", origin, " not match ", ret[i])
154
+ failed = failed + 1
155
+ elseif not fail then
156
+ print("ok; matched individual stream member")
157
+ passed = passed + 1
158
+ end
159
+ end
160
+ end
161
+
162
+ end
163
+
164
+ function test_partial_unpack(name, count, ...)
165
+ io.write("Testing partial unpack '",name,"' ...\n")
166
+ local first = select(1, ...)
167
+ local pack, unpacked, args, offset, cargs, ok, err
168
+ if (type(first) == "table") then
169
+ pack = first.p
170
+ args = first.remaining
171
+ offset = first.o
172
+ cargs = {pack, count, offset}
173
+ else
174
+ pack = cmsgpack.pack(unpack({...}))
175
+ args = {...}
176
+ cargs = {pack, count}
177
+ end
178
+ if offset and offset < 0 then
179
+ ok, unpacked, err = pcall(function()return {cmsgpack.unpack_limit(unpack(cargs))} end)
180
+ if not ok then
181
+ print("ok; received error as expected") --, unpacked)
182
+ passed = passed + 1
183
+ return
184
+ end
185
+ else
186
+ unpacked = {cmsgpack.unpack_limit(unpack(cargs))}
187
+ -- print ("GOT RETURNED:", unpack(unpacked))
188
+ end
189
+
190
+ if count == 0 and #unpacked == 1 then
191
+ print("ok; received zero decodes as expected")
192
+ passed = passed + 1
193
+ return
194
+ end
195
+
196
+ if not (((#unpacked)-1) == count) then
197
+ print(string.format("ERROR: received %d instead of %d objects:", (#unpacked)-1, count),
198
+ unpack(select(1, unpacked)))
199
+ failed = failed + 1
200
+ return
201
+ end
202
+
203
+ for i=2, #unpacked do
204
+ local origin = args[i-1]
205
+ --print("Comparing ", origin, unpacked[i])
206
+ if not compare_objects(origin, unpacked[i]) then
207
+ print("ERROR:", origin, " not match ", unpacked[i])
208
+ failed = failed + 1
209
+ else
210
+ print("ok; matched unpacked value to input")
211
+ passed = passed + 1
212
+ end
213
+ end
214
+
215
+ -- return the packed value and our continue offset
216
+ return pack, unpacked[1]
217
+ end
218
+
219
+ function test_pack(name,obj,raw,optraw)
220
+ io.write("Testing encoder '",name,"' ...")
221
+ local result = hex(cmsgpack.pack(obj))
222
+ if optraw and (result == optraw) then
223
+ print("ok")
224
+ passed = passed + 1
225
+ elseif result ~= raw then
226
+ print("ERROR:", obj, hex(cmsgpack.pack(obj)), raw)
227
+ failed = failed+1
228
+ else
229
+ print("ok")
230
+ passed = passed+1
231
+ end
232
+ end
233
+
234
+ function test_unpack_one(name, packed, check, offset)
235
+ io.write("Testing one unpack '",name,"' ...")
236
+ local unpacked = {cmsgpack.unpack_one(unpack({packed, offset}))}
237
+
238
+ if #unpacked > 2 then
239
+ print("ERROR: unpacked more than one object:", unpack(unpacked))
240
+ failed = failed + 1
241
+ elseif not compare_objects(unpacked[2], check) then
242
+ print("ERROR: unpacked unexpected result:", unpack(unpacked))
243
+ failed = failed + 1
244
+ else
245
+ print("ok") --; unpacked", unpacked[2])
246
+ passed = passed + 1
247
+ end
248
+
249
+ return unpacked[1]
250
+ end
251
+
252
+ function test_unpack(name,raw,obj)
253
+ io.write("Testing decoder '",name,"' ...")
254
+ if not compare_objects(cmsgpack.unpack(unhex(raw)),obj) then
255
+ print("ERROR:", obj, raw, cmsgpack.unpack(unhex(raw)))
256
+ failed = failed+1
257
+ else
258
+ print("ok")
259
+ passed = passed+1
260
+ end
261
+ end
262
+
263
+ function test_pack_and_unpack(name,obj,raw)
264
+ test_pack(name,obj,raw)
265
+ test_unpack(name,raw,obj)
266
+ end
267
+
268
+ local function test_global()
269
+ io.write("Testing global variable ...")
270
+
271
+ if _VERSION == "Lua 5.1" then
272
+ if not _G.cmsgpack then
273
+ print("ERROR: Lua 5.1 should set global")
274
+ failed = failed+1
275
+ else
276
+ print("ok")
277
+ passed = passed+1
278
+ end
279
+ else
280
+ if _G.cmsgpack then
281
+ print("ERROR: Lua 5.2 should not set global")
282
+ failed = failed+1
283
+ else
284
+ print("ok")
285
+ passed = passed+1
286
+ end
287
+ end
288
+ end
289
+
290
+ local function test_array()
291
+ io.write("Testing array detection ...")
292
+
293
+ local a = {a1 = 1, a2 = 1, a3 = 1, a4 = 1, a5 = 1, a6 = 1, a7 = 1, a8 = 1, a9 = 1}
294
+ a[1] = 10 a[2] = 20 a[3] = 30
295
+ a.a1,a.a2,a.a3,a.a4,a.a5,a.a6,a.a7,a.a8, a.a9 = nil
296
+
297
+ local test_obj = {10,20,30}
298
+ assert(compare_objects(test_obj, a))
299
+
300
+ local etalon = cmsgpack.pack(test_obj)
301
+ local encode = cmsgpack.pack(a)
302
+
303
+ if etalon ~= encode then
304
+ print("ERROR:")
305
+ print("", "expected: ", hex(etalon))
306
+ print("", " got: ", hex(encode))
307
+ failed = failed+1
308
+ else
309
+ print("ok")
310
+ passed = passed+1
311
+ end
312
+
313
+ io.write("Testing array detection ...")
314
+
315
+ a = {["1"] = 20, [2] = 30, [3] = 40}
316
+ encode = cmsgpack.pack(a)
317
+ if etalon == encode then
318
+ print("ERROR:")
319
+ print("", " incorrect: ", hex(etalon))
320
+ failed = failed+1
321
+ else
322
+ print("ok")
323
+ passed = passed+1
324
+ end
325
+ end
326
+
327
+ test_global()
328
+ test_array()
329
+ test_circular("positive fixnum",17);
330
+ test_circular("negative fixnum",-1);
331
+ test_circular("true boolean",true);
332
+ test_circular("false boolean",false);
333
+ test_circular("float",1.5);
334
+ test_circular("positive uint8",101);
335
+ test_circular("negative int8",-101);
336
+ test_circular("positive uint16",20001);
337
+ test_circular("negative int16",-20001);
338
+ test_circular("positive uint32",20000001);
339
+ test_circular("negative int32",-20000001);
340
+ test_circular("positive uint64",200000000001);
341
+ test_circular("negative int64",-200000000001);
342
+ test_circular("uint8 max",0xff);
343
+ test_circular("uint16 max",0xffff);
344
+ test_circular("uint32 max",0xffffffff);
345
+ test_circular("int8 min",-128);
346
+ test_circular("int16 min",-32768);
347
+ test_circular("int32 min",-2147483648);
348
+ test_circular("nil",nil);
349
+ test_circular("fix string","abc");
350
+ test_circular("string16","xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab");
351
+ test_circular("fix array (1)",{1,2,3,"foo"})
352
+ test_circular("fix array (2)",{})
353
+ test_circular("fix array (3)",{1,{},{}})
354
+ test_circular("fix map",{a=5,b=10,c="string"})
355
+ test_circular("positive infinity", math.huge)
356
+ test_circular("negative infinity", -math.huge)
357
+ test_circular("high bits", 0xFFFFFFFF)
358
+ test_circular("higher bits", 0xFFFFFFFFFFFFFFFF)
359
+ test_circular("high bits", -0x7FFFFFFF)
360
+ test_circular("higher bits", -0x7FFFFFFFFFFFFFFF)
361
+
362
+ -- The following test vectors are taken from the Javascript lib at:
363
+ -- https://github.com/cuzic/MessagePack-JS/blob/master/test/test_pack.html
364
+
365
+ test_pack_and_unpack("positive fixnum",0,"00")
366
+ test_pack_and_unpack("negative fixnum",-1,"ff")
367
+ test_pack_and_unpack("uint8",255,"ccff")
368
+ test_pack_and_unpack("fix raw","a","a161")
369
+ test_pack_and_unpack("fix array",{0},"9100")
370
+ test_pack_and_unpack("fix map",{a=64},"81a16140")
371
+ test_pack_and_unpack("nil",nil,"c0")
372
+ test_pack_and_unpack("true",true,"c3")
373
+ test_pack_and_unpack("false",false,"c2")
374
+ test_pack_and_unpack("double",0.1,"cb3fb999999999999a")
375
+ test_pack_and_unpack("uint16",32768,"cd8000")
376
+ test_pack_and_unpack("uint32",1048576,"ce00100000")
377
+ test_pack_and_unpack("int8",-64,"d0c0")
378
+ test_pack_and_unpack("int16",-1024,"d1fc00")
379
+ test_pack_and_unpack("int32",-1048576,"d2fff00000")
380
+ test_pack_and_unpack("int64",-1099511627776,"d3ffffff0000000000")
381
+ test_pack_and_unpack("raw16"," ","da002820202020202020202020202020202020202020202020202020202020202020202020202020202020")
382
+ test_pack_and_unpack("array 16",{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},"dc001000000000000000000000000000000000")
383
+
384
+ -- Regression test for issue #4, cyclic references in tables.
385
+ a = {x=nil,y=5}
386
+ b = {x=a}
387
+ a['x'] = b
388
+ pack = cmsgpack.pack(a)
389
+ -- Note: the generated result isn't stable because the order of traversal for
390
+ -- a table isn't defined. So far we've only noticed two serializations of a
391
+ -- (and the second serialization only happens on Lua 5.3 sometimes)
392
+ test_pack("regression for issue #4 output matching",a,"82a17905a17881a17882a17905a17881a17882a17905a17881a17882a17905a17881a17882a17905a17881a17882a17905a17881a17882a17905a17881a17882a17905a17881a178c0", "82a17881a17882a17881a17882a17881a17882a17881a17882a17881a17882a17881a17882a17881a17882a17881a178c0a17905a17905a17905a17905a17905a17905a17905a17905")
393
+ test_circular("regression for issue #4 circular",a)
394
+
395
+ -- test unpacking malformed input without crashing. This actually returns one integer value (the ASCII code)
396
+ -- for each character in the string. We don't care about the return value, just that we don't segfault.
397
+ cmsgpack.unpack("82a17881a17882a17881a17882a17881a17882a17881a17882a17881a17882a17881a17882a17881a17882a17881a17")
398
+
399
+ -- Test unpacking input which may cause overflow memory access ("-1" for 32-bit size fields).
400
+ -- These should cause a Lua error but not a segfault.
401
+ test_error("unpack big string with missing input", function() cmsgpack.unpack("\219\255\255\255\255Z") end)
402
+ test_error("unpack big array with missing input", function() cmsgpack.unpack("\221\255\255\255\255Z") end)
403
+ test_error("unpack big map with missing input", function() cmsgpack.unpack("\223\255\255\255\255Z") end)
404
+
405
+ -- Tests from github.com/moteus
406
+ test_circular("map with number keys", {[1] = {1,2,3}})
407
+ test_circular("map with string keys", {["1"] = {1,2,3}})
408
+ test_circular("map with string keys", {["1"] = 20, [2] = 30, ["3"] = 40})
409
+ test_circular("map with float keys", {[1.5] = {1,2,3}})
410
+ test_error("unpack nil", function() cmsgpack.unpack(nil) end)
411
+ test_error("unpack table", function() cmsgpack.unpack({}) end)
412
+ test_error("unpack udata", function() cmsgpack.unpack(io.stdout) end)
413
+ test_noerror("unpack nil", function() cmsgpack_safe.unpack(nil) end)
414
+ test_noerror("unpack nil", function() cmsgpack_safe.unpack(nil) end)
415
+ test_noerror("unpack table", function() cmsgpack_safe.unpack({}) end)
416
+ test_noerror("unpack udata", function() cmsgpack_safe.unpack(io.stdout) end)
417
+ test_multiple("two ints", 1, 2)
418
+ test_multiple("holes", 1, nil, 2, nil, 4)
419
+
420
+ -- Streaming/Multi-Input Tests
421
+ test_stream(cmsgpack, "simple", {a=1}, {b=2}, {c=3}, 4, 5, 6, 7)
422
+ test_stream(cmsgpack_safe, "safe simple", {a=1}, {b=2}, {c=3}, 4, 5, 6, 7)
423
+ test_stream(cmsgpack, "oddities", {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0}, {a=64}, math.huge, -math.huge)
424
+ test_stream(cmsgpack_safe, "safe oddities", {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0}, {a=64}, math.huge, -math.huge)
425
+ test_stream(cmsgpack, "strange things", nil, {}, {nil}, a, b, b, b, a, a, b, {c = a, d = b})
426
+ test_stream(cmsgpack_safe, "strange things", nil, {}, {nil}, a, b, b, b, a, a, b, {c = a, d = b})
427
+ test_error("pack nothing", function() cmsgpack.pack() end)
428
+ test_noerror("pack nothing safe", function() cmsgpack_safe.pack() end)
429
+ test_circular("large object test",
430
+ {A=9483, a=9483, aa=9483, aal=9483, aalii=9483, aam=9483, Aani=9483,
431
+ aardvark=9483, aardwolf=9483, Aaron=9483, Aaronic=9483, Aaronical=9483,
432
+ Aaronite=9483, Aaronitic=9483, Aaru=9483, Ab=9483, aba=9483, Ababdeh=9483,
433
+ Ababua=9483, abac=9483, abaca=9483, abacate=9483, abacay=9483,
434
+ abacinate=9483, abacination=9483, abaciscus=9483, abacist=9483,
435
+ aback=9483, abactinal=9483, abactinally=9483, abaction=9483, abactor=9483,
436
+ abaculus=9483, abacus=9483, Abadite=9483, abaff=9483, abaft=9483,
437
+ abaisance=9483, abaiser=9483, abaissed=9483, abalienate=9483,
438
+ abalienation=9483, abalone=9483, Abama=9483, abampere=9483, abandon=9483,
439
+ abandonable=9483, abandoned=9483, abandonedly=9483, abandonee=9483,
440
+ abandoner=9483, abandonment=9483, Abanic=9483, Abantes=9483,
441
+ abaptiston=9483, Abarambo=9483, Abaris=9483, abarthrosis=9483,
442
+ abarticular=9483, abarticulation=9483, abas=9483, abase=9483, abased=9483,
443
+ abasedly=9483, abasedness=9483, abasement=9483, abaser=9483, Abasgi=9483,
444
+ abash=9483, abashed=9483, abashedly=9483, abashedness=9483,
445
+ abashless=9483, abashlessly=9483, abashment=9483, abasia=9483,
446
+ abasic=9483, abask=9483, Abassin=9483, abastardize=9483, abatable=9483,
447
+ abate=9483, abatement=9483, abater=9483, abatis=9483, abatised=9483,
448
+ abaton=9483, abator=9483, abattoir=9483, Abatua=9483, abature=9483,
449
+ abave=9483, abaxial=9483, abaxile=9483, abaze=9483, abb=9483, Abba=9483,
450
+ abbacomes=9483, abbacy=9483, Abbadide=9483, abbas=9483, abbasi=9483,
451
+ abbassi=9483, Abbasside=9483, abbatial=9483, abbatical=9483, abbess=9483,
452
+ abbey=9483, abbeystede=9483, Abbie=9483, abbot=9483, abbotcy=9483,
453
+ abbotnullius=9483, abbotship=9483, abbreviate=9483, abbreviately=9483,
454
+ abbreviation=9483, abbreviator=9483, abbreviatory=9483, abbreviature=9483,
455
+ Abby=9483, abcoulomb=9483, abdal=9483, abdat=9483, Abderian=9483,
456
+ Abderite=9483, abdest=9483, abdicable=9483, abdicant=9483, abdicate=9483,
457
+ abdication=9483, abdicative=9483, abdicator=9483, Abdiel=9483,
458
+ abditive=9483, abditory=9483, abdomen=9483, abdominal=9483,
459
+ Abdominales=9483, abdominalian=9483, abdominally=9483,
460
+ abdominoanterior=9483, abdominocardiac=9483, abdominocentesis=9483,
461
+ abdominocystic=9483, abdominogenital=9483, abdominohysterectomy=9483,
462
+ abdominohysterotomy=9483, abdominoposterior=9483, abdominoscope=9483,
463
+ abdominoscopy=9483, abdominothoracic=9483, abdominous=9483,
464
+ abdominovaginal=9483, abdominovesical=9483, abduce=9483, abducens=9483,
465
+ abducent=9483, abduct=9483, abduction=9483, abductor=9483, Abe=9483,
466
+ abeam=9483, abear=9483, abearance=9483, abecedarian=9483,
467
+ abecedarium=9483, abecedary=9483, abed=9483, abeigh=9483, Abel=9483,
468
+ abele=9483, Abelia=9483, Abelian=9483, Abelicea=9483, Abelite=9483,
469
+ abelite=9483, Abelmoschus=9483, abelmosk=9483, Abelonian=9483,
470
+ abeltree=9483, Abencerrages=9483, abenteric=9483, abepithymia=9483,
471
+ Aberdeen=9483, aberdevine=9483, Aberdonian=9483, Aberia=9483,
472
+ aberrance=9483, aberrancy=9483, aberrant=9483, aberrate=9483,
473
+ aberration=9483, aberrational=9483, aberrator=9483, aberrometer=9483,
474
+ aberroscope=9483, aberuncator=9483, abet=9483, abetment=9483,
475
+ abettal=9483, abettor=9483, abevacuation=9483, abey=9483, abeyance=9483,
476
+ abeyancy=9483, abeyant=9483, abfarad=9483, abhenry=9483, abhiseka=9483,
477
+ abhominable=9483, abhor=9483, abhorrence=9483, abhorrency=9483,
478
+ abhorrent=9483, abhorrently=9483, abhorrer=9483, abhorrible=9483,
479
+ abhorring=9483, Abhorson=9483, abidal=9483, abidance=9483, abide=9483,
480
+ abider=9483, abidi=9483, abiding=9483, abidingly=9483, abidingness=9483,
481
+ Abie=9483, Abies=9483, abietate=9483, abietene=9483, abietic=9483,
482
+ abietin=9483, Abietineae=9483, abietineous=9483, abietinic=9483,
483
+ Abiezer=9483, Abigail=9483, abigail=9483, abigailship=9483, abigeat=9483,
484
+ abigeus=9483, abilao=9483, ability=9483, abilla=9483, abilo=9483,
485
+ abintestate=9483, abiogenesis=9483, abiogenesist=9483, abiogenetic=9483,
486
+ abiogenetical=9483, abiogenetically=9483, abiogenist=9483,
487
+ abiogenous=9483, abiogeny=9483, abiological=9483, abiologically=9483,
488
+ abiology=9483, abiosis=9483, abiotic=9483, abiotrophic=9483,
489
+ abiotrophy=9483, Abipon=9483, abir=9483, abirritant=9483, abirritate=9483,
490
+ abirritation=9483, abirritative=9483, abiston=9483, Abitibi=9483,
491
+ abiuret=9483, abject=9483, abjectedness=9483, abjection=9483,
492
+ abjective=9483, abjectly=9483, abjectness=9483, abjoint=9483,
493
+ abjudge=9483, abjudicate=9483, abjudication=9483, abjunction=9483,
494
+ abjunctive=9483, abjuration=9483, abjuratory=9483, abjure=9483,
495
+ abjurement=9483, abjurer=9483, abkar=9483, abkari=9483, Abkhas=9483,
496
+ Abkhasian=9483, ablach=9483, ablactate=9483, ablactation=9483,
497
+ ablare=9483, ablastemic=9483, ablastous=9483, ablate=9483, ablation=9483,
498
+ ablatitious=9483, ablatival=9483, ablative=9483, ablator=9483,
499
+ ablaut=9483, ablaze=9483, able=9483, ableeze=9483, ablegate=9483,
500
+ ableness=9483, ablepharia=9483, ablepharon=9483, ablepharous=9483,
501
+ Ablepharus=9483, ablepsia=9483, ableptical=9483, ableptically=9483,
502
+ abler=9483, ablest=9483, ablewhackets=9483, ablins=9483, abloom=9483,
503
+ ablow=9483, ablude=9483, abluent=9483, ablush=9483, ablution=9483,
504
+ ablutionary=9483, abluvion=9483, ably=9483, abmho=9483, Abnaki=9483,
505
+ abnegate=9483, abnegation=9483, abnegative=9483, abnegator=9483,
506
+ Abner=9483, abnerval=9483, abnet=9483, abneural=9483, abnormal=9483,
507
+ abnormalism=9483, abnormalist=9483, abnormality=9483, abnormalize=9483,
508
+ abnormally=9483, abnormalness=9483, abnormity=9483, abnormous=9483,
509
+ abnumerable=9483, Abo=9483, aboard=9483, Abobra=9483, abode=9483,
510
+ abodement=9483, abody=9483, abohm=9483, aboil=9483, abolish=9483,
511
+ abolisher=9483, abolishment=9483, abolition=9483, abolitionary=9483,
512
+ abolitionism=9483, abolitionist=9483, abolitionize=9483, abolla=9483,
513
+ aboma=9483, abomasum=9483, abomasus=9483, abominable=9483,
514
+ abominableness=9483, abominably=9483, abominate=9483, abomination=9483,
515
+ abominator=9483, abomine=9483, Abongo=9483, aboon=9483, aborad=9483,
516
+ aboral=9483, aborally=9483, abord=9483, aboriginal=9483,
517
+ aboriginality=9483, aboriginally=9483, aboriginary=9483, aborigine=9483,
518
+ abort=9483, aborted=9483, aborticide=9483, abortient=9483,
519
+ abortifacient=9483, abortin=9483, abortion=9483, abortional=9483,
520
+ abortionist=9483, abortive=9483, abortively=9483, abortiveness=9483,
521
+ abortus=9483, abouchement=9483, abound=9483, abounder=9483,
522
+ abounding=9483, aboundingly=9483, about=9483, abouts=9483, above=9483,
523
+ aboveboard=9483, abovedeck=9483, aboveground=9483, aboveproof=9483,
524
+ abovestairs=9483, abox=9483, abracadabra=9483, abrachia=9483,
525
+ abradant=9483, abrade=9483, abrader=9483, Abraham=9483, Abrahamic=9483,
526
+ Abrahamidae=9483, Abrahamite=9483, Abrahamitic=9483, abraid=9483,
527
+ Abram=9483, Abramis=9483, abranchial=9483, abranchialism=9483,
528
+ abranchian=9483, Abranchiata=9483, abranchiate=9483, abranchious=9483,
529
+ abrasax=9483, abrase=9483, abrash=9483, abrasiometer=9483, abrasion=9483,
530
+ abrasive=9483, abrastol=9483, abraum=9483, abraxas=9483, abreact=9483,
531
+ abreaction=9483, abreast=9483, abrenounce=9483, abret=9483, abrico=9483,
532
+ abridge=9483, abridgeable=9483, abridged=9483, abridgedly=9483,
533
+ abridger=9483, abridgment=9483, abrim=9483, abrin=9483, abristle=9483,
534
+ abroach=9483, abroad=9483, Abrocoma=9483, abrocome=9483, abrogable=9483,
535
+ abrogate=9483, abrogation=9483, abrogative=9483, abrogator=9483,
536
+ Abroma=9483, Abronia=9483, abrook=9483, abrotanum=9483, abrotine=9483,
537
+ abrupt=9483, abruptedly=9483, abruption=9483, abruptly=9483,
538
+ abruptness=9483, Abrus=9483, Absalom=9483, absampere=9483, Absaroka=9483,
539
+ absarokite=9483, abscess=9483, abscessed=9483, abscession=9483,
540
+ abscessroot=9483, abscind=9483, abscise=9483, abscision=9483,
541
+ absciss=9483, abscissa=9483, abscissae=9483, abscisse=9483,
542
+ abscission=9483, absconce=9483, abscond=9483, absconded=9483,
543
+ abscondedly=9483, abscondence=9483})
544
+
545
+ -- Test limited streaming
546
+ packed, offset = test_partial_unpack("unpack 1a out of 7", 1, "a", "b", "c", "d", "e", "f", "g")
547
+ packed, offset = test_partial_unpack("unpack 1b of remaining 7", 1, {p=packed,o=offset,remaining={"b"}})
548
+ packed, offset = test_partial_unpack("unpack 1c of remaining 7", 1, {p=packed,o=offset,remaining={"c"}})
549
+ packed, offset = test_partial_unpack("unpack 1d of remaining 7", 1, {p=packed,o=offset,remaining={"d"}})
550
+ packed, offset = test_partial_unpack("unpack 1e of remaining 7", 1, {p=packed,o=offset,remaining={"e"}})
551
+ packed, offset = test_partial_unpack("unpack 1f of remaining 7", 1, {p=packed,o=offset,remaining={"f"}})
552
+ packed, offset = test_partial_unpack("unpack 1g of remaining 7", 1, {p=packed,o=offset,remaining={"g"}})
553
+ packed, offset = test_partial_unpack("unpack 1nil of remaining 7", 0, {p=packed,o=offset})
554
+
555
+ packed, offset = test_partial_unpack("unpack 3 out of 7", 3, "a", "b", "c", "d", "e", "f", "g")
556
+ test_partial_unpack("unpack remaining 4", 4, {p=packed,o=offset,remaining={"d", "e", "f", "g"}})
557
+
558
+ test_unpack_one("simple", packed, "a")
559
+ offset = test_unpack_one("simple", cmsgpack.pack({f = 3, j = 2}, "m", "e", 7), {f = 3, j = 2})
560
+ test_unpack_one("simple", cmsgpack.pack({f = 3, j = 2}, "m", "e", 7), "m", offset)
561
+
562
+ -- Final report
563
+ print()
564
+ print("TEST PASSED:",passed)
565
+ print("TEST FAILED:",failed)
566
+ print("TEST SKIPPED:",skipped)
567
+
568
+ if failed > 0 then
569
+ os.exit(1)
570
+ end