diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2011-05-25 20:57:22 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2011-05-25 20:57:22 +0000 |
commit | 3a8ba90dfb0c2eb224f317dd692ede426691e72a (patch) | |
tree | fe1cc5379a2e0e031663fe9c15d908653844bc73 /test | |
parent | bce60be30fe8e9c1b0eb33128c23c93d7bca5303 (diff) | |
download | luasocket-3a8ba90dfb0c2eb224f317dd692ede426691e72a.tar.gz luasocket-3a8ba90dfb0c2eb224f317dd692ede426691e72a.tar.bz2 luasocket-3a8ba90dfb0c2eb224f317dd692ede426691e72a.zip |
Saving before big changes to support IPv6.
Diffstat (limited to 'test')
-rw-r--r-- | test/ftptest.lua | 8 | ||||
-rw-r--r-- | test/httptest.lua | 188 | ||||
-rw-r--r-- | test/smtptest.lua | 104 | ||||
-rw-r--r-- | test/testclnt.lua | 122 | ||||
-rw-r--r-- | test/testsupport.lua | 14 | ||||
-rw-r--r-- | test/urltest.lua | 620 | ||||
-rw-r--r-- | test/utestclnt.lua | 2 |
7 files changed, 543 insertions, 515 deletions
diff --git a/test/ftptest.lua b/test/ftptest.lua index f35e16f..fb13326 100644 --- a/test/ftptest.lua +++ b/test/ftptest.lua | |||
@@ -82,10 +82,10 @@ print("ok") | |||
82 | io.write("testing parameter overriding: ") | 82 | io.write("testing parameter overriding: ") |
83 | local back = {} | 83 | local back = {} |
84 | ret, err = ftp.get{ | 84 | ret, err = ftp.get{ |
85 | url = "//stupid:mistake@" .. host .. "/index.html", | 85 | url = "//stupid:mistake@" .. host .. "/index.html", |
86 | user = "luasocket", | 86 | user = "luasocket", |
87 | password = "pedrovian", | 87 | password = "pedrovian", |
88 | type = "i", | 88 | type = "i", |
89 | sink = ltn12.sink.table(back) | 89 | sink = ltn12.sink.table(back) |
90 | } | 90 | } |
91 | assert(ret and not err and table.concat(back) == index, err) | 91 | assert(ret and not err and table.concat(back) == index, err) |
diff --git a/test/httptest.lua b/test/httptest.lua index 9d50a14..614acf3 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -34,28 +34,28 @@ index_file = "index.html" | |||
34 | index = readfile(index_file) | 34 | index = readfile(index_file) |
35 | 35 | ||
36 | local check_result = function(response, expect, ignore) | 36 | local check_result = function(response, expect, ignore) |
37 | for i,v in pairs(response) do | 37 | for i,v in pairs(response) do |
38 | if not ignore[i] then | 38 | if not ignore[i] then |
39 | if v ~= expect[i] then | 39 | if v ~= expect[i] then |
40 | local f = io.open("err", "w") | 40 | local f = io.open("err", "w") |
41 | f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i])) | 41 | f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i])) |
42 | f:close() | 42 | f:close() |
43 | fail(i .. " differs!") | 43 | fail(i .. " differs!") |
44 | end | 44 | end |
45 | end | 45 | end |
46 | end | 46 | end |
47 | for i,v in pairs(expect) do | 47 | for i,v in pairs(expect) do |
48 | if not ignore[i] then | 48 | if not ignore[i] then |
49 | if v ~= response[i] then | 49 | if v ~= response[i] then |
50 | local f = io.open("err", "w") | 50 | local f = io.open("err", "w") |
51 | f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v)) | 51 | f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v)) |
52 | v = string.sub(type(v) == "string" and v or "", 1, 70) | 52 | v = string.sub(type(v) == "string" and v or "", 1, 70) |
53 | f:close() | 53 | f:close() |
54 | fail(i .. " differs!") | 54 | fail(i .. " differs!") |
55 | end | 55 | end |
56 | end | 56 | end |
57 | end | 57 | end |
58 | print("ok") | 58 | print("ok") |
59 | end | 59 | end |
60 | 60 | ||
61 | local check_request = function(request, expect, ignore) | 61 | local check_request = function(request, expect, ignore) |
@@ -63,7 +63,7 @@ local check_request = function(request, expect, ignore) | |||
63 | if not request.sink then request.sink, t = ltn12.sink.table() end | 63 | if not request.sink then request.sink, t = ltn12.sink.table() end |
64 | request.source = request.source or | 64 | request.source = request.source or |
65 | (request.body and ltn12.source.string(request.body)) | 65 | (request.body and ltn12.source.string(request.body)) |
66 | local response = {} | 66 | local response = {} |
67 | response.code, response.headers, response.status = | 67 | response.code, response.headers, response.status = |
68 | socket.skip(1, http.request(request)) | 68 | socket.skip(1, http.request(request)) |
69 | if t and table.getn(t) > 0 then response.body = table.concat(t) end | 69 | if t and table.getn(t) > 0 then response.body = table.concat(t) end |
@@ -90,15 +90,15 @@ else fail("failed!") end | |||
90 | ------------------------------------------------------------------------ | 90 | ------------------------------------------------------------------------ |
91 | io.write("testing document retrieval: ") | 91 | io.write("testing document retrieval: ") |
92 | request = { | 92 | request = { |
93 | url = "http://" .. host .. prefix .. "/index.html" | 93 | url = "http://" .. host .. prefix .. "/index.html" |
94 | } | 94 | } |
95 | expect = { | 95 | expect = { |
96 | body = index, | 96 | body = index, |
97 | code = 200 | 97 | code = 200 |
98 | } | 98 | } |
99 | ignore = { | 99 | ignore = { |
100 | status = 1, | 100 | status = 1, |
101 | headers = 1 | 101 | headers = 1 |
102 | } | 102 | } |
103 | check_request(request, expect, ignore) | 103 | check_request(request, expect, ignore) |
104 | 104 | ||
@@ -111,9 +111,9 @@ expect = { | |||
111 | code = 302 | 111 | code = 302 |
112 | } | 112 | } |
113 | ignore = { | 113 | ignore = { |
114 | status = 1, | 114 | status = 1, |
115 | headers = 1, | 115 | headers = 1, |
116 | body = 1 | 116 | body = 1 |
117 | } | 117 | } |
118 | check_request(request, expect, ignore) | 118 | check_request(request, expect, ignore) |
119 | 119 | ||
@@ -144,19 +144,19 @@ check_request(request, expect, ignore) | |||
144 | io.write("testing post method: ") | 144 | io.write("testing post method: ") |
145 | -- wanted to test chunked post, but apache doesn't support it... | 145 | -- wanted to test chunked post, but apache doesn't support it... |
146 | request = { | 146 | request = { |
147 | url = "http://" .. host .. cgiprefix .. "/cat", | 147 | url = "http://" .. host .. cgiprefix .. "/cat", |
148 | method = "POST", | 148 | method = "POST", |
149 | body = index, | 149 | body = index, |
150 | -- remove content-length header to send chunked body | 150 | -- remove content-length header to send chunked body |
151 | headers = { ["content-length"] = string.len(index) } | 151 | headers = { ["content-length"] = string.len(index) } |
152 | } | 152 | } |
153 | expect = { | 153 | expect = { |
154 | body = index, | 154 | body = index, |
155 | code = 200 | 155 | code = 200 |
156 | } | 156 | } |
157 | ignore = { | 157 | ignore = { |
158 | status = 1, | 158 | status = 1, |
159 | headers = 1 | 159 | headers = 1 |
160 | } | 160 | } |
161 | check_request(request, expect, ignore) | 161 | check_request(request, expect, ignore) |
162 | 162 | ||
@@ -164,19 +164,19 @@ check_request(request, expect, ignore) | |||
164 | --[[ | 164 | --[[ |
165 | io.write("testing proxy with post method: ") | 165 | io.write("testing proxy with post method: ") |
166 | request = { | 166 | request = { |
167 | url = "http://" .. host .. cgiprefix .. "/cat", | 167 | url = "http://" .. host .. cgiprefix .. "/cat", |
168 | method = "POST", | 168 | method = "POST", |
169 | body = index, | 169 | body = index, |
170 | headers = { ["content-length"] = string.len(index) }, | 170 | headers = { ["content-length"] = string.len(index) }, |
171 | proxy= proxy | 171 | proxy= proxy |
172 | } | 172 | } |
173 | expect = { | 173 | expect = { |
174 | body = index, | 174 | body = index, |
175 | code = 200 | 175 | code = 200 |
176 | } | 176 | } |
177 | ignore = { | 177 | ignore = { |
178 | status = 1, | 178 | status = 1, |
179 | headers = 1 | 179 | headers = 1 |
180 | } | 180 | } |
181 | check_request(request, expect, ignore) | 181 | check_request(request, expect, ignore) |
182 | ]] | 182 | ]] |
@@ -190,18 +190,18 @@ print("ok") | |||
190 | ------------------------------------------------------------------------ | 190 | ------------------------------------------------------------------------ |
191 | io.write("testing ltn12.(sink|source).file: ") | 191 | io.write("testing ltn12.(sink|source).file: ") |
192 | request = { | 192 | request = { |
193 | url = "http://" .. host .. cgiprefix .. "/cat", | 193 | url = "http://" .. host .. cgiprefix .. "/cat", |
194 | method = "POST", | 194 | method = "POST", |
195 | source = ltn12.source.file(io.open(index_file, "rb")), | 195 | source = ltn12.source.file(io.open(index_file, "rb")), |
196 | sink = ltn12.sink.file(io.open(index_file .. "-back", "wb")), | 196 | sink = ltn12.sink.file(io.open(index_file .. "-back", "wb")), |
197 | headers = { ["content-length"] = string.len(index) } | 197 | headers = { ["content-length"] = string.len(index) } |
198 | } | 198 | } |
199 | expect = { | 199 | expect = { |
200 | code = 200 | 200 | code = 200 |
201 | } | 201 | } |
202 | ignore = { | 202 | ignore = { |
203 | status = 1, | 203 | status = 1, |
204 | headers = 1 | 204 | headers = 1 |
205 | } | 205 | } |
206 | check_request(request, expect, ignore) | 206 | check_request(request, expect, ignore) |
207 | back = readfile(index_file .. "-back") | 207 | back = readfile(index_file .. "-back") |
@@ -231,19 +231,19 @@ local sink = ltn12.sink.chain( | |||
231 | ) | 231 | ) |
232 | 232 | ||
233 | request = { | 233 | request = { |
234 | url = "http://" .. host .. cgiprefix .. "/cat", | 234 | url = "http://" .. host .. cgiprefix .. "/cat", |
235 | method = "POST", | 235 | method = "POST", |
236 | source = source, | 236 | source = source, |
237 | sink = sink, | 237 | sink = sink, |
238 | headers = { ["content-length"] = b64length(string.len(index)) } | 238 | headers = { ["content-length"] = b64length(string.len(index)) } |
239 | } | 239 | } |
240 | expect = { | 240 | expect = { |
241 | code = 200 | 241 | code = 200 |
242 | } | 242 | } |
243 | ignore = { | 243 | ignore = { |
244 | body_cb = 1, | 244 | body_cb = 1, |
245 | status = 1, | 245 | status = 1, |
246 | headers = 1 | 246 | headers = 1 |
247 | } | 247 | } |
248 | check_request(request, expect, ignore) | 248 | check_request(request, expect, ignore) |
249 | back = readfile(index_file .. "-back") | 249 | back = readfile(index_file .. "-back") |
@@ -253,15 +253,15 @@ os.remove(index_file .. "-back") | |||
253 | ------------------------------------------------------------------------ | 253 | ------------------------------------------------------------------------ |
254 | io.write("testing http redirection: ") | 254 | io.write("testing http redirection: ") |
255 | request = { | 255 | request = { |
256 | url = "http://" .. host .. prefix | 256 | url = "http://" .. host .. prefix |
257 | } | 257 | } |
258 | expect = { | 258 | expect = { |
259 | body = index, | 259 | body = index, |
260 | code = 200 | 260 | code = 200 |
261 | } | 261 | } |
262 | ignore = { | 262 | ignore = { |
263 | status = 1, | 263 | status = 1, |
264 | headers = 1 | 264 | headers = 1 |
265 | } | 265 | } |
266 | check_request(request, expect, ignore) | 266 | check_request(request, expect, ignore) |
267 | 267 | ||
@@ -269,16 +269,16 @@ check_request(request, expect, ignore) | |||
269 | --[[ | 269 | --[[ |
270 | io.write("testing proxy with redirection: ") | 270 | io.write("testing proxy with redirection: ") |
271 | request = { | 271 | request = { |
272 | url = "http://" .. host .. prefix, | 272 | url = "http://" .. host .. prefix, |
273 | proxy = proxy | 273 | proxy = proxy |
274 | } | 274 | } |
275 | expect = { | 275 | expect = { |
276 | body = index, | 276 | body = index, |
277 | code = 200 | 277 | code = 200 |
278 | } | 278 | } |
279 | ignore = { | 279 | ignore = { |
280 | status = 1, | 280 | status = 1, |
281 | headers = 1 | 281 | headers = 1 |
282 | } | 282 | } |
283 | check_request(request, expect, ignore) | 283 | check_request(request, expect, ignore) |
284 | ]] | 284 | ]] |
@@ -293,104 +293,104 @@ expect = { | |||
293 | } | 293 | } |
294 | ignore = { | 294 | ignore = { |
295 | body = 1, | 295 | body = 1, |
296 | status = 1, | 296 | status = 1, |
297 | headers = 1 | 297 | headers = 1 |
298 | } | 298 | } |
299 | check_request(request, expect, ignore) | 299 | check_request(request, expect, ignore) |
300 | 300 | ||
301 | ------------------------------------------------------------------------ | 301 | ------------------------------------------------------------------------ |
302 | io.write("testing http redirection failure: ") | 302 | io.write("testing http redirection failure: ") |
303 | request = { | 303 | request = { |
304 | url = "http://" .. host .. prefix, | 304 | url = "http://" .. host .. prefix, |
305 | redirect = false | 305 | redirect = false |
306 | } | 306 | } |
307 | expect = { | 307 | expect = { |
308 | code = 301 | 308 | code = 301 |
309 | } | 309 | } |
310 | ignore = { | 310 | ignore = { |
311 | body = 1, | 311 | body = 1, |
312 | status = 1, | 312 | status = 1, |
313 | headers = 1 | 313 | headers = 1 |
314 | } | 314 | } |
315 | check_request(request, expect, ignore) | 315 | check_request(request, expect, ignore) |
316 | 316 | ||
317 | ------------------------------------------------------------------------ | 317 | ------------------------------------------------------------------------ |
318 | io.write("testing document not found: ") | 318 | io.write("testing document not found: ") |
319 | request = { | 319 | request = { |
320 | url = "http://" .. host .. "/wrongdocument.html" | 320 | url = "http://" .. host .. "/wrongdocument.html" |
321 | } | 321 | } |
322 | expect = { | 322 | expect = { |
323 | code = 404 | 323 | code = 404 |
324 | } | 324 | } |
325 | ignore = { | 325 | ignore = { |
326 | body = 1, | 326 | body = 1, |
327 | status = 1, | 327 | status = 1, |
328 | headers = 1 | 328 | headers = 1 |
329 | } | 329 | } |
330 | check_request(request, expect, ignore) | 330 | check_request(request, expect, ignore) |
331 | 331 | ||
332 | ------------------------------------------------------------------------ | 332 | ------------------------------------------------------------------------ |
333 | io.write("testing auth failure: ") | 333 | io.write("testing auth failure: ") |
334 | request = { | 334 | request = { |
335 | url = "http://" .. host .. prefix .. "/auth/index.html" | 335 | url = "http://" .. host .. prefix .. "/auth/index.html" |
336 | } | 336 | } |
337 | expect = { | 337 | expect = { |
338 | code = 401 | 338 | code = 401 |
339 | } | 339 | } |
340 | ignore = { | 340 | ignore = { |
341 | body = 1, | 341 | body = 1, |
342 | status = 1, | 342 | status = 1, |
343 | headers = 1 | 343 | headers = 1 |
344 | } | 344 | } |
345 | check_request(request, expect, ignore) | 345 | check_request(request, expect, ignore) |
346 | 346 | ||
347 | ------------------------------------------------------------------------ | 347 | ------------------------------------------------------------------------ |
348 | io.write("testing manual basic auth: ") | 348 | io.write("testing manual basic auth: ") |
349 | request = { | 349 | request = { |
350 | url = "http://" .. host .. prefix .. "/auth/index.html", | 350 | url = "http://" .. host .. prefix .. "/auth/index.html", |
351 | headers = { | 351 | headers = { |
352 | authorization = "Basic " .. (mime.b64("luasocket:password")) | 352 | authorization = "Basic " .. (mime.b64("luasocket:password")) |
353 | } | 353 | } |
354 | } | 354 | } |
355 | expect = { | 355 | expect = { |
356 | code = 200, | 356 | code = 200, |
357 | body = index | 357 | body = index |
358 | } | 358 | } |
359 | ignore = { | 359 | ignore = { |
360 | status = 1, | 360 | status = 1, |
361 | headers = 1 | 361 | headers = 1 |
362 | } | 362 | } |
363 | check_request(request, expect, ignore) | 363 | check_request(request, expect, ignore) |
364 | 364 | ||
365 | ------------------------------------------------------------------------ | 365 | ------------------------------------------------------------------------ |
366 | io.write("testing automatic basic auth: ") | 366 | io.write("testing automatic basic auth: ") |
367 | request = { | 367 | request = { |
368 | url = "http://luasocket:password@" .. host .. prefix .. "/auth/index.html" | 368 | url = "http://luasocket:password@" .. host .. prefix .. "/auth/index.html" |
369 | } | 369 | } |
370 | expect = { | 370 | expect = { |
371 | code = 200, | 371 | code = 200, |
372 | body = index | 372 | body = index |
373 | } | 373 | } |
374 | ignore = { | 374 | ignore = { |
375 | status = 1, | 375 | status = 1, |
376 | headers = 1 | 376 | headers = 1 |
377 | } | 377 | } |
378 | check_request(request, expect, ignore) | 378 | check_request(request, expect, ignore) |
379 | 379 | ||
380 | ------------------------------------------------------------------------ | 380 | ------------------------------------------------------------------------ |
381 | io.write("testing auth info overriding: ") | 381 | io.write("testing auth info overriding: ") |
382 | request = { | 382 | request = { |
383 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", | 383 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", |
384 | user = "luasocket", | 384 | user = "luasocket", |
385 | password = "password" | 385 | password = "password" |
386 | } | 386 | } |
387 | expect = { | 387 | expect = { |
388 | code = 200, | 388 | code = 200, |
389 | body = index | 389 | body = index |
390 | } | 390 | } |
391 | ignore = { | 391 | ignore = { |
392 | status = 1, | 392 | status = 1, |
393 | headers = 1 | 393 | headers = 1 |
394 | } | 394 | } |
395 | check_request(request, expect, ignore) | 395 | check_request(request, expect, ignore) |
396 | 396 | ||
@@ -400,12 +400,12 @@ request = { | |||
400 | url = "http://" .. host .. cgiprefix .. "/cat-index-html" | 400 | url = "http://" .. host .. cgiprefix .. "/cat-index-html" |
401 | } | 401 | } |
402 | expect = { | 402 | expect = { |
403 | body = index, | 403 | body = index, |
404 | code = 200 | 404 | code = 200 |
405 | } | 405 | } |
406 | ignore = { | 406 | ignore = { |
407 | status = 1, | 407 | status = 1, |
408 | headers = 1 | 408 | headers = 1 |
409 | } | 409 | } |
410 | check_request(request, expect, ignore) | 410 | check_request(request, expect, ignore) |
411 | 411 | ||
diff --git a/test/smtptest.lua b/test/smtptest.lua index d0c938c..5f0e0e5 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
@@ -19,11 +19,11 @@ local parse = mbox.parse | |||
19 | dofile("testsupport.lua") | 19 | dofile("testsupport.lua") |
20 | 20 | ||
21 | local total = function() | 21 | local total = function() |
22 | local t = 0 | 22 | local t = 0 |
23 | for i = 1, table.getn(sent) do | 23 | for i = 1, table.getn(sent) do |
24 | t = t + sent[i].count | 24 | t = t + sent[i].count |
25 | end | 25 | end |
26 | return t | 26 | return t |
27 | end | 27 | end |
28 | 28 | ||
29 | local similar = function(s1, s2) | 29 | local similar = function(s1, s2) |
@@ -39,14 +39,14 @@ local fail = function(s) | |||
39 | end | 39 | end |
40 | 40 | ||
41 | local readfile = function(name) | 41 | local readfile = function(name) |
42 | local f = io.open(name, "r") | 42 | local f = io.open(name, "r") |
43 | if not f then | 43 | if not f then |
44 | fail("unable to open file!") | 44 | fail("unable to open file!") |
45 | return nil | 45 | return nil |
46 | end | 46 | end |
47 | local s = f:read("*a") | 47 | local s = f:read("*a") |
48 | f:close() | 48 | f:close() |
49 | return s | 49 | return s |
50 | end | 50 | end |
51 | 51 | ||
52 | local empty = function() | 52 | local empty = function() |
@@ -62,7 +62,7 @@ end | |||
62 | local get = function() | 62 | local get = function() |
63 | local s = "" | 63 | local s = "" |
64 | for i,v in ipairs(files) do | 64 | for i,v in ipairs(files) do |
65 | s = s .. "\n" .. readfile(v) | 65 | s = s .. "\n" .. readfile(v) |
66 | end | 66 | end |
67 | return s | 67 | return s |
68 | end | 68 | end |
@@ -82,40 +82,40 @@ local check_body = function(sent, got) | |||
82 | end | 82 | end |
83 | 83 | ||
84 | local check = function(sent, m) | 84 | local check = function(sent, m) |
85 | io.write("checking ", m.headers.title, ": ") | 85 | io.write("checking ", m.headers.title, ": ") |
86 | for i = 1, table.getn(sent) do | 86 | for i = 1, table.getn(sent) do |
87 | local s = sent[i] | 87 | local s = sent[i] |
88 | if s.title == m.headers.title and s.count > 0 then | 88 | if s.title == m.headers.title and s.count > 0 then |
89 | check_headers(s.headers, m.headers) | 89 | check_headers(s.headers, m.headers) |
90 | check_body(s.body, m.body) | 90 | check_body(s.body, m.body) |
91 | s.count = s.count - 1 | 91 | s.count = s.count - 1 |
92 | print("ok") | 92 | print("ok") |
93 | return | 93 | return |
94 | end | 94 | end |
95 | end | 95 | end |
96 | fail("not found") | 96 | fail("not found") |
97 | end | 97 | end |
98 | 98 | ||
99 | local insert = function(sent, message) | 99 | local insert = function(sent, message) |
100 | if type(message.rcpt) == "table" then | 100 | if type(message.rcpt) == "table" then |
101 | message.count = table.getn(message.rcpt) | 101 | message.count = table.getn(message.rcpt) |
102 | else message.count = 1 end | 102 | else message.count = 1 end |
103 | message.headers = message.headers or {} | 103 | message.headers = message.headers or {} |
104 | message.headers.title = message.title | 104 | message.headers.title = message.title |
105 | table.insert(sent, message) | 105 | table.insert(sent, message) |
106 | end | 106 | end |
107 | 107 | ||
108 | local mark = function() | 108 | local mark = function() |
109 | local time = socket.time() | 109 | local time = socket.time() |
110 | return { time = time } | 110 | return { time = time } |
111 | end | 111 | end |
112 | 112 | ||
113 | local wait = function(sentinel, n) | 113 | local wait = function(sentinel, n) |
114 | local to | 114 | local to |
115 | io.write("waiting for ", n, " messages: ") | 115 | io.write("waiting for ", n, " messages: ") |
116 | while 1 do | 116 | while 1 do |
117 | local mbox = parse(get()) | 117 | local mbox = parse(get()) |
118 | if n == table.getn(mbox) then break end | 118 | if n == table.getn(mbox) then break end |
119 | if socket.time() - sentinel.time > 50 then | 119 | if socket.time() - sentinel.time > 50 then |
120 | to = 1 | 120 | to = 1 |
121 | break | 121 | break |
@@ -124,8 +124,8 @@ local wait = function(sentinel, n) | |||
124 | io.write(".") | 124 | io.write(".") |
125 | io.stdout:flush() | 125 | io.stdout:flush() |
126 | end | 126 | end |
127 | if to then fail("timeout") | 127 | if to then fail("timeout") |
128 | else print("ok") end | 128 | else print("ok") end |
129 | end | 129 | end |
130 | 130 | ||
131 | local stuffed_body = [[ | 131 | local stuffed_body = [[ |
@@ -144,21 +144,21 @@ a lot of trouble. | |||
144 | insert(sent, { | 144 | insert(sent, { |
145 | from = from, | 145 | from = from, |
146 | rcpt = { | 146 | rcpt = { |
147 | "luasocket@localhost", | 147 | "luasocket@localhost", |
148 | "luasock3@dell-diego.cs.princeton.edu", | 148 | "luasock3@dell-diego.cs.princeton.edu", |
149 | "luasock1@dell-diego.cs.princeton.edu" | 149 | "luasock1@dell-diego.cs.princeton.edu" |
150 | }, | 150 | }, |
151 | body = "multiple rcpt body", | 151 | body = "multiple rcpt body", |
152 | title = "multiple rcpt", | 152 | title = "multiple rcpt", |
153 | }) | 153 | }) |
154 | 154 | ||
155 | insert(sent, { | 155 | insert(sent, { |
156 | from = from, | 156 | from = from, |
157 | rcpt = { | 157 | rcpt = { |
158 | "luasock2@localhost", | 158 | "luasock2@localhost", |
159 | "luasock3", | 159 | "luasock3", |
160 | "luasock1" | 160 | "luasock1" |
161 | }, | 161 | }, |
162 | headers = { | 162 | headers = { |
163 | header1 = "header 1", | 163 | header1 = "header 1", |
164 | header2 = "header 2", | 164 | header2 = "header 2", |
@@ -210,24 +210,24 @@ insert(sent, { | |||
210 | io.write("testing host not found: ") | 210 | io.write("testing host not found: ") |
211 | local c, e = socket.connect("wrong.host", 25) | 211 | local c, e = socket.connect("wrong.host", 25) |
212 | local ret, err = socket.smtp.mail{ | 212 | local ret, err = socket.smtp.mail{ |
213 | from = from, | 213 | from = from, |
214 | rcpt = rcpt, | 214 | rcpt = rcpt, |
215 | server = "wrong.host" | 215 | server = "wrong.host" |
216 | } | 216 | } |
217 | if ret or e ~= err then fail("wrong error message") | 217 | if ret or e ~= err then fail("wrong error message") |
218 | else print("ok") end | 218 | else print("ok") end |
219 | 219 | ||
220 | io.write("testing invalid from: ") | 220 | io.write("testing invalid from: ") |
221 | local ret, err = socket.smtp.mail{ | 221 | local ret, err = socket.smtp.mail{ |
222 | from = ' " " (( _ * ', | 222 | from = ' " " (( _ * ', |
223 | rcpt = rcpt, | 223 | rcpt = rcpt, |
224 | } | 224 | } |
225 | if ret or not err then fail("wrong error message") | 225 | if ret or not err then fail("wrong error message") |
226 | else print(err) end | 226 | else print(err) end |
227 | 227 | ||
228 | io.write("testing no rcpt: ") | 228 | io.write("testing no rcpt: ") |
229 | local ret, err = socket.smtp.mail{ | 229 | local ret, err = socket.smtp.mail{ |
230 | from = from, | 230 | from = from, |
231 | } | 231 | } |
232 | if ret or not err then fail("wrong error message") | 232 | if ret or not err then fail("wrong error message") |
233 | else print(err) end | 233 | else print(err) end |
@@ -252,7 +252,7 @@ local mbox = parse(get()) | |||
252 | print(table.getn(mbox) .. " messages found!") | 252 | print(table.getn(mbox) .. " messages found!") |
253 | 253 | ||
254 | for i = 1, table.getn(mbox) do | 254 | for i = 1, table.getn(mbox) do |
255 | check(sent, mbox[i]) | 255 | check(sent, mbox[i]) |
256 | end | 256 | end |
257 | 257 | ||
258 | print("passed all tests") | 258 | print("passed all tests") |
diff --git a/test/testclnt.lua b/test/testclnt.lua index 1f03b10..4c2f211 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
@@ -3,15 +3,20 @@ local socket = require"socket" | |||
3 | host = host or "localhost" | 3 | host = host or "localhost" |
4 | port = port or "8383" | 4 | port = port or "8383" |
5 | 5 | ||
6 | function pass(...) | 6 | function printf(...) |
7 | local s = string.format(unpack(arg)) | 7 | local s = string.format(unpack(arg)) |
8 | io.stderr:write(s, "\n") | 8 | io.stderr:write(s) |
9 | end | ||
10 | |||
11 | function pass(...) | ||
12 | printf(...) | ||
13 | io.stderr:write("\n") | ||
9 | end | 14 | end |
10 | 15 | ||
11 | function fail(...) | 16 | function fail(...) |
12 | local s = string.format(unpack(arg)) | 17 | io.stderr:write("ERROR: ") |
13 | io.stderr:write("ERROR: ", s, "!\n") | 18 | printf(...) |
14 | socket.sleep(3) | 19 | io.stderr:write("!\n") |
15 | os.exit() | 20 | os.exit() |
16 | end | 21 | end |
17 | 22 | ||
@@ -80,7 +85,6 @@ io.stderr:write("----------------------------------------------\n", | |||
80 | start = socket.gettime() | 85 | start = socket.gettime() |
81 | 86 | ||
82 | function reconnect() | 87 | function reconnect() |
83 | io.stderr:write("attempting data connection... ") | ||
84 | if data then data:close() end | 88 | if data then data:close() end |
85 | remote [[ | 89 | remote [[ |
86 | if data then data:close() data = nil end | 90 | if data then data:close() data = nil end |
@@ -88,12 +92,11 @@ function reconnect() | |||
88 | data:setoption("tcp-nodelay", true) | 92 | data:setoption("tcp-nodelay", true) |
89 | ]] | 93 | ]] |
90 | data, err = socket.connect(host, port) | 94 | data, err = socket.connect(host, port) |
91 | if not data then fail(err) | 95 | if not data then fail(err) end |
92 | else pass("connected!") end | ||
93 | data:setoption("tcp-nodelay", true) | 96 | data:setoption("tcp-nodelay", true) |
94 | end | 97 | end |
95 | 98 | ||
96 | pass("attempting control connection...") | 99 | printf("attempting control connection...") |
97 | control, err = socket.connect(host, port) | 100 | control, err = socket.connect(host, port) |
98 | if err then fail(err) | 101 | if err then fail(err) |
99 | else pass("connected!") end | 102 | else pass("connected!") end |
@@ -112,6 +115,7 @@ end | |||
112 | ------------------------------------------------------------------------ | 115 | ------------------------------------------------------------------------ |
113 | function test_mixed(len) | 116 | function test_mixed(len) |
114 | reconnect() | 117 | reconnect() |
118 | io.stderr:write("length " .. len .. ": ") | ||
115 | local inter = math.ceil(len/4) | 119 | local inter = math.ceil(len/4) |
116 | local p1 = "unix " .. string.rep("x", inter) .. "line\n" | 120 | local p1 = "unix " .. string.rep("x", inter) .. "line\n" |
117 | local p2 = "dos " .. string.rep("y", inter) .. "line\r\n" | 121 | local p2 = "dos " .. string.rep("y", inter) .. "line\r\n" |
@@ -139,6 +143,7 @@ end | |||
139 | ------------------------------------------------------------------------ | 143 | ------------------------------------------------------------------------ |
140 | function test_asciiline(len) | 144 | function test_asciiline(len) |
141 | reconnect() | 145 | reconnect() |
146 | io.stderr:write("length " .. len .. ": ") | ||
142 | local str, str10, back, err | 147 | local str, str10, back, err |
143 | str = string.rep("x", math.mod(len, 10)) | 148 | str = string.rep("x", math.mod(len, 10)) |
144 | str10 = string.rep("aZb.c#dAe?", math.floor(len/10)) | 149 | str10 = string.rep("aZb.c#dAe?", math.floor(len/10)) |
@@ -156,6 +161,7 @@ end | |||
156 | ------------------------------------------------------------------------ | 161 | ------------------------------------------------------------------------ |
157 | function test_rawline(len) | 162 | function test_rawline(len) |
158 | reconnect() | 163 | reconnect() |
164 | io.stderr:write("length " .. len .. ": ") | ||
159 | local str, str10, back, err | 165 | local str, str10, back, err |
160 | str = string.rep(string.char(47), math.mod(len, 10)) | 166 | str = string.rep(string.char(47), math.mod(len, 10)) |
161 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), | 167 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), |
@@ -174,6 +180,7 @@ end | |||
174 | ------------------------------------------------------------------------ | 180 | ------------------------------------------------------------------------ |
175 | function test_raw(len) | 181 | function test_raw(len) |
176 | reconnect() | 182 | reconnect() |
183 | io.stderr:write("length " .. len .. ": ") | ||
177 | local half = math.floor(len/2) | 184 | local half = math.floor(len/2) |
178 | local s1, s2, back, err | 185 | local s1, s2, back, err |
179 | s1 = string.rep("x", half) | 186 | s1 = string.rep("x", half) |
@@ -194,7 +201,7 @@ end | |||
194 | function test_totaltimeoutreceive(len, tm, sl) | 201 | function test_totaltimeoutreceive(len, tm, sl) |
195 | reconnect() | 202 | reconnect() |
196 | local str, err, partial | 203 | local str, err, partial |
197 | pass("%d bytes, %ds total timeout, %ds pause", len, tm, sl) | 204 | printf("%d bytes, %ds total timeout, %ds pause: ", len, tm, sl) |
198 | remote (string.format ([[ | 205 | remote (string.format ([[ |
199 | data:settimeout(%d) | 206 | data:settimeout(%d) |
200 | str = string.rep('a', %d) | 207 | str = string.rep('a', %d) |
@@ -215,7 +222,7 @@ end | |||
215 | function test_totaltimeoutsend(len, tm, sl) | 222 | function test_totaltimeoutsend(len, tm, sl) |
216 | reconnect() | 223 | reconnect() |
217 | local str, err, total | 224 | local str, err, total |
218 | pass("%d bytes, %ds total timeout, %ds pause", len, tm, sl) | 225 | printf("%d bytes, %ds total timeout, %ds pause: ", len, tm, sl) |
219 | remote (string.format ([[ | 226 | remote (string.format ([[ |
220 | data:settimeout(%d) | 227 | data:settimeout(%d) |
221 | str = data:receive(%d) | 228 | str = data:receive(%d) |
@@ -235,7 +242,7 @@ end | |||
235 | function test_blockingtimeoutreceive(len, tm, sl) | 242 | function test_blockingtimeoutreceive(len, tm, sl) |
236 | reconnect() | 243 | reconnect() |
237 | local str, err, partial | 244 | local str, err, partial |
238 | pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) | 245 | printf("%d bytes, %ds blocking timeout, %ds pause: ", len, tm, sl) |
239 | remote (string.format ([[ | 246 | remote (string.format ([[ |
240 | data:settimeout(%d) | 247 | data:settimeout(%d) |
241 | str = string.rep('a', %d) | 248 | str = string.rep('a', %d) |
@@ -255,7 +262,7 @@ end | |||
255 | function test_blockingtimeoutsend(len, tm, sl) | 262 | function test_blockingtimeoutsend(len, tm, sl) |
256 | reconnect() | 263 | reconnect() |
257 | local str, err, total | 264 | local str, err, total |
258 | pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) | 265 | printf("%d bytes, %ds blocking timeout, %ds pause: ", len, tm, sl) |
259 | remote (string.format ([[ | 266 | remote (string.format ([[ |
260 | data:settimeout(%d) | 267 | data:settimeout(%d) |
261 | str = data:receive(%d) | 268 | str = data:receive(%d) |
@@ -273,6 +280,7 @@ end | |||
273 | 280 | ||
274 | ------------------------------------------------------------------------ | 281 | ------------------------------------------------------------------------ |
275 | function empty_connect() | 282 | function empty_connect() |
283 | printf("empty connect: ") | ||
276 | reconnect() | 284 | reconnect() |
277 | if data then data:close() data = nil end | 285 | if data then data:close() data = nil end |
278 | remote [[ | 286 | remote [[ |
@@ -284,7 +292,7 @@ function empty_connect() | |||
284 | pass("ok") | 292 | pass("ok") |
285 | data = socket.connect(host, port) | 293 | data = socket.connect(host, port) |
286 | else | 294 | else |
287 | pass("gethostbyname returns localhost on empty string...") | 295 | pass("gethostbyname returns localhost on empty string...") |
288 | end | 296 | end |
289 | end | 297 | end |
290 | 298 | ||
@@ -311,7 +319,7 @@ function test_closed() | |||
311 | local back, partial, err | 319 | local back, partial, err |
312 | local str = 'little string' | 320 | local str = 'little string' |
313 | reconnect() | 321 | reconnect() |
314 | pass("trying read detection") | 322 | printf("trying read detection: ") |
315 | remote (string.format ([[ | 323 | remote (string.format ([[ |
316 | data:send('%s') | 324 | data:send('%s') |
317 | data:close() | 325 | data:close() |
@@ -324,7 +332,7 @@ function test_closed() | |||
324 | elseif str ~= partial then fail("didn't receive partial result.") | 332 | elseif str ~= partial then fail("didn't receive partial result.") |
325 | else pass("graceful 'closed' received") end | 333 | else pass("graceful 'closed' received") end |
326 | reconnect() | 334 | reconnect() |
327 | pass("trying write detection") | 335 | printf("trying write detection: ") |
328 | remote [[ | 336 | remote [[ |
329 | data:close() | 337 | data:close() |
330 | data = nil | 338 | data = nil |
@@ -342,7 +350,6 @@ end | |||
342 | ------------------------------------------------------------------------ | 350 | ------------------------------------------------------------------------ |
343 | function test_selectbugs() | 351 | function test_selectbugs() |
344 | local r, s, e = socket.select(nil, nil, 0.1) | 352 | local r, s, e = socket.select(nil, nil, 0.1) |
345 | print(r, s, e) | ||
346 | assert(type(r) == "table" and type(s) == "table" and | 353 | assert(type(r) == "table" and type(s) == "table" and |
347 | (e == "timeout" or e == "error")) | 354 | (e == "timeout" or e == "error")) |
348 | pass("both nil: ok") | 355 | pass("both nil: ok") |
@@ -374,7 +381,7 @@ end | |||
374 | 381 | ||
375 | ------------------------------------------------------------------------ | 382 | ------------------------------------------------------------------------ |
376 | function accept_timeout() | 383 | function accept_timeout() |
377 | io.stderr:write("accept with timeout (if it hangs, it failed): ") | 384 | printf("accept with timeout (if it hangs, it failed): ") |
378 | local s, e = socket.bind("*", 0, 0) | 385 | local s, e = socket.bind("*", 0, 0) |
379 | assert(s, e) | 386 | assert(s, e) |
380 | local t = socket.gettime() | 387 | local t = socket.gettime() |
@@ -390,23 +397,22 @@ end | |||
390 | 397 | ||
391 | ------------------------------------------------------------------------ | 398 | ------------------------------------------------------------------------ |
392 | function connect_timeout() | 399 | function connect_timeout() |
393 | io.stderr:write("connect with timeout (if it hangs, it failed!): ") | 400 | printf("connect with timeout (if it hangs, it failed!): ") |
394 | local t = socket.gettime() | 401 | local t = socket.gettime() |
395 | local c, e = socket.tcp() | 402 | local c, e = socket.tcp() |
396 | assert(c, e) | 403 | assert(c, e) |
397 | c:settimeout(0.1) | 404 | c:settimeout(0.1) |
398 | local t = socket.gettime() | 405 | local t = socket.gettime() |
399 | local r, e = c:connect("10.0.0.1", 81) | 406 | local r, e = c:connect("10.0.0.1", 81) |
400 | print(r, e) | ||
401 | assert(not r, "should not connect") | 407 | assert(not r, "should not connect") |
402 | assert(socket.gettime() - t < 2, "took too long to give up.") | 408 | assert(socket.gettime() - t < 2, "took too long to give up.") |
403 | c:close() | 409 | c:close() |
404 | print("ok") | 410 | pass("ok") |
405 | end | 411 | end |
406 | 412 | ||
407 | ------------------------------------------------------------------------ | 413 | ------------------------------------------------------------------------ |
408 | function accept_errors() | 414 | function accept_errors() |
409 | io.stderr:write("not listening: ") | 415 | printf("not listening: ") |
410 | local d, e = socket.bind("*", 0) | 416 | local d, e = socket.bind("*", 0) |
411 | assert(d, e); | 417 | assert(d, e); |
412 | local c, e = socket.tcp(); | 418 | local c, e = socket.tcp(); |
@@ -415,26 +421,26 @@ function accept_errors() | |||
415 | d:settimeout(2) | 421 | d:settimeout(2) |
416 | local r, e = d:accept() | 422 | local r, e = d:accept() |
417 | assert(not r and e) | 423 | assert(not r and e) |
418 | print("ok: ", e) | 424 | pass("ok") |
419 | io.stderr:write("not supported: ") | 425 | printf("not supported: ") |
420 | local c, e = socket.udp() | 426 | local c, e = socket.udp() |
421 | assert(c, e); | 427 | assert(c, e); |
422 | d:setfd(c:getfd()) | 428 | d:setfd(c:getfd()) |
423 | local r, e = d:accept() | 429 | local r, e = d:accept() |
424 | assert(not r and e) | 430 | assert(not r and e) |
425 | print("ok: ", e) | 431 | pass("ok") |
426 | end | 432 | end |
427 | 433 | ||
428 | ------------------------------------------------------------------------ | 434 | ------------------------------------------------------------------------ |
429 | function connect_errors() | 435 | function connect_errors() |
430 | io.stderr:write("connection refused: ") | 436 | printf("connection refused: ") |
431 | local c, e = socket.connect("localhost", 1); | 437 | local c, e = socket.connect("localhost", 1); |
432 | assert(not c and e) | 438 | assert(not c and e) |
433 | print("ok: ", e) | 439 | pass("ok") |
434 | io.stderr:write("host not found: ") | 440 | printf("host not found: ") |
435 | local c, e = socket.connect("host.is.invalid", 1); | 441 | local c, e = socket.connect("host.is.invalid", 1); |
436 | assert(not c and e, e) | 442 | assert(not c and e, e) |
437 | print("ok: ", e) | 443 | pass("ok") |
438 | end | 444 | end |
439 | 445 | ||
440 | ------------------------------------------------------------------------ | 446 | ------------------------------------------------------------------------ |
@@ -447,7 +453,7 @@ function rebind_test() | |||
447 | r, e = s:bind("localhost", p) | 453 | r, e = s:bind("localhost", p) |
448 | assert(not r, "managed to rebind!") | 454 | assert(not r, "managed to rebind!") |
449 | assert(e) | 455 | assert(e) |
450 | print("ok: ", e) | 456 | pass("ok") |
451 | end | 457 | end |
452 | 458 | ||
453 | ------------------------------------------------------------------------ | 459 | ------------------------------------------------------------------------ |
@@ -469,14 +475,14 @@ function getstats_test() | |||
469 | assert(s == t, "sent count failed" .. tostring(s) | 475 | assert(s == t, "sent count failed" .. tostring(s) |
470 | .. "/" .. tostring(t)) | 476 | .. "/" .. tostring(t)) |
471 | end | 477 | end |
472 | print("ok") | 478 | pass("ok") |
473 | end | 479 | end |
474 | 480 | ||
475 | 481 | ||
476 | ------------------------------------------------------------------------ | 482 | ------------------------------------------------------------------------ |
477 | function test_nonblocking(size) | 483 | function test_nonblocking(size) |
478 | reconnect() | 484 | reconnect() |
479 | print("Testing " .. 2*size .. " bytes") | 485 | printf("testing " .. 2*size .. " bytes: ") |
480 | remote(string.format([[ | 486 | remote(string.format([[ |
481 | data:send(string.rep("a", %d)) | 487 | data:send(string.rep("a", %d)) |
482 | socket.sleep(0.5) | 488 | socket.sleep(0.5) |
@@ -508,7 +514,7 @@ remote(string.format([[ | |||
508 | data:settimeout(-1) | 514 | data:settimeout(-1) |
509 | local back = data:receive(2*size) | 515 | local back = data:receive(2*size) |
510 | assert(back == str, "'" .. back .. "' vs '" .. str .. "'") | 516 | assert(back == str, "'" .. back .. "' vs '" .. str .. "'") |
511 | print("ok") | 517 | pass("ok") |
512 | end | 518 | end |
513 | 519 | ||
514 | ------------------------------------------------------------------------ | 520 | ------------------------------------------------------------------------ |
@@ -516,7 +522,7 @@ function test_readafterclose() | |||
516 | local back, partial, err | 522 | local back, partial, err |
517 | local str = 'little string' | 523 | local str = 'little string' |
518 | reconnect() | 524 | reconnect() |
519 | pass("trying repeated '*a' pattern") | 525 | printf("trying repeated '*a' pattern") |
520 | remote (string.format ([[ | 526 | remote (string.format ([[ |
521 | data:send('%s') | 527 | data:send('%s') |
522 | data:close() | 528 | data:close() |
@@ -526,9 +532,9 @@ function test_readafterclose() | |||
526 | assert(back == str, "unexpected data read") | 532 | assert(back == str, "unexpected data read") |
527 | back, err, partial = data:receive("*a") | 533 | back, err, partial = data:receive("*a") |
528 | assert(back == nil and err == "closed", "should have returned 'closed'") | 534 | assert(back == nil and err == "closed", "should have returned 'closed'") |
529 | print("ok") | 535 | pass("ok") |
530 | reconnect() | 536 | reconnect() |
531 | pass("trying active close before '*a'") | 537 | printf("trying active close before '*a'") |
532 | remote (string.format ([[ | 538 | remote (string.format ([[ |
533 | data:close() | 539 | data:close() |
534 | data = nil | 540 | data = nil |
@@ -536,9 +542,9 @@ function test_readafterclose() | |||
536 | data:close() | 542 | data:close() |
537 | back, err, partial = data:receive("*a") | 543 | back, err, partial = data:receive("*a") |
538 | assert(back == nil and err == "closed", "should have returned 'closed'") | 544 | assert(back == nil and err == "closed", "should have returned 'closed'") |
539 | print("ok") | 545 | pass("ok") |
540 | reconnect() | 546 | reconnect() |
541 | pass("trying active close before '*l'") | 547 | printf("trying active close before '*l'") |
542 | remote (string.format ([[ | 548 | remote (string.format ([[ |
543 | data:close() | 549 | data:close() |
544 | data = nil | 550 | data = nil |
@@ -546,9 +552,9 @@ function test_readafterclose() | |||
546 | data:close() | 552 | data:close() |
547 | back, err, partial = data:receive() | 553 | back, err, partial = data:receive() |
548 | assert(back == nil and err == "closed", "should have returned 'closed'") | 554 | assert(back == nil and err == "closed", "should have returned 'closed'") |
549 | print("ok") | 555 | pass("ok") |
550 | reconnect() | 556 | reconnect() |
551 | pass("trying active close before raw 1") | 557 | printf("trying active close before raw 1") |
552 | remote (string.format ([[ | 558 | remote (string.format ([[ |
553 | data:close() | 559 | data:close() |
554 | data = nil | 560 | data = nil |
@@ -556,9 +562,9 @@ function test_readafterclose() | |||
556 | data:close() | 562 | data:close() |
557 | back, err, partial = data:receive(1) | 563 | back, err, partial = data:receive(1) |
558 | assert(back == nil and err == "closed", "should have returned 'closed'") | 564 | assert(back == nil and err == "closed", "should have returned 'closed'") |
559 | print("ok") | 565 | pass("ok") |
560 | reconnect() | 566 | reconnect() |
561 | pass("trying active close before raw 0") | 567 | printf("trying active close before raw 0") |
562 | remote (string.format ([[ | 568 | remote (string.format ([[ |
563 | data:close() | 569 | data:close() |
564 | data = nil | 570 | data = nil |
@@ -566,7 +572,7 @@ function test_readafterclose() | |||
566 | data:close() | 572 | data:close() |
567 | back, err, partial = data:receive(0) | 573 | back, err, partial = data:receive(0) |
568 | assert(back == nil and err == "closed", "should have returned 'closed'") | 574 | assert(back == nil and err == "closed", "should have returned 'closed'") |
569 | print("ok") | 575 | pass("ok") |
570 | end | 576 | end |
571 | 577 | ||
572 | ------------------------------------------------------------------------ | 578 | ------------------------------------------------------------------------ |
@@ -581,13 +587,29 @@ function test_writeafterclose() | |||
581 | while not err do | 587 | while not err do |
582 | sent, err, errsent, time = data:send(str) | 588 | sent, err, errsent, time = data:send(str) |
583 | end | 589 | end |
584 | print(sent, err, errsent, time) | 590 | assert(err == "closed", "should have returned 'closed'") |
585 | print("ok") | 591 | pass("ok") |
586 | end | 592 | end |
587 | 593 | ||
588 | ------------------------------------------------------------------------ | 594 | ------------------------------------------------------------------------ |
589 | --test_writeafterclose() | ||
590 | 595 | ||
596 | function test_partialrecv() | ||
597 | local str = 'little string' | ||
598 | reconnect() | ||
599 | remote([[ | ||
600 | data:send("7890") | ||
601 | ]]) | ||
602 | data:settimeout(1) | ||
603 | back, err = data:receive(10, "123456") | ||
604 | assert(back == "1234567890", "failed on exact mixed length") | ||
605 | back, err = data:receive(8, "87654321") | ||
606 | assert(back == "87654321", "failed on exact length") | ||
607 | back, err = data:receive(4, "87654321") | ||
608 | assert(back == "87654321", "failed on smaller length") | ||
609 | pass("ok") | ||
610 | end | ||
611 | |||
612 | ------------------------------------------------------------------------ | ||
591 | test("method registration") | 613 | test("method registration") |
592 | test_methods(socket.tcp(), { | 614 | test_methods(socket.tcp(), { |
593 | "accept", | 615 | "accept", |
@@ -629,12 +651,18 @@ test_methods(socket.udp(), { | |||
629 | "settimeout" | 651 | "settimeout" |
630 | }) | 652 | }) |
631 | 653 | ||
654 | test("partial receive") | ||
655 | test_partialrecv() | ||
656 | |||
632 | test("select function") | 657 | test("select function") |
633 | test_selectbugs() | 658 | test_selectbugs() |
634 | 659 | ||
635 | test("testing read after close") | 660 | test("read after close") |
636 | test_readafterclose() | 661 | test_readafterclose() |
637 | 662 | ||
663 | test("write after close") | ||
664 | test_writeafterclose() | ||
665 | |||
638 | test("connect function") | 666 | test("connect function") |
639 | connect_timeout() | 667 | connect_timeout() |
640 | empty_connect() | 668 | empty_connect() |
diff --git a/test/testsupport.lua b/test/testsupport.lua index acad8f5..b986088 100644 --- a/test/testsupport.lua +++ b/test/testsupport.lua | |||
@@ -1,13 +1,13 @@ | |||
1 | function readfile(name) | 1 | function readfile(name) |
2 | local f = io.open(name, "rb") | 2 | local f = io.open(name, "rb") |
3 | if not f then return nil end | 3 | if not f then return nil end |
4 | local s = f:read("*a") | 4 | local s = f:read("*a") |
5 | f:close() | 5 | f:close() |
6 | return s | 6 | return s |
7 | end | 7 | end |
8 | 8 | ||
9 | function similar(s1, s2) | 9 | function similar(s1, s2) |
10 | return string.lower(string.gsub(s1 or "", "%s", "")) == | 10 | return string.lower(string.gsub(s1 or "", "%s", "")) == |
11 | string.lower(string.gsub(s2 or "", "%s", "")) | 11 | string.lower(string.gsub(s2 or "", "%s", "")) |
12 | end | 12 | end |
13 | 13 | ||
@@ -28,7 +28,7 @@ local set = rawset | |||
28 | local warn = print | 28 | local warn = print |
29 | 29 | ||
30 | local setglobal = function(table, key, value) | 30 | local setglobal = function(table, key, value) |
31 | warn("changed " .. key) | 31 | warn("changed " .. key) |
32 | set(table, key, value) | 32 | set(table, key, value) |
33 | end | 33 | end |
34 | 34 | ||
diff --git a/test/urltest.lua b/test/urltest.lua index 8dc0c14..d46cb03 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -3,439 +3,439 @@ socket.url = require("socket.url") | |||
3 | dofile("testsupport.lua") | 3 | dofile("testsupport.lua") |
4 | 4 | ||
5 | local check_build_url = function(parsed) | 5 | local check_build_url = function(parsed) |
6 | local built = socket.url.build(parsed) | 6 | local built = socket.url.build(parsed) |
7 | if built ~= parsed.url then | 7 | if built ~= parsed.url then |
8 | print("built is different from expected") | 8 | print("built is different from expected") |
9 | print(built) | 9 | print(built) |
10 | print(expected) | 10 | print(expected) |
11 | exit() | 11 | exit() |
12 | end | 12 | end |
13 | end | 13 | end |
14 | 14 | ||
15 | local check_protect = function(parsed, path, unsafe) | 15 | local check_protect = function(parsed, path, unsafe) |
16 | local built = socket.url.build_path(parsed, unsafe) | 16 | local built = socket.url.build_path(parsed, unsafe) |
17 | if built ~= path then | 17 | if built ~= path then |
18 | print(built, path) | 18 | print(built, path) |
19 | print("path composition failed.") | 19 | print("path composition failed.") |
20 | exit() | 20 | exit() |
21 | end | 21 | end |
22 | end | 22 | end |
23 | 23 | ||
24 | local check_invert = function(url) | 24 | local check_invert = function(url) |
25 | local parsed = socket.url.parse(url) | 25 | local parsed = socket.url.parse(url) |
26 | parsed.path = socket.url.build_path(socket.url.parse_path(parsed.path)) | 26 | parsed.path = socket.url.build_path(socket.url.parse_path(parsed.path)) |
27 | local rebuilt = socket.url.build(parsed) | 27 | local rebuilt = socket.url.build(parsed) |
28 | if rebuilt ~= url then | 28 | if rebuilt ~= url then |
29 | print(url, rebuilt) | 29 | print(url, rebuilt) |
30 | print("original and rebuilt are different") | 30 | print("original and rebuilt are different") |
31 | exit() | 31 | exit() |
32 | end | 32 | end |
33 | end | 33 | end |
34 | 34 | ||
35 | local check_parse_path = function(path, expect) | 35 | local check_parse_path = function(path, expect) |
36 | local parsed = socket.url.parse_path(path) | 36 | local parsed = socket.url.parse_path(path) |
37 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do | 37 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do |
38 | if parsed[i] ~= expect[i] then | 38 | if parsed[i] ~= expect[i] then |
39 | print(path) | 39 | print(path) |
40 | exit() | 40 | exit() |
41 | end | 41 | end |
42 | end | 42 | end |
43 | if expect.is_directory ~= parsed.is_directory then | 43 | if expect.is_directory ~= parsed.is_directory then |
44 | print(path) | 44 | print(path) |
45 | print("is_directory mismatch") | 45 | print("is_directory mismatch") |
46 | exit() | 46 | exit() |
47 | end | 47 | end |
48 | if expect.is_absolute ~= parsed.is_absolute then | 48 | if expect.is_absolute ~= parsed.is_absolute then |
49 | print(path) | 49 | print(path) |
50 | print("is_absolute mismatch") | 50 | print("is_absolute mismatch") |
51 | exit() | 51 | exit() |
52 | end | 52 | end |
53 | local built = socket.url.build_path(expect) | 53 | local built = socket.url.build_path(expect) |
54 | if built ~= path then | 54 | if built ~= path then |
55 | print(built, path) | 55 | print(built, path) |
56 | print("path composition failed.") | 56 | print("path composition failed.") |
57 | exit() | 57 | exit() |
58 | end | 58 | end |
59 | end | 59 | end |
60 | 60 | ||
61 | local check_absolute_url = function(base, relative, absolute) | 61 | local check_absolute_url = function(base, relative, absolute) |
62 | local res = socket.url.absolute(base, relative) | 62 | local res = socket.url.absolute(base, relative) |
63 | if res ~= absolute then | 63 | if res ~= absolute then |
64 | io.write("absolute: In test for '", relative, "' expected '", | 64 | io.write("absolute: In test for '", relative, "' expected '", |
65 | absolute, "' but got '", res, "'\n") | 65 | absolute, "' but got '", res, "'\n") |
66 | exit() | 66 | exit() |
67 | end | 67 | end |
68 | end | 68 | end |
69 | 69 | ||
70 | local check_parse_url = function(gaba) | 70 | local check_parse_url = function(gaba) |
71 | local url = gaba.url | 71 | local url = gaba.url |
72 | gaba.url = nil | 72 | gaba.url = nil |
73 | local parsed = socket.url.parse(url) | 73 | local parsed = socket.url.parse(url) |
74 | for i, v in pairs(gaba) do | 74 | for i, v in pairs(gaba) do |
75 | if v ~= parsed[i] then | 75 | if v ~= parsed[i] then |
76 | io.write("parse: In test for '", url, "' expected ", i, " = '", | 76 | io.write("parse: In test for '", url, "' expected ", i, " = '", |
77 | v, "' but got '", tostring(parsed[i]), "'\n") | 77 | v, "' but got '", tostring(parsed[i]), "'\n") |
78 | for i,v in pairs(parsed) do print(i,v) end | 78 | for i,v in pairs(parsed) do print(i,v) end |
79 | exit() | 79 | exit() |
80 | end | 80 | end |
81 | end | 81 | end |
82 | for i, v in pairs(parsed) do | 82 | for i, v in pairs(parsed) do |
83 | if v ~= gaba[i] then | 83 | if v ~= gaba[i] then |
84 | io.write("parse: In test for '", url, "' expected ", i, " = '", | 84 | io.write("parse: In test for '", url, "' expected ", i, " = '", |
85 | tostring(gaba[i]), "' but got '", v, "'\n") | 85 | tostring(gaba[i]), "' but got '", v, "'\n") |
86 | for i,v in pairs(parsed) do print(i,v) end | 86 | for i,v in pairs(parsed) do print(i,v) end |
87 | exit() | 87 | exit() |
88 | end | 88 | end |
89 | end | 89 | end |
90 | end | 90 | end |
91 | 91 | ||
92 | print("testing URL parsing") | 92 | print("testing URL parsing") |
93 | check_parse_url{ | 93 | check_parse_url{ |
94 | url = "scheme://userinfo@host:port/path;params?query#fragment", | 94 | url = "scheme://userinfo@host:port/path;params?query#fragment", |
95 | scheme = "scheme", | 95 | scheme = "scheme", |
96 | authority = "userinfo@host:port", | 96 | authority = "userinfo@host:port", |
97 | host = "host", | 97 | host = "host", |
98 | port = "port", | 98 | port = "port", |
99 | userinfo = "userinfo", | 99 | userinfo = "userinfo", |
100 | user = "userinfo", | 100 | user = "userinfo", |
101 | path = "/path", | 101 | path = "/path", |
102 | params = "params", | 102 | params = "params", |
103 | query = "query", | 103 | query = "query", |
104 | fragment = "fragment" | 104 | fragment = "fragment" |
105 | } | 105 | } |
106 | 106 | ||
107 | check_parse_url{ | 107 | check_parse_url{ |
108 | url = "scheme://user:password@host:port/path;params?query#fragment", | 108 | url = "scheme://user:password@host:port/path;params?query#fragment", |
109 | scheme = "scheme", | 109 | scheme = "scheme", |
110 | authority = "user:password@host:port", | 110 | authority = "user:password@host:port", |
111 | host = "host", | 111 | host = "host", |
112 | port = "port", | 112 | port = "port", |
113 | userinfo = "user:password", | 113 | userinfo = "user:password", |
114 | user = "user", | 114 | user = "user", |
115 | password = "password", | 115 | password = "password", |
116 | path = "/path", | 116 | path = "/path", |
117 | params = "params", | 117 | params = "params", |
118 | query = "query", | 118 | query = "query", |
119 | fragment = "fragment", | 119 | fragment = "fragment", |
120 | } | 120 | } |
121 | 121 | ||
122 | check_parse_url{ | 122 | check_parse_url{ |
123 | url = "scheme://userinfo@host:port/path;params?query#", | 123 | url = "scheme://userinfo@host:port/path;params?query#", |
124 | scheme = "scheme", | 124 | scheme = "scheme", |
125 | authority = "userinfo@host:port", | 125 | authority = "userinfo@host:port", |
126 | host = "host", | 126 | host = "host", |
127 | port = "port", | 127 | port = "port", |
128 | userinfo = "userinfo", | 128 | userinfo = "userinfo", |
129 | user = "userinfo", | 129 | user = "userinfo", |
130 | path = "/path", | 130 | path = "/path", |
131 | params = "params", | 131 | params = "params", |
132 | query = "query", | 132 | query = "query", |
133 | fragment = "" | 133 | fragment = "" |
134 | } | 134 | } |
135 | 135 | ||
136 | check_parse_url{ | 136 | check_parse_url{ |
137 | url = "scheme://userinfo@host:port/path;params?#fragment", | 137 | url = "scheme://userinfo@host:port/path;params?#fragment", |
138 | scheme = "scheme", | 138 | scheme = "scheme", |
139 | authority = "userinfo@host:port", | 139 | authority = "userinfo@host:port", |
140 | host = "host", | 140 | host = "host", |
141 | port = "port", | 141 | port = "port", |
142 | userinfo = "userinfo", | 142 | userinfo = "userinfo", |
143 | user = "userinfo", | 143 | user = "userinfo", |
144 | path = "/path", | 144 | path = "/path", |
145 | params = "params", | 145 | params = "params", |
146 | query = "", | 146 | query = "", |
147 | fragment = "fragment" | 147 | fragment = "fragment" |
148 | } | 148 | } |
149 | 149 | ||
150 | check_parse_url{ | 150 | check_parse_url{ |
151 | url = "scheme://userinfo@host:port/path;params#fragment", | 151 | url = "scheme://userinfo@host:port/path;params#fragment", |
152 | scheme = "scheme", | 152 | scheme = "scheme", |
153 | authority = "userinfo@host:port", | 153 | authority = "userinfo@host:port", |
154 | host = "host", | 154 | host = "host", |
155 | port = "port", | 155 | port = "port", |
156 | userinfo = "userinfo", | 156 | userinfo = "userinfo", |
157 | user = "userinfo", | 157 | user = "userinfo", |
158 | path = "/path", | 158 | path = "/path", |
159 | params = "params", | 159 | params = "params", |
160 | fragment = "fragment" | 160 | fragment = "fragment" |
161 | } | 161 | } |
162 | 162 | ||
163 | check_parse_url{ | 163 | check_parse_url{ |
164 | url = "scheme://userinfo@host:port/path;?query#fragment", | 164 | url = "scheme://userinfo@host:port/path;?query#fragment", |
165 | scheme = "scheme", | 165 | scheme = "scheme", |
166 | authority = "userinfo@host:port", | 166 | authority = "userinfo@host:port", |
167 | host = "host", | 167 | host = "host", |
168 | port = "port", | 168 | port = "port", |
169 | userinfo = "userinfo", | 169 | userinfo = "userinfo", |
170 | user = "userinfo", | 170 | user = "userinfo", |
171 | path = "/path", | 171 | path = "/path", |
172 | params = "", | 172 | params = "", |
173 | query = "query", | 173 | query = "query", |
174 | fragment = "fragment" | 174 | fragment = "fragment" |
175 | } | 175 | } |
176 | 176 | ||
177 | check_parse_url{ | 177 | check_parse_url{ |
178 | url = "scheme://userinfo@host:port/path?query#fragment", | 178 | url = "scheme://userinfo@host:port/path?query#fragment", |
179 | scheme = "scheme", | 179 | scheme = "scheme", |
180 | authority = "userinfo@host:port", | 180 | authority = "userinfo@host:port", |
181 | host = "host", | 181 | host = "host", |
182 | port = "port", | 182 | port = "port", |
183 | userinfo = "userinfo", | 183 | userinfo = "userinfo", |
184 | user = "userinfo", | 184 | user = "userinfo", |
185 | path = "/path", | 185 | path = "/path", |
186 | query = "query", | 186 | query = "query", |
187 | fragment = "fragment" | 187 | fragment = "fragment" |
188 | } | 188 | } |
189 | 189 | ||
190 | check_parse_url{ | 190 | check_parse_url{ |
191 | url = "scheme://userinfo@host:port/;params?query#fragment", | 191 | url = "scheme://userinfo@host:port/;params?query#fragment", |
192 | scheme = "scheme", | 192 | scheme = "scheme", |
193 | authority = "userinfo@host:port", | 193 | authority = "userinfo@host:port", |
194 | host = "host", | 194 | host = "host", |
195 | port = "port", | 195 | port = "port", |
196 | userinfo = "userinfo", | 196 | userinfo = "userinfo", |
197 | user = "userinfo", | 197 | user = "userinfo", |
198 | path = "/", | 198 | path = "/", |
199 | params = "params", | 199 | params = "params", |
200 | query = "query", | 200 | query = "query", |
201 | fragment = "fragment" | 201 | fragment = "fragment" |
202 | } | 202 | } |
203 | 203 | ||
204 | check_parse_url{ | 204 | check_parse_url{ |
205 | url = "scheme://userinfo@host:port", | 205 | url = "scheme://userinfo@host:port", |
206 | scheme = "scheme", | 206 | scheme = "scheme", |
207 | authority = "userinfo@host:port", | 207 | authority = "userinfo@host:port", |
208 | host = "host", | 208 | host = "host", |
209 | port = "port", | 209 | port = "port", |
210 | userinfo = "userinfo", | 210 | userinfo = "userinfo", |
211 | user = "userinfo", | 211 | user = "userinfo", |
212 | } | 212 | } |
213 | 213 | ||
214 | check_parse_url{ | 214 | check_parse_url{ |
215 | url = "//userinfo@host:port/path;params?query#fragment", | 215 | url = "//userinfo@host:port/path;params?query#fragment", |
216 | authority = "userinfo@host:port", | 216 | authority = "userinfo@host:port", |
217 | host = "host", | 217 | host = "host", |
218 | port = "port", | 218 | port = "port", |
219 | userinfo = "userinfo", | 219 | userinfo = "userinfo", |
220 | user = "userinfo", | 220 | user = "userinfo", |
221 | path = "/path", | 221 | path = "/path", |
222 | params = "params", | 222 | params = "params", |
223 | query = "query", | 223 | query = "query", |
224 | fragment = "fragment" | 224 | fragment = "fragment" |
225 | } | 225 | } |
226 | 226 | ||
227 | check_parse_url{ | 227 | check_parse_url{ |
228 | url = "//userinfo@host:port/path", | 228 | url = "//userinfo@host:port/path", |
229 | authority = "userinfo@host:port", | 229 | authority = "userinfo@host:port", |
230 | host = "host", | 230 | host = "host", |
231 | port = "port", | 231 | port = "port", |
232 | userinfo = "userinfo", | 232 | userinfo = "userinfo", |
233 | user = "userinfo", | 233 | user = "userinfo", |
234 | path = "/path", | 234 | path = "/path", |
235 | } | 235 | } |
236 | 236 | ||
237 | check_parse_url{ | 237 | check_parse_url{ |
238 | url = "//userinfo@host/path", | 238 | url = "//userinfo@host/path", |
239 | authority = "userinfo@host", | 239 | authority = "userinfo@host", |
240 | host = "host", | 240 | host = "host", |
241 | userinfo = "userinfo", | 241 | userinfo = "userinfo", |
242 | user = "userinfo", | 242 | user = "userinfo", |
243 | path = "/path", | 243 | path = "/path", |
244 | } | 244 | } |
245 | 245 | ||
246 | check_parse_url{ | 246 | check_parse_url{ |
247 | url = "//user:password@host/path", | 247 | url = "//user:password@host/path", |
248 | authority = "user:password@host", | 248 | authority = "user:password@host", |
249 | host = "host", | 249 | host = "host", |
250 | userinfo = "user:password", | 250 | userinfo = "user:password", |
251 | password = "password", | 251 | password = "password", |
252 | user = "user", | 252 | user = "user", |
253 | path = "/path", | 253 | path = "/path", |
254 | } | 254 | } |
255 | 255 | ||
256 | check_parse_url{ | 256 | check_parse_url{ |
257 | url = "//user:@host/path", | 257 | url = "//user:@host/path", |
258 | authority = "user:@host", | 258 | authority = "user:@host", |
259 | host = "host", | 259 | host = "host", |
260 | userinfo = "user:", | 260 | userinfo = "user:", |
261 | password = "", | 261 | password = "", |
262 | user = "user", | 262 | user = "user", |
263 | path = "/path", | 263 | path = "/path", |
264 | } | 264 | } |
265 | 265 | ||
266 | check_parse_url{ | 266 | check_parse_url{ |
267 | url = "//user@host:port/path", | 267 | url = "//user@host:port/path", |
268 | authority = "user@host:port", | 268 | authority = "user@host:port", |
269 | host = "host", | 269 | host = "host", |
270 | userinfo = "user", | 270 | userinfo = "user", |
271 | user = "user", | 271 | user = "user", |
272 | port = "port", | 272 | port = "port", |
273 | path = "/path", | 273 | path = "/path", |
274 | } | 274 | } |
275 | 275 | ||
276 | check_parse_url{ | 276 | check_parse_url{ |
277 | url = "//host:port/path", | 277 | url = "//host:port/path", |
278 | authority = "host:port", | 278 | authority = "host:port", |
279 | port = "port", | 279 | port = "port", |
280 | host = "host", | 280 | host = "host", |
281 | path = "/path", | 281 | path = "/path", |
282 | } | 282 | } |
283 | 283 | ||
284 | check_parse_url{ | 284 | check_parse_url{ |
285 | url = "//host/path", | 285 | url = "//host/path", |
286 | authority = "host", | 286 | authority = "host", |
287 | host = "host", | 287 | host = "host", |
288 | path = "/path", | 288 | path = "/path", |
289 | } | 289 | } |
290 | 290 | ||
291 | check_parse_url{ | 291 | check_parse_url{ |
292 | url = "//host", | 292 | url = "//host", |
293 | authority = "host", | 293 | authority = "host", |
294 | host = "host", | 294 | host = "host", |
295 | } | 295 | } |
296 | 296 | ||
297 | check_parse_url{ | 297 | check_parse_url{ |
298 | url = "/path", | 298 | url = "/path", |
299 | path = "/path", | 299 | path = "/path", |
300 | } | 300 | } |
301 | 301 | ||
302 | check_parse_url{ | 302 | check_parse_url{ |
303 | url = "path", | 303 | url = "path", |
304 | path = "path", | 304 | path = "path", |
305 | } | 305 | } |
306 | 306 | ||
307 | print("testing URL building") | 307 | print("testing URL building") |
308 | check_build_url { | 308 | check_build_url { |
309 | url = "scheme://user:password@host:port/path;params?query#fragment", | 309 | url = "scheme://user:password@host:port/path;params?query#fragment", |
310 | scheme = "scheme", | 310 | scheme = "scheme", |
311 | host = "host", | 311 | host = "host", |
312 | port = "port", | 312 | port = "port", |
313 | user = "user", | 313 | user = "user", |
314 | password = "password", | 314 | password = "password", |
315 | path = "/path", | 315 | path = "/path", |
316 | params = "params", | 316 | params = "params", |
317 | query = "query", | 317 | query = "query", |
318 | fragment = "fragment" | 318 | fragment = "fragment" |
319 | } | 319 | } |
320 | 320 | ||
321 | check_build_url { | 321 | check_build_url { |
322 | url = "scheme://user:password@host/path;params?query#fragment", | 322 | url = "scheme://user:password@host/path;params?query#fragment", |
323 | scheme = "scheme", | 323 | scheme = "scheme", |
324 | host = "host", | 324 | host = "host", |
325 | user = "user", | 325 | user = "user", |
326 | password = "password", | 326 | password = "password", |
327 | path = "/path", | 327 | path = "/path", |
328 | params = "params", | 328 | params = "params", |
329 | query = "query", | 329 | query = "query", |
330 | fragment = "fragment" | 330 | fragment = "fragment" |
331 | } | 331 | } |
332 | 332 | ||
333 | check_build_url { | 333 | check_build_url { |
334 | url = "scheme://user@host/path;params?query#fragment", | 334 | url = "scheme://user@host/path;params?query#fragment", |
335 | scheme = "scheme", | 335 | scheme = "scheme", |
336 | host = "host", | 336 | host = "host", |
337 | user = "user", | 337 | user = "user", |
338 | path = "/path", | 338 | path = "/path", |
339 | params = "params", | 339 | params = "params", |
340 | query = "query", | 340 | query = "query", |
341 | fragment = "fragment" | 341 | fragment = "fragment" |
342 | } | 342 | } |
343 | 343 | ||
344 | check_build_url { | 344 | check_build_url { |
345 | url = "scheme://host/path;params?query#fragment", | 345 | url = "scheme://host/path;params?query#fragment", |
346 | scheme = "scheme", | 346 | scheme = "scheme", |
347 | host = "host", | 347 | host = "host", |
348 | path = "/path", | 348 | path = "/path", |
349 | params = "params", | 349 | params = "params", |
350 | query = "query", | 350 | query = "query", |
351 | fragment = "fragment" | 351 | fragment = "fragment" |
352 | } | 352 | } |
353 | 353 | ||
354 | check_build_url { | 354 | check_build_url { |
355 | url = "scheme://host/path;params#fragment", | 355 | url = "scheme://host/path;params#fragment", |
356 | scheme = "scheme", | 356 | scheme = "scheme", |
357 | host = "host", | 357 | host = "host", |
358 | path = "/path", | 358 | path = "/path", |
359 | params = "params", | 359 | params = "params", |
360 | fragment = "fragment" | 360 | fragment = "fragment" |
361 | } | 361 | } |
362 | 362 | ||
363 | check_build_url { | 363 | check_build_url { |
364 | url = "scheme://host/path#fragment", | 364 | url = "scheme://host/path#fragment", |
365 | scheme = "scheme", | 365 | scheme = "scheme", |
366 | host = "host", | 366 | host = "host", |
367 | path = "/path", | 367 | path = "/path", |
368 | fragment = "fragment" | 368 | fragment = "fragment" |
369 | } | 369 | } |
370 | 370 | ||
371 | check_build_url { | 371 | check_build_url { |
372 | url = "scheme://host/path", | 372 | url = "scheme://host/path", |
373 | scheme = "scheme", | 373 | scheme = "scheme", |
374 | host = "host", | 374 | host = "host", |
375 | path = "/path", | 375 | path = "/path", |
376 | } | 376 | } |
377 | 377 | ||
378 | check_build_url { | 378 | check_build_url { |
379 | url = "//host/path", | 379 | url = "//host/path", |
380 | host = "host", | 380 | host = "host", |
381 | path = "/path", | 381 | path = "/path", |
382 | } | 382 | } |
383 | 383 | ||
384 | check_build_url { | 384 | check_build_url { |
385 | url = "/path", | 385 | url = "/path", |
386 | path = "/path", | 386 | path = "/path", |
387 | } | 387 | } |
388 | 388 | ||
389 | check_build_url { | 389 | check_build_url { |
390 | url = "scheme://user:password@host:port/path;params?query#fragment", | 390 | url = "scheme://user:password@host:port/path;params?query#fragment", |
391 | scheme = "scheme", | 391 | scheme = "scheme", |
392 | host = "host", | 392 | host = "host", |
393 | port = "port", | 393 | port = "port", |
394 | user = "user", | 394 | user = "user", |
395 | userinfo = "not used", | 395 | userinfo = "not used", |
396 | password = "password", | 396 | password = "password", |
397 | path = "/path", | 397 | path = "/path", |
398 | params = "params", | 398 | params = "params", |
399 | query = "query", | 399 | query = "query", |
400 | fragment = "fragment" | 400 | fragment = "fragment" |
401 | } | 401 | } |
402 | 402 | ||
403 | check_build_url { | 403 | check_build_url { |
404 | url = "scheme://user:password@host:port/path;params?query#fragment", | 404 | url = "scheme://user:password@host:port/path;params?query#fragment", |
405 | scheme = "scheme", | 405 | scheme = "scheme", |
406 | host = "host", | 406 | host = "host", |
407 | port = "port", | 407 | port = "port", |
408 | user = "user", | 408 | user = "user", |
409 | userinfo = "not used", | 409 | userinfo = "not used", |
410 | authority = "not used", | 410 | authority = "not used", |
411 | password = "password", | 411 | password = "password", |
412 | path = "/path", | 412 | path = "/path", |
413 | params = "params", | 413 | params = "params", |
414 | query = "query", | 414 | query = "query", |
415 | fragment = "fragment" | 415 | fragment = "fragment" |
416 | } | 416 | } |
417 | 417 | ||
418 | check_build_url { | 418 | check_build_url { |
419 | url = "scheme://user:password@host:port/path;params?query#fragment", | 419 | url = "scheme://user:password@host:port/path;params?query#fragment", |
420 | scheme = "scheme", | 420 | scheme = "scheme", |
421 | host = "host", | 421 | host = "host", |
422 | port = "port", | 422 | port = "port", |
423 | userinfo = "user:password", | 423 | userinfo = "user:password", |
424 | authority = "not used", | 424 | authority = "not used", |
425 | path = "/path", | 425 | path = "/path", |
426 | params = "params", | 426 | params = "params", |
427 | query = "query", | 427 | query = "query", |
428 | fragment = "fragment" | 428 | fragment = "fragment" |
429 | } | 429 | } |
430 | 430 | ||
431 | check_build_url { | 431 | check_build_url { |
432 | url = "scheme://user:password@host:port/path;params?query#fragment", | 432 | url = "scheme://user:password@host:port/path;params?query#fragment", |
433 | scheme = "scheme", | 433 | scheme = "scheme", |
434 | authority = "user:password@host:port", | 434 | authority = "user:password@host:port", |
435 | path = "/path", | 435 | path = "/path", |
436 | params = "params", | 436 | params = "params", |
437 | query = "query", | 437 | query = "query", |
438 | fragment = "fragment" | 438 | fragment = "fragment" |
439 | } | 439 | } |
440 | 440 | ||
441 | -- standard RFC tests | 441 | -- standard RFC tests |
@@ -488,11 +488,11 @@ print("testing path parsing and composition") | |||
488 | check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) | 488 | check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) |
489 | check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) | 489 | check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) |
490 | check_parse_path("eu/tu/ele/nos/vos/eles/", | 490 | check_parse_path("eu/tu/ele/nos/vos/eles/", |
491 | { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) | 491 | { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) |
492 | check_parse_path("/", { is_absolute = 1, is_directory = 1}) | 492 | check_parse_path("/", { is_absolute = 1, is_directory = 1}) |
493 | check_parse_path("", { }) | 493 | check_parse_path("", { }) |
494 | check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", | 494 | check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", |
495 | { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) | 495 | { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) |
496 | check_parse_path("eu/tu", { "eu", "tu" }) | 496 | check_parse_path("eu/tu", { "eu", "tu" }) |
497 | 497 | ||
498 | print("testing path protection") | 498 | print("testing path protection") |
diff --git a/test/utestclnt.lua b/test/utestclnt.lua index f002c6e..eec6adc 100644 --- a/test/utestclnt.lua +++ b/test/utestclnt.lua | |||
@@ -298,7 +298,7 @@ function empty_connect() | |||
298 | pass("ok") | 298 | pass("ok") |
299 | data = socket.connect(host, port) | 299 | data = socket.connect(host, port) |
300 | else | 300 | else |
301 | pass("gethostbyname returns localhost on empty string...") | 301 | pass("gethostbyname returns localhost on empty string...") |
302 | end | 302 | end |
303 | end | 303 | end |
304 | 304 | ||