diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/auth/.htaccess | 2 | ||||
-rw-r--r-- | test/excepttest.lua | 32 | ||||
-rwxr-xr-x | test/find-connect-limit | 2 | ||||
-rw-r--r-- | test/ftptest.lua | 34 | ||||
-rw-r--r-- | test/httptest.lua | 31 | ||||
-rw-r--r-- | test/ltn12test.lua | 33 | ||||
-rw-r--r-- | test/mimetest.lua | 46 | ||||
-rw-r--r-- | test/smtptest.lua | 20 | ||||
-rwxr-xr-x | test/tcp-getoptions | 28 | ||||
-rw-r--r-- | test/test_socket_error.lua | 2 | ||||
-rw-r--r-- | test/testclnt.lua | 1 | ||||
-rw-r--r-- | test/testmesg.lua | 14 | ||||
-rw-r--r-- | test/testsupport.lua | 2 | ||||
-rwxr-xr-x | test/udp-zero-length-send | 4 | ||||
-rwxr-xr-x | test/udp-zero-length-send-recv | 4 | ||||
-rw-r--r-- | test/unixdgramclnt.lua | 9 | ||||
-rw-r--r-- | test/unixdgramsrvr.lua | 9 | ||||
-rw-r--r-- | test/unixstreamclnt.lua (renamed from test/unixclnt.lua) | 2 | ||||
-rw-r--r-- | test/unixstreamsrvr.lua (renamed from test/unixsrvr.lua) | 2 | ||||
-rw-r--r-- | test/urltest.lua | 211 | ||||
-rw-r--r-- | test/utestclnt.lua | 68 | ||||
-rw-r--r-- | test/utestsrvr.lua | 2 |
22 files changed, 385 insertions, 173 deletions
diff --git a/test/auth/.htaccess b/test/auth/.htaccess index bb2794a..2509ae3 100644 --- a/test/auth/.htaccess +++ b/test/auth/.htaccess | |||
@@ -1,4 +1,4 @@ | |||
1 | AuthName "test-auth" | 1 | AuthName "test-auth" |
2 | AuthType Basic | 2 | AuthType Basic |
3 | AuthUserFile /Users/diego/impa/luasocket/test/auth/.htpasswd | 3 | AuthUserFile /home/diego/impa/luasocket/test/auth/.htpasswd |
4 | Require valid-user | 4 | Require valid-user |
diff --git a/test/excepttest.lua b/test/excepttest.lua index ce9f197..80c9cb8 100644 --- a/test/excepttest.lua +++ b/test/excepttest.lua | |||
@@ -1,6 +1,30 @@ | |||
1 | local socket = require("socket") | 1 | local socket = require("socket") |
2 | try = socket.newtry(function() | 2 | |
3 | print("finalized!!!") | 3 | local finalizer_called |
4 | |||
5 | local func = socket.protect(function(err, ...) | ||
6 | local try = socket.newtry(function() | ||
7 | finalizer_called = true | ||
8 | end) | ||
9 | |||
10 | if err then | ||
11 | return error(err, 0) | ||
12 | else | ||
13 | return try(...) | ||
14 | end | ||
4 | end) | 15 | end) |
5 | try = socket.protect(try) | 16 | |
6 | print(try(nil, "it works")) | 17 | local ret1, ret2, ret3 = func(false, 1, 2, 3) |
18 | assert(not finalizer_called, "unexpected finalizer call") | ||
19 | assert(ret1 == 1 and ret2 == 2 and ret3 == 3, "incorrect return values") | ||
20 | |||
21 | ret1, ret2, ret3 = func(false, false, "error message") | ||
22 | assert(finalizer_called, "finalizer not called") | ||
23 | assert(ret1 == nil and ret2 == "error message" and ret3 == nil, "incorrect return values") | ||
24 | |||
25 | local err = {key = "value"} | ||
26 | ret1, ret2 = pcall(func, err) | ||
27 | assert(not ret1, "error not rethrown") | ||
28 | assert(ret2 == err, "incorrect error rethrown") | ||
29 | |||
30 | print("OK") | ||
diff --git a/test/find-connect-limit b/test/find-connect-limit index ad0c3f5..199e515 100755 --- a/test/find-connect-limit +++ b/test/find-connect-limit | |||
@@ -10,7 +10,7 @@ ulimit -n | |||
10 | You'll probably need to be root to do this. | 10 | You'll probably need to be root to do this. |
11 | ]] | 11 | ]] |
12 | 12 | ||
13 | require "socket" | 13 | socket = require "socket" |
14 | 14 | ||
15 | host = arg[1] or "google.com" | 15 | host = arg[1] or "google.com" |
16 | port = arg[2] or 80 | 16 | port = arg[2] or 80 |
diff --git a/test/ftptest.lua b/test/ftptest.lua index fb13326..3ea0d39 100644 --- a/test/ftptest.lua +++ b/test/ftptest.lua | |||
@@ -3,19 +3,31 @@ local ftp = require("socket.ftp") | |||
3 | local url = require("socket.url") | 3 | local url = require("socket.url") |
4 | local ltn12 = require("ltn12") | 4 | local ltn12 = require("ltn12") |
5 | 5 | ||
6 | -- use dscl to create user "luasocket" with password "password" | ||
7 | -- with home in /Users/diego/luasocket/test/ftp | ||
8 | -- with group com.apple.access_ftp | ||
9 | -- with shell set to /sbin/nologin | ||
10 | -- set /etc/ftpchroot to chroot luasocket | ||
11 | -- must set group com.apple.access_ftp on user _ftp (for anonymous access) | ||
12 | -- copy index.html to /var/empty/pub (home of user ftp) | ||
13 | -- start ftp server with | ||
14 | -- sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist | ||
15 | -- copy index.html to /Users/diego/luasocket/test/ftp | ||
16 | -- stop with | ||
17 | -- sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist | ||
18 | |||
6 | -- override protection to make sure we see all errors | 19 | -- override protection to make sure we see all errors |
7 | --socket.protect = function(s) return s end | 20 | --socket.protect = function(s) return s end |
8 | 21 | ||
9 | dofile("testsupport.lua") | 22 | dofile("testsupport.lua") |
10 | 23 | ||
11 | local host, port, index_file, index, back, err, ret | 24 | local host = host or "localhost" |
25 | local port, index_file, index, back, err, ret | ||
12 | 26 | ||
13 | local t = socket.gettime() | 27 | local t = socket.gettime() |
14 | 28 | ||
15 | host = host or "localhost" | ||
16 | index_file = "index.html" | 29 | index_file = "index.html" |
17 | 30 | ||
18 | |||
19 | -- a function that returns a directory listing | 31 | -- a function that returns a directory listing |
20 | local function nlst(u) | 32 | local function nlst(u) |
21 | local t = {} | 33 | local t = {} |
@@ -55,27 +67,27 @@ assert(not err and back == index, err) | |||
55 | print("ok") | 67 | print("ok") |
56 | 68 | ||
57 | io.write("erasing before upload: ") | 69 | io.write("erasing before upload: ") |
58 | ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") | 70 | ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") |
59 | if not ret then print(err) | 71 | if not ret then print(err) |
60 | else print("ok") end | 72 | else print("ok") end |
61 | 73 | ||
62 | io.write("testing upload: ") | 74 | io.write("testing upload: ") |
63 | ret, err = ftp.put("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i", index) | 75 | ret, err = ftp.put("ftp://luasocket:password@" .. host .. "/index.up.html;type=i", index) |
64 | assert(ret and not err, err) | 76 | assert(ret and not err, err) |
65 | print("ok") | 77 | print("ok") |
66 | 78 | ||
67 | io.write("downloading uploaded file: ") | 79 | io.write("downloading uploaded file: ") |
68 | back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i") | 80 | back, err = ftp.get("ftp://luasocket:password@" .. host .. "/index.up.html;type=i") |
69 | assert(ret and not err and index == back, err) | 81 | assert(ret and not err and index == back, err) |
70 | print("ok") | 82 | print("ok") |
71 | 83 | ||
72 | io.write("erasing after upload/download: ") | 84 | io.write("erasing after upload/download: ") |
73 | ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") | 85 | ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") |
74 | assert(ret and not err, err) | 86 | assert(ret and not err, err) |
75 | print("ok") | 87 | print("ok") |
76 | 88 | ||
77 | io.write("testing weird-character translation: ") | 89 | io.write("testing weird-character translation: ") |
78 | back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/%23%3f;type=i") | 90 | back, err = ftp.get("ftp://luasocket:password@" .. host .. "/%23%3f;type=i") |
79 | assert(not err and back == index, err) | 91 | assert(not err and back == index, err) |
80 | print("ok") | 92 | print("ok") |
81 | 93 | ||
@@ -84,7 +96,7 @@ local back = {} | |||
84 | ret, err = ftp.get{ | 96 | ret, err = ftp.get{ |
85 | url = "//stupid:mistake@" .. host .. "/index.html", | 97 | url = "//stupid:mistake@" .. host .. "/index.html", |
86 | user = "luasocket", | 98 | user = "luasocket", |
87 | password = "pedrovian", | 99 | password = "password", |
88 | type = "i", | 100 | type = "i", |
89 | sink = ltn12.sink.table(back) | 101 | sink = ltn12.sink.table(back) |
90 | } | 102 | } |
diff --git a/test/httptest.lua b/test/httptest.lua index 63ff921..3457b07 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -265,6 +265,37 @@ ignore = { | |||
265 | } | 265 | } |
266 | check_request(request, expect, ignore) | 266 | check_request(request, expect, ignore) |
267 | 267 | ||
268 | -- Use https://httpbin.org/#/Dynamic_data/get_base64__value_ for testing | ||
269 | ----------------------------------------------------- | ||
270 | io.write("testing absolute https redirection: ") | ||
271 | request = { | ||
272 | url = "https://httpbin.org/redirect-to?url=https://httpbin.org/base64/THVhIFNvY2tldA==" | ||
273 | } | ||
274 | expect = { | ||
275 | code = 200, | ||
276 | body = "Lua Socket" | ||
277 | } | ||
278 | ignore = { | ||
279 | status = 1, | ||
280 | headers = 1 | ||
281 | } | ||
282 | check_request(request, expect, ignore) | ||
283 | |||
284 | ----------------------------------------------------- | ||
285 | io.write("testing relative https redirection: ") | ||
286 | request = { | ||
287 | url = "https://httpbin.org/redirect-to?url=/base64/THVhIFNvY2tldA==" | ||
288 | } | ||
289 | expect = { | ||
290 | code = 200, | ||
291 | body = "Lua Socket" | ||
292 | } | ||
293 | ignore = { | ||
294 | status = 1, | ||
295 | headers = 1 | ||
296 | } | ||
297 | check_request(request, expect, ignore) | ||
298 | |||
268 | ------------------------------------------------------------------------ | 299 | ------------------------------------------------------------------------ |
269 | --[[ | 300 | --[[ |
270 | io.write("testing proxy with redirection: ") | 301 | io.write("testing proxy with redirection: ") |
diff --git a/test/ltn12test.lua b/test/ltn12test.lua index e3f85fb..0cafbc9 100644 --- a/test/ltn12test.lua +++ b/test/ltn12test.lua | |||
@@ -38,7 +38,7 @@ local function named(f, name) | |||
38 | end | 38 | end |
39 | 39 | ||
40 | -------------------------------- | 40 | -------------------------------- |
41 | local function split(size) | 41 | local function split(size) |
42 | local buffer = "" | 42 | local buffer = "" |
43 | local last_out = "" | 43 | local last_out = "" |
44 | local last_in = "" | 44 | local last_in = "" |
@@ -50,12 +50,12 @@ local function split(size) | |||
50 | return last_out | 50 | return last_out |
51 | end | 51 | end |
52 | return function(chunk, done) | 52 | return function(chunk, done) |
53 | if done then | 53 | if done then |
54 | return not last_in and not last_out | 54 | return not last_in and not last_out |
55 | end | 55 | end |
56 | -- check if argument is consistent with state | 56 | -- check if argument is consistent with state |
57 | if not chunk then | 57 | if not chunk then |
58 | if last_in and last_in ~= "" and last_out ~= "" then | 58 | if last_in and last_in ~= "" and last_out ~= "" then |
59 | error("nil chunk following data chunk", 2) | 59 | error("nil chunk following data chunk", 2) |
60 | end | 60 | end |
61 | if not last_out then error("extra nil chunk", 2) end | 61 | if not last_out then error("extra nil chunk", 2) end |
@@ -67,8 +67,8 @@ local function split(size) | |||
67 | return output(chunk) | 67 | return output(chunk) |
68 | else | 68 | else |
69 | if not last_in then error("data chunk following nil chunk", 2) end | 69 | if not last_in then error("data chunk following nil chunk", 2) end |
70 | if last_in ~= "" and last_out ~= "" then | 70 | if last_in ~= "" and last_out ~= "" then |
71 | error("data chunk following data chunk", 2) | 71 | error("data chunk following data chunk", 2) |
72 | end | 72 | end |
73 | buffer = chunk | 73 | buffer = chunk |
74 | return output(chunk) | 74 | return output(chunk) |
@@ -85,7 +85,7 @@ local function format(chunk) | |||
85 | end | 85 | end |
86 | 86 | ||
87 | -------------------------------- | 87 | -------------------------------- |
88 | local function merge(size) | 88 | local function merge(size) |
89 | local buffer = "" | 89 | local buffer = "" |
90 | local last_out = "" | 90 | local last_out = "" |
91 | local last_in = "" | 91 | local last_in = "" |
@@ -102,12 +102,12 @@ local function merge(size) | |||
102 | return last_out | 102 | return last_out |
103 | end | 103 | end |
104 | return function(chunk, done) | 104 | return function(chunk, done) |
105 | if done then | 105 | if done then |
106 | return not last_in and not last_out | 106 | return not last_in and not last_out |
107 | end | 107 | end |
108 | -- check if argument is consistent with state | 108 | -- check if argument is consistent with state |
109 | if not chunk then | 109 | if not chunk then |
110 | if last_in and last_in ~= "" and last_out ~= "" then | 110 | if last_in and last_in ~= "" and last_out ~= "" then |
111 | error("nil chunk following data chunk", 2) | 111 | error("nil chunk following data chunk", 2) |
112 | end | 112 | end |
113 | if not last_out then error("extra nil chunk", 2) end | 113 | if not last_out then error("extra nil chunk", 2) end |
@@ -119,8 +119,8 @@ local function merge(size) | |||
119 | return output(chunk) | 119 | return output(chunk) |
120 | else | 120 | else |
121 | if not last_in then error("data chunk following nil chunk", 2) end | 121 | if not last_in then error("data chunk following nil chunk", 2) end |
122 | if last_in ~= "" and last_out ~= "" then | 122 | if last_in ~= "" and last_out ~= "" then |
123 | error("data chunk following data chunk", 2) | 123 | error("data chunk following data chunk", 2) |
124 | end | 124 | end |
125 | buffer = buffer .. chunk | 125 | buffer = buffer .. chunk |
126 | return output(chunk) | 126 | return output(chunk) |
@@ -181,6 +181,15 @@ assert(table.concat(t) == s, "mismatch") | |||
181 | print("ok") | 181 | print("ok") |
182 | 182 | ||
183 | -------------------------------- | 183 | -------------------------------- |
184 | io.write("testing source.table: ") | ||
185 | local inp = {'a','b','c','d','e'} | ||
186 | local source = ltn12.source.table(inp) | ||
187 | sink, t = ltn12.sink.table() | ||
188 | assert(ltn12.pump.all(source, sink), "returned error") | ||
189 | for i = 1, #inp do assert(t[i] == inp[i], "mismatch") end | ||
190 | print("ok") | ||
191 | |||
192 | -------------------------------- | ||
184 | io.write("testing source.chain (with split): ") | 193 | io.write("testing source.chain (with split): ") |
185 | source = ltn12.source.string(s) | 194 | source = ltn12.source.string(s) |
186 | filter = split(5) | 195 | filter = split(5) |
diff --git a/test/mimetest.lua b/test/mimetest.lua index f5b3747..a3c89ac 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua | |||
@@ -15,27 +15,27 @@ local eb64test = "b64test.bin2" | |||
15 | local db64test = "b64test.bin3" | 15 | local db64test = "b64test.bin3" |
16 | 16 | ||
17 | 17 | ||
18 | -- from Machado de Assis, "A Mão e a Rosa" | 18 | -- from Machado de Assis, "A M�o e a Rosa" |
19 | local mao = [[ | 19 | local mao = [[ |
20 | Cursavam estes dois moços a academia de S. Paulo, estando | 20 | Cursavam estes dois mo�os a academia de S. Paulo, estando |
21 | Luís Alves no quarto ano e Estêvão no terceiro. | 21 | Lu�s Alves no quarto ano e Est�v�o no terceiro. |
22 | Conheceram-se na academia, e ficaram amigos íntimos, tanto | 22 | Conheceram-se na academia, e ficaram amigos �ntimos, tanto |
23 | quanto podiam sê-lo dois espíritos diferentes, ou talvez por | 23 | quanto podiam s�-lo dois esp�ritos diferentes, ou talvez por |
24 | isso mesmo que o eram. Estêvão, dotado de extrema | 24 | isso mesmo que o eram. Est�v�o, dotado de extrema |
25 | sensibilidade, e não menor fraqueza de ânimo, afetuoso e | 25 | sensibilidade, e n�o menor fraqueza de �nimo, afetuoso e |
26 | bom, não daquela bondade varonil, que é apanágio de uma alma | 26 | bom, n�o daquela bondade varonil, que � apan�gio de uma alma |
27 | forte, mas dessa outra bondade mole e de cera, que vai à | 27 | forte, mas dessa outra bondade mole e de cera, que vai � |
28 | mercê de todas as circunstâncias, tinha, além de tudo isso, | 28 | merc� de todas as circunst�ncias, tinha, al�m de tudo isso, |
29 | o infortúnio de trazer ainda sobre o nariz os óculos | 29 | o infort�nio de trazer ainda sobre o nariz os �culos |
30 | cor-de-rosa de suas virginais ilusões. Luís Alves via bem | 30 | cor-de-rosa de suas virginais ilus�es. Lu�s Alves via bem |
31 | com os olhos da cara. Não era mau rapaz, mas tinha o seu | 31 | com os olhos da cara. N�o era mau rapaz, mas tinha o seu |
32 | grão de egoísmo, e se não era incapaz de afeições, sabia | 32 | gr�o de ego�smo, e se n�o era incapaz de afei��es, sabia |
33 | regê-las, moderá-las, e sobretudo guiá-las ao seu próprio | 33 | reg�-las, moder�-las, e sobretudo gui�-las ao seu pr�prio |
34 | interesse. Entre estes dois homens travara-se amizade | 34 | interesse. Entre estes dois homens travara-se amizade |
35 | íntima, nascida para um na simpatia, para outro no costume. | 35 | �ntima, nascida para um na simpatia, para outro no costume. |
36 | Eram eles os naturais confidentes um do outro, com a | 36 | Eram eles os naturais confidentes um do outro, com a |
37 | diferença que Luís Alves dava menos do que recebia, e, ainda | 37 | diferen�a que Lu�s Alves dava menos do que recebia, e, ainda |
38 | assim, nem tudo o que dava exprimia grande confiança. | 38 | assim, nem tudo o que dava exprimia grande confian�a. |
39 | ]] | 39 | ]] |
40 | 40 | ||
41 | local function random(handle, io_err) | 41 | local function random(handle, io_err) |
@@ -44,8 +44,8 @@ local function random(handle, io_err) | |||
44 | if not handle then error("source is empty!", 2) end | 44 | if not handle then error("source is empty!", 2) end |
45 | local len = math.random(0, 1024) | 45 | local len = math.random(0, 1024) |
46 | local chunk = handle:read(len) | 46 | local chunk = handle:read(len) |
47 | if not chunk then | 47 | if not chunk then |
48 | handle:close() | 48 | handle:close() |
49 | handle = nil | 49 | handle = nil |
50 | end | 50 | end |
51 | return chunk | 51 | return chunk |
@@ -62,7 +62,7 @@ local what = nil | |||
62 | local function transform(input, output, filter) | 62 | local function transform(input, output, filter) |
63 | local source = random(io.open(input, "rb")) | 63 | local source = random(io.open(input, "rb")) |
64 | local sink = ltn12.sink.file(io.open(output, "wb")) | 64 | local sink = ltn12.sink.file(io.open(output, "wb")) |
65 | if what then | 65 | if what then |
66 | sink = ltn12.sink.chain(filter, sink) | 66 | sink = ltn12.sink.chain(filter, sink) |
67 | else | 67 | else |
68 | source = ltn12.source.chain(source, filter) | 68 | source = ltn12.source.chain(source, filter) |
@@ -147,7 +147,7 @@ local function create_qptest() | |||
147 | f:write(' ',string.char(32)) | 147 | f:write(' ',string.char(32)) |
148 | end | 148 | end |
149 | f:write("\r\n") | 149 | f:write("\r\n") |
150 | 150 | ||
151 | f:close() | 151 | f:close() |
152 | end | 152 | end |
153 | 153 | ||
@@ -157,7 +157,7 @@ local function cleanup_qptest() | |||
157 | os.remove(dqptest) | 157 | os.remove(dqptest) |
158 | end | 158 | end |
159 | 159 | ||
160 | -- create test file | 160 | -- create test file |
161 | local function create_b64test() | 161 | local function create_b64test() |
162 | local f = assert(io.open(b64test, "wb")) | 162 | local f = assert(io.open(b64test, "wb")) |
163 | local t = {} | 163 | local t = {} |
diff --git a/test/smtptest.lua b/test/smtptest.lua index b5380ff..9d06054 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
@@ -27,8 +27,8 @@ local total = function() | |||
27 | end | 27 | end |
28 | 28 | ||
29 | local similar = function(s1, s2) | 29 | local similar = function(s1, s2) |
30 | return | 30 | return |
31 | string.lower(string.gsub(s1, "%s", "")) == | 31 | string.lower(string.gsub(s1, "%s", "")) == |
32 | string.lower(string.gsub(s2, "%s", "")) | 32 | string.lower(string.gsub(s2, "%s", "")) |
33 | end | 33 | end |
34 | 34 | ||
@@ -40,9 +40,9 @@ 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() |
@@ -52,7 +52,7 @@ end | |||
52 | local empty = function() | 52 | local empty = function() |
53 | for i,v in ipairs(files) do | 53 | for i,v in ipairs(files) do |
54 | local f = io.open(v, "w") | 54 | local f = io.open(v, "w") |
55 | if not f then | 55 | if not f then |
56 | fail("unable to open file!") | 56 | fail("unable to open file!") |
57 | end | 57 | end |
58 | f:close() | 58 | f:close() |
@@ -116,8 +116,8 @@ local wait = function(sentinel, n) | |||
116 | while 1 do | 116 | while 1 do |
117 | local mbox = parse(get()) | 117 | local mbox = parse(get()) |
118 | if n == #mbox then break end | 118 | if n == #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 |
122 | end | 122 | end |
123 | socket.sleep(1) | 123 | socket.sleep(1) |
@@ -132,7 +132,7 @@ local stuffed_body = [[ | |||
132 | This message body needs to be | 132 | This message body needs to be |
133 | stuffed because it has a dot | 133 | stuffed because it has a dot |
134 | . | 134 | . |
135 | by itself on a line. | 135 | by itself on a line. |
136 | Otherwise the mailer would | 136 | Otherwise the mailer would |
137 | think that the dot | 137 | think that the dot |
138 | . | 138 | . |
@@ -219,7 +219,7 @@ 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") |
@@ -227,7 +227,7 @@ 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 |
diff --git a/test/tcp-getoptions b/test/tcp-getoptions index f9b3d1b..fbcc884 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions | |||
@@ -1,19 +1,35 @@ | |||
1 | #!/usr/bin/env lua | 1 | #!/usr/bin/env lua |
2 | 2 | ||
3 | require"socket" | 3 | local socket = require"socket" |
4 | 4 | ||
5 | port = 8765 | 5 | port = 8765 |
6 | 6 | ||
7 | function pcalltest(msg, o, opt) | ||
8 | local a = { pcall(o.getoption, o, opt) } | ||
9 | if a[1] then | ||
10 | print(msg, opt, unpack(a)) | ||
11 | else | ||
12 | print(msg, opt, 'fail: ' .. a[2]) | ||
13 | end | ||
14 | end | ||
15 | |||
7 | function options(o) | 16 | function options(o) |
8 | print("options for", o) | 17 | print("options for", o) |
9 | 18 | ||
10 | for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do | 19 | for _, opt in ipairs{ |
11 | print("getoption", opt, o:getoption(opt)) | 20 | "keepalive", "reuseaddr", |
21 | "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do | ||
22 | pcalltest("getoption", o, opt) | ||
12 | end | 23 | end |
13 | 24 | ||
14 | print("getoption", "linger", | 25 | r = o:getoption'linger' |
15 | "on", o:getoption("linger").on, | 26 | if r then |
16 | "timeout", o:getoption("linger").timeout) | 27 | print("getoption", "linger", |
28 | "on", r.on, | ||
29 | "timeout", r.timeout) | ||
30 | else | ||
31 | print("getoption", "linger", "no result") | ||
32 | end | ||
17 | end | 33 | end |
18 | 34 | ||
19 | local m = socket.tcp() | 35 | local m = socket.tcp() |
diff --git a/test/test_socket_error.lua b/test/test_socket_error.lua index bda6408..1b4b601 100644 --- a/test/test_socket_error.lua +++ b/test/test_socket_error.lua | |||
@@ -19,7 +19,7 @@ for i = 1, 10 do | |||
19 | assert(ss == sock) | 19 | assert(ss == sock) |
20 | else | 20 | else |
21 | assert('timeout' == err, 'unexpected error :' .. tostring(err)) | 21 | assert('timeout' == err, 'unexpected error :' .. tostring(err)) |
22 | end | 22 | end |
23 | err = sock:getoption("error") -- i get 'connection refused' on WinXP | 23 | err = sock:getoption("error") -- i get 'connection refused' on WinXP |
24 | if err then | 24 | if err then |
25 | print("Passed! Error is '" .. err .. "'.") | 25 | print("Passed! Error is '" .. err .. "'.") |
diff --git a/test/testclnt.lua b/test/testclnt.lua index ee1201f..170e187 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
@@ -669,7 +669,6 @@ local udp_methods = { | |||
669 | "settimeout" | 669 | "settimeout" |
670 | } | 670 | } |
671 | 671 | ||
672 | |||
673 | ------------------------------------------------------------------------ | 672 | ------------------------------------------------------------------------ |
674 | test_methods(socket.udp(), udp_methods) | 673 | test_methods(socket.udp(), udp_methods) |
675 | do local sock = socket.tcp6() | 674 | do local sock = socket.tcp6() |
diff --git a/test/testmesg.lua b/test/testmesg.lua index 135a008..8c086d5 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua | |||
@@ -34,11 +34,11 @@ r, e = smtp.send{ | |||
34 | 34 | ||
35 | print(r, e) | 35 | print(r, e) |
36 | 36 | ||
37 | -- creates a source to send a message with two parts. The first part is | 37 | -- creates a source to send a message with two parts. The first part is |
38 | -- plain text, the second part is a PNG image, encoded as base64. | 38 | -- plain text, the second part is a PNG image, encoded as base64. |
39 | source = smtp.message{ | 39 | source = smtp.message{ |
40 | headers = { | 40 | headers = { |
41 | -- Remember that headers are *ignored* by smtp.send. | 41 | -- Remember that headers are *ignored* by smtp.send. |
42 | from = "Sicrano <sicrano@tecgraf.puc-rio.br>", | 42 | from = "Sicrano <sicrano@tecgraf.puc-rio.br>", |
43 | to = "Fulano <fulano@tecgraf.puc-rio.br>", | 43 | to = "Fulano <fulano@tecgraf.puc-rio.br>", |
44 | subject = "Here is a message with attachments" | 44 | subject = "Here is a message with attachments" |
@@ -49,18 +49,18 @@ source = smtp.message{ | |||
49 | "Preamble might show up even in a MIME enabled client.", | 49 | "Preamble might show up even in a MIME enabled client.", |
50 | -- first part: No headers means plain text, us-ascii. | 50 | -- first part: No headers means plain text, us-ascii. |
51 | -- The mime.eol low-level filter normalizes end-of-line markers. | 51 | -- The mime.eol low-level filter normalizes end-of-line markers. |
52 | [1] = { | 52 | [1] = { |
53 | body = mime.eol(0, [[ | 53 | body = mime.eol(0, [[ |
54 | Lines in a message body should always end with CRLF. | 54 | Lines in a message body should always end with CRLF. |
55 | The smtp module will *NOT* perform translation. It will | 55 | The smtp module will *NOT* perform translation. It will |
56 | perform necessary stuffing, though. | 56 | perform necessary stuffing, though. |
57 | ]]) | 57 | ]]) |
58 | }, | 58 | }, |
59 | -- second part: Headers describe content the to be an image, | 59 | -- second part: Headers describe content the to be an image, |
60 | -- sent under the base64 transfer content encoding. | 60 | -- sent under the base64 transfer content encoding. |
61 | -- Notice that nothing happens until the message is sent. Small | 61 | -- Notice that nothing happens until the message is sent. Small |
62 | -- chunks are loaded into memory and translation happens on the fly. | 62 | -- chunks are loaded into memory and translation happens on the fly. |
63 | [2] = { | 63 | [2] = { |
64 | headers = { | 64 | headers = { |
65 | ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"', | 65 | ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"', |
66 | ["content-disposition"] = 'attachment; filename="luasocket.png"', | 66 | ["content-disposition"] = 'attachment; filename="luasocket.png"', |
diff --git a/test/testsupport.lua b/test/testsupport.lua index b986088..4360b6b 100644 --- a/test/testsupport.lua +++ b/test/testsupport.lua | |||
@@ -7,7 +7,7 @@ function readfile(name) | |||
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 | ||
diff --git a/test/udp-zero-length-send b/test/udp-zero-length-send index a594944..9038c99 100755 --- a/test/udp-zero-length-send +++ b/test/udp-zero-length-send | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/lua | 1 | #!/usr/bin/env lua |
2 | 2 | ||
3 | --[[ | 3 | --[[ |
4 | Show that luasocket returns an error message on zero-length UDP sends, | 4 | Show that luasocket returns an error message on zero-length UDP sends, |
@@ -12,7 +12,7 @@ listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes | |||
12 | 12 | ||
13 | ]] | 13 | ]] |
14 | 14 | ||
15 | require"socket" | 15 | socket = require"socket" |
16 | 16 | ||
17 | s = assert(socket.udp()) | 17 | s = assert(socket.udp()) |
18 | r = assert(socket.udp()) | 18 | r = assert(socket.udp()) |
diff --git a/test/udp-zero-length-send-recv b/test/udp-zero-length-send-recv index 541efd4..064ca52 100755 --- a/test/udp-zero-length-send-recv +++ b/test/udp-zero-length-send-recv | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/lua | 1 | #!/usr/bin/env lua |
2 | 2 | ||
3 | --[[ | 3 | --[[ |
4 | Show that luasocket returns an error message on zero-length UDP sends, | 4 | Show that luasocket returns an error message on zero-length UDP sends, |
@@ -12,7 +12,7 @@ listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes | |||
12 | 12 | ||
13 | ]] | 13 | ]] |
14 | 14 | ||
15 | require"socket" | 15 | socket = require"socket" |
16 | 16 | ||
17 | s = assert(socket.udp()) | 17 | s = assert(socket.udp()) |
18 | r = assert(socket.udp()) | 18 | r = assert(socket.udp()) |
diff --git a/test/unixdgramclnt.lua b/test/unixdgramclnt.lua new file mode 100644 index 0000000..9bd60f7 --- /dev/null +++ b/test/unixdgramclnt.lua | |||
@@ -0,0 +1,9 @@ | |||
1 | socket = require"socket" | ||
2 | socket.unix = require"socket.unix" | ||
3 | c = assert(socket.unix.dgram()) | ||
4 | print(c:bind("/tmp/bar")) | ||
5 | while 1 do | ||
6 | local l = io.read("*l") | ||
7 | assert(c:sendto(l, "/tmp/foo")) | ||
8 | print(assert(c:receivefrom())) | ||
9 | end | ||
diff --git a/test/unixdgramsrvr.lua b/test/unixdgramsrvr.lua new file mode 100644 index 0000000..4c11f55 --- /dev/null +++ b/test/unixdgramsrvr.lua | |||
@@ -0,0 +1,9 @@ | |||
1 | socket = require"socket" | ||
2 | socket.unix = require"socket.unix" | ||
3 | u = assert(socket.unix.dgram()) | ||
4 | assert(u:bind("/tmp/foo")) | ||
5 | while 1 do | ||
6 | x, r = assert(u:receivefrom()) | ||
7 | print(x, r) | ||
8 | assert(u:sendto(">" .. x, r)) | ||
9 | end | ||
diff --git a/test/unixclnt.lua b/test/unixstreamclnt.lua index 5171535..4f2e1e3 100644 --- a/test/unixclnt.lua +++ b/test/unixstreamclnt.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | socket = require"socket" | 1 | socket = require"socket" |
2 | socket.unix = require"socket.unix" | 2 | socket.unix = require"socket.unix" |
3 | c = assert(socket.unix()) | 3 | c = assert(socket.unix.stream()) |
4 | assert(c:connect("/tmp/foo")) | 4 | assert(c:connect("/tmp/foo")) |
5 | while 1 do | 5 | while 1 do |
6 | local l = io.read() | 6 | local l = io.read() |
diff --git a/test/unixsrvr.lua b/test/unixstreamsrvr.lua index 81b9c99..0a5c644 100644 --- a/test/unixsrvr.lua +++ b/test/unixstreamsrvr.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | socket = require"socket" | 1 | socket = require"socket" |
2 | socket.unix = require"socket.unix" | 2 | socket.unix = require"socket.unix" |
3 | u = assert(socket.unix()) | 3 | u = assert(socket.unix.stream()) |
4 | assert(u:bind("/tmp/foo")) | 4 | assert(u:bind("/tmp/foo")) |
5 | assert(u:listen()) | 5 | assert(u:listen()) |
6 | c = assert(u:accept()) | 6 | c = assert(u:accept()) |
diff --git a/test/urltest.lua b/test/urltest.lua index 32cb348..9a3c470 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -60,8 +60,8 @@ 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 base='", base, "', rel='", relative, "' expected '", |
65 | absolute, "' but got '", res, "'\n") | 65 | absolute, "' but got '", res, "'\n") |
66 | os.exit() | 66 | os.exit() |
67 | end | 67 | end |
@@ -73,7 +73,7 @@ local check_parse_url = function(gaba) | |||
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 | os.exit() | 79 | os.exit() |
@@ -81,7 +81,7 @@ local check_parse_url = function(gaba) | |||
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 | os.exit() | 87 | os.exit() |
@@ -91,9 +91,78 @@ end | |||
91 | 91 | ||
92 | print("testing URL parsing") | 92 | print("testing URL parsing") |
93 | check_parse_url{ | 93 | check_parse_url{ |
94 | url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment", | ||
95 | scheme = "scheme", | ||
96 | authority = "user:pass$%?#wd@host:port", | ||
97 | host = "host", | ||
98 | port = "port", | ||
99 | userinfo = "user:pass$%?#wd", | ||
100 | password = "pass$%?#wd", | ||
101 | user = "user", | ||
102 | path = "/path", | ||
103 | params = "params", | ||
104 | query = "query", | ||
105 | fragment = "fragment" | ||
106 | } | ||
107 | check_parse_url{ | ||
108 | url = "scheme://user:pass?#wd@host:port/path;params?query#fragment", | ||
109 | scheme = "scheme", | ||
110 | authority = "user:pass?#wd@host:port", | ||
111 | host = "host", | ||
112 | port = "port", | ||
113 | userinfo = "user:pass?#wd", | ||
114 | password = "pass?#wd", | ||
115 | user = "user", | ||
116 | path = "/path", | ||
117 | params = "params", | ||
118 | query = "query", | ||
119 | fragment = "fragment" | ||
120 | } | ||
121 | check_parse_url{ | ||
122 | url = "scheme://user:pass-wd@host:port/path;params?query#fragment", | ||
123 | scheme = "scheme", | ||
124 | authority = "user:pass-wd@host:port", | ||
125 | host = "host", | ||
126 | port = "port", | ||
127 | userinfo = "user:pass-wd", | ||
128 | password = "pass-wd", | ||
129 | user = "user", | ||
130 | path = "/path", | ||
131 | params = "params", | ||
132 | query = "query", | ||
133 | fragment = "fragment" | ||
134 | } | ||
135 | check_parse_url{ | ||
136 | url = "scheme://user:pass#wd@host:port/path;params?query#fragment", | ||
137 | scheme = "scheme", | ||
138 | authority = "user:pass#wd@host:port", | ||
139 | host = "host", | ||
140 | port = "port", | ||
141 | userinfo = "user:pass#wd", | ||
142 | password = "pass#wd", | ||
143 | user = "user", | ||
144 | path = "/path", | ||
145 | params = "params", | ||
146 | query = "query", | ||
147 | fragment = "fragment" | ||
148 | } | ||
149 | check_parse_url{ | ||
150 | url = "scheme://user:pass#wd@host:port/path;params?query", | ||
151 | scheme = "scheme", | ||
152 | authority = "user:pass#wd@host:port", | ||
153 | host = "host", | ||
154 | port = "port", | ||
155 | userinfo = "user:pass#wd", | ||
156 | password = "pass#wd", | ||
157 | user = "user", | ||
158 | path = "/path", | ||
159 | params = "params", | ||
160 | query = "query", | ||
161 | } | ||
162 | check_parse_url{ | ||
94 | url = "scheme://userinfo@host:port/path;params?query#fragment", | 163 | url = "scheme://userinfo@host:port/path;params?query#fragment", |
95 | scheme = "scheme", | 164 | scheme = "scheme", |
96 | authority = "userinfo@host:port", | 165 | authority = "userinfo@host:port", |
97 | host = "host", | 166 | host = "host", |
98 | port = "port", | 167 | port = "port", |
99 | userinfo = "userinfo", | 168 | userinfo = "userinfo", |
@@ -106,8 +175,8 @@ check_parse_url{ | |||
106 | 175 | ||
107 | check_parse_url{ | 176 | check_parse_url{ |
108 | url = "scheme://user:password@host:port/path;params?query#fragment", | 177 | url = "scheme://user:password@host:port/path;params?query#fragment", |
109 | scheme = "scheme", | 178 | scheme = "scheme", |
110 | authority = "user:password@host:port", | 179 | authority = "user:password@host:port", |
111 | host = "host", | 180 | host = "host", |
112 | port = "port", | 181 | port = "port", |
113 | userinfo = "user:password", | 182 | userinfo = "user:password", |
@@ -121,8 +190,8 @@ check_parse_url{ | |||
121 | 190 | ||
122 | check_parse_url{ | 191 | check_parse_url{ |
123 | url = "scheme://userinfo@host:port/path;params?query#", | 192 | url = "scheme://userinfo@host:port/path;params?query#", |
124 | scheme = "scheme", | 193 | scheme = "scheme", |
125 | authority = "userinfo@host:port", | 194 | authority = "userinfo@host:port", |
126 | host = "host", | 195 | host = "host", |
127 | port = "port", | 196 | port = "port", |
128 | userinfo = "userinfo", | 197 | userinfo = "userinfo", |
@@ -135,8 +204,8 @@ check_parse_url{ | |||
135 | 204 | ||
136 | check_parse_url{ | 205 | check_parse_url{ |
137 | url = "scheme://userinfo@host:port/path;params?#fragment", | 206 | url = "scheme://userinfo@host:port/path;params?#fragment", |
138 | scheme = "scheme", | 207 | scheme = "scheme", |
139 | authority = "userinfo@host:port", | 208 | authority = "userinfo@host:port", |
140 | host = "host", | 209 | host = "host", |
141 | port = "port", | 210 | port = "port", |
142 | userinfo = "userinfo", | 211 | userinfo = "userinfo", |
@@ -149,8 +218,8 @@ check_parse_url{ | |||
149 | 218 | ||
150 | check_parse_url{ | 219 | check_parse_url{ |
151 | url = "scheme://userinfo@host:port/path;params#fragment", | 220 | url = "scheme://userinfo@host:port/path;params#fragment", |
152 | scheme = "scheme", | 221 | scheme = "scheme", |
153 | authority = "userinfo@host:port", | 222 | authority = "userinfo@host:port", |
154 | host = "host", | 223 | host = "host", |
155 | port = "port", | 224 | port = "port", |
156 | userinfo = "userinfo", | 225 | userinfo = "userinfo", |
@@ -162,8 +231,8 @@ check_parse_url{ | |||
162 | 231 | ||
163 | check_parse_url{ | 232 | check_parse_url{ |
164 | url = "scheme://userinfo@host:port/path;?query#fragment", | 233 | url = "scheme://userinfo@host:port/path;?query#fragment", |
165 | scheme = "scheme", | 234 | scheme = "scheme", |
166 | authority = "userinfo@host:port", | 235 | authority = "userinfo@host:port", |
167 | host = "host", | 236 | host = "host", |
168 | port = "port", | 237 | port = "port", |
169 | userinfo = "userinfo", | 238 | userinfo = "userinfo", |
@@ -176,8 +245,8 @@ check_parse_url{ | |||
176 | 245 | ||
177 | check_parse_url{ | 246 | check_parse_url{ |
178 | url = "scheme://userinfo@host:port/path?query#fragment", | 247 | url = "scheme://userinfo@host:port/path?query#fragment", |
179 | scheme = "scheme", | 248 | scheme = "scheme", |
180 | authority = "userinfo@host:port", | 249 | authority = "userinfo@host:port", |
181 | host = "host", | 250 | host = "host", |
182 | port = "port", | 251 | port = "port", |
183 | userinfo = "userinfo", | 252 | userinfo = "userinfo", |
@@ -189,8 +258,8 @@ check_parse_url{ | |||
189 | 258 | ||
190 | check_parse_url{ | 259 | check_parse_url{ |
191 | url = "scheme://userinfo@host:port/;params?query#fragment", | 260 | url = "scheme://userinfo@host:port/;params?query#fragment", |
192 | scheme = "scheme", | 261 | scheme = "scheme", |
193 | authority = "userinfo@host:port", | 262 | authority = "userinfo@host:port", |
194 | host = "host", | 263 | host = "host", |
195 | port = "port", | 264 | port = "port", |
196 | userinfo = "userinfo", | 265 | userinfo = "userinfo", |
@@ -203,8 +272,8 @@ check_parse_url{ | |||
203 | 272 | ||
204 | check_parse_url{ | 273 | check_parse_url{ |
205 | url = "scheme://userinfo@host:port", | 274 | url = "scheme://userinfo@host:port", |
206 | scheme = "scheme", | 275 | scheme = "scheme", |
207 | authority = "userinfo@host:port", | 276 | authority = "userinfo@host:port", |
208 | host = "host", | 277 | host = "host", |
209 | port = "port", | 278 | port = "port", |
210 | userinfo = "userinfo", | 279 | userinfo = "userinfo", |
@@ -213,7 +282,7 @@ check_parse_url{ | |||
213 | 282 | ||
214 | check_parse_url{ | 283 | check_parse_url{ |
215 | url = "//userinfo@host:port/path;params?query#fragment", | 284 | url = "//userinfo@host:port/path;params?query#fragment", |
216 | authority = "userinfo@host:port", | 285 | authority = "userinfo@host:port", |
217 | host = "host", | 286 | host = "host", |
218 | port = "port", | 287 | port = "port", |
219 | userinfo = "userinfo", | 288 | userinfo = "userinfo", |
@@ -226,7 +295,7 @@ check_parse_url{ | |||
226 | 295 | ||
227 | check_parse_url{ | 296 | check_parse_url{ |
228 | url = "//userinfo@host:port/path", | 297 | url = "//userinfo@host:port/path", |
229 | authority = "userinfo@host:port", | 298 | authority = "userinfo@host:port", |
230 | host = "host", | 299 | host = "host", |
231 | port = "port", | 300 | port = "port", |
232 | userinfo = "userinfo", | 301 | userinfo = "userinfo", |
@@ -236,7 +305,7 @@ check_parse_url{ | |||
236 | 305 | ||
237 | check_parse_url{ | 306 | check_parse_url{ |
238 | url = "//userinfo@host/path", | 307 | url = "//userinfo@host/path", |
239 | authority = "userinfo@host", | 308 | authority = "userinfo@host", |
240 | host = "host", | 309 | host = "host", |
241 | userinfo = "userinfo", | 310 | userinfo = "userinfo", |
242 | user = "userinfo", | 311 | user = "userinfo", |
@@ -245,7 +314,7 @@ check_parse_url{ | |||
245 | 314 | ||
246 | check_parse_url{ | 315 | check_parse_url{ |
247 | url = "//user:password@host/path", | 316 | url = "//user:password@host/path", |
248 | authority = "user:password@host", | 317 | authority = "user:password@host", |
249 | host = "host", | 318 | host = "host", |
250 | userinfo = "user:password", | 319 | userinfo = "user:password", |
251 | password = "password", | 320 | password = "password", |
@@ -255,7 +324,7 @@ check_parse_url{ | |||
255 | 324 | ||
256 | check_parse_url{ | 325 | check_parse_url{ |
257 | url = "//user:@host/path", | 326 | url = "//user:@host/path", |
258 | authority = "user:@host", | 327 | authority = "user:@host", |
259 | host = "host", | 328 | host = "host", |
260 | userinfo = "user:", | 329 | userinfo = "user:", |
261 | password = "", | 330 | password = "", |
@@ -265,7 +334,7 @@ check_parse_url{ | |||
265 | 334 | ||
266 | check_parse_url{ | 335 | check_parse_url{ |
267 | url = "//user@host:port/path", | 336 | url = "//user@host:port/path", |
268 | authority = "user@host:port", | 337 | authority = "user@host:port", |
269 | host = "host", | 338 | host = "host", |
270 | userinfo = "user", | 339 | userinfo = "user", |
271 | user = "user", | 340 | user = "user", |
@@ -275,7 +344,7 @@ check_parse_url{ | |||
275 | 344 | ||
276 | check_parse_url{ | 345 | check_parse_url{ |
277 | url = "//host:port/path", | 346 | url = "//host:port/path", |
278 | authority = "host:port", | 347 | authority = "host:port", |
279 | port = "port", | 348 | port = "port", |
280 | host = "host", | 349 | host = "host", |
281 | path = "/path", | 350 | path = "/path", |
@@ -283,14 +352,14 @@ check_parse_url{ | |||
283 | 352 | ||
284 | check_parse_url{ | 353 | check_parse_url{ |
285 | url = "//host/path", | 354 | url = "//host/path", |
286 | authority = "host", | 355 | authority = "host", |
287 | host = "host", | 356 | host = "host", |
288 | path = "/path", | 357 | path = "/path", |
289 | } | 358 | } |
290 | 359 | ||
291 | check_parse_url{ | 360 | check_parse_url{ |
292 | url = "//host", | 361 | url = "//host", |
293 | authority = "host", | 362 | authority = "host", |
294 | host = "host", | 363 | host = "host", |
295 | } | 364 | } |
296 | 365 | ||
@@ -364,7 +433,7 @@ check_parse_url{ | |||
364 | 433 | ||
365 | check_parse_url{ | 434 | check_parse_url{ |
366 | url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", | 435 | url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", |
367 | authority = "userinfo@[::FFFF:129.144.52.38]:port", | 436 | authority = "userinfo@[::FFFF:129.144.52.38]:port", |
368 | host = "::FFFF:129.144.52.38", | 437 | host = "::FFFF:129.144.52.38", |
369 | port = "port", | 438 | port = "port", |
370 | userinfo = "userinfo", | 439 | userinfo = "userinfo", |
@@ -378,7 +447,7 @@ check_parse_url{ | |||
378 | check_parse_url{ | 447 | check_parse_url{ |
379 | url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", | 448 | url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", |
380 | scheme = "scheme", | 449 | scheme = "scheme", |
381 | authority = "user:password@[::192.9.5.5]:port", | 450 | authority = "user:password@[::192.9.5.5]:port", |
382 | host = "::192.9.5.5", | 451 | host = "::192.9.5.5", |
383 | port = "port", | 452 | port = "port", |
384 | userinfo = "user:password", | 453 | userinfo = "user:password", |
@@ -393,7 +462,7 @@ check_parse_url{ | |||
393 | print("testing URL building") | 462 | print("testing URL building") |
394 | check_build_url { | 463 | check_build_url { |
395 | url = "scheme://user:password@host:port/path;params?query#fragment", | 464 | url = "scheme://user:password@host:port/path;params?query#fragment", |
396 | scheme = "scheme", | 465 | scheme = "scheme", |
397 | host = "host", | 466 | host = "host", |
398 | port = "port", | 467 | port = "port", |
399 | user = "user", | 468 | user = "user", |
@@ -430,7 +499,7 @@ check_build_url{ | |||
430 | 499 | ||
431 | check_build_url { | 500 | check_build_url { |
432 | url = "scheme://user:password@host/path;params?query#fragment", | 501 | url = "scheme://user:password@host/path;params?query#fragment", |
433 | scheme = "scheme", | 502 | scheme = "scheme", |
434 | host = "host", | 503 | host = "host", |
435 | user = "user", | 504 | user = "user", |
436 | password = "password", | 505 | password = "password", |
@@ -442,7 +511,7 @@ check_build_url { | |||
442 | 511 | ||
443 | check_build_url { | 512 | check_build_url { |
444 | url = "scheme://user@host/path;params?query#fragment", | 513 | url = "scheme://user@host/path;params?query#fragment", |
445 | scheme = "scheme", | 514 | scheme = "scheme", |
446 | host = "host", | 515 | host = "host", |
447 | user = "user", | 516 | user = "user", |
448 | path = "/path", | 517 | path = "/path", |
@@ -453,7 +522,7 @@ check_build_url { | |||
453 | 522 | ||
454 | check_build_url { | 523 | check_build_url { |
455 | url = "scheme://host/path;params?query#fragment", | 524 | url = "scheme://host/path;params?query#fragment", |
456 | scheme = "scheme", | 525 | scheme = "scheme", |
457 | host = "host", | 526 | host = "host", |
458 | path = "/path", | 527 | path = "/path", |
459 | params = "params", | 528 | params = "params", |
@@ -463,7 +532,7 @@ check_build_url { | |||
463 | 532 | ||
464 | check_build_url { | 533 | check_build_url { |
465 | url = "scheme://host/path;params#fragment", | 534 | url = "scheme://host/path;params#fragment", |
466 | scheme = "scheme", | 535 | scheme = "scheme", |
467 | host = "host", | 536 | host = "host", |
468 | path = "/path", | 537 | path = "/path", |
469 | params = "params", | 538 | params = "params", |
@@ -472,7 +541,7 @@ check_build_url { | |||
472 | 541 | ||
473 | check_build_url { | 542 | check_build_url { |
474 | url = "scheme://host/path#fragment", | 543 | url = "scheme://host/path#fragment", |
475 | scheme = "scheme", | 544 | scheme = "scheme", |
476 | host = "host", | 545 | host = "host", |
477 | path = "/path", | 546 | path = "/path", |
478 | fragment = "fragment" | 547 | fragment = "fragment" |
@@ -480,7 +549,7 @@ check_build_url { | |||
480 | 549 | ||
481 | check_build_url { | 550 | check_build_url { |
482 | url = "scheme://host/path", | 551 | url = "scheme://host/path", |
483 | scheme = "scheme", | 552 | scheme = "scheme", |
484 | host = "host", | 553 | host = "host", |
485 | path = "/path", | 554 | path = "/path", |
486 | } | 555 | } |
@@ -498,7 +567,7 @@ check_build_url { | |||
498 | 567 | ||
499 | check_build_url { | 568 | check_build_url { |
500 | url = "scheme://user:password@host:port/path;params?query#fragment", | 569 | url = "scheme://user:password@host:port/path;params?query#fragment", |
501 | scheme = "scheme", | 570 | scheme = "scheme", |
502 | host = "host", | 571 | host = "host", |
503 | port = "port", | 572 | port = "port", |
504 | user = "user", | 573 | user = "user", |
@@ -512,7 +581,7 @@ check_build_url { | |||
512 | 581 | ||
513 | check_build_url { | 582 | check_build_url { |
514 | url = "scheme://user:password@host:port/path;params?query#fragment", | 583 | url = "scheme://user:password@host:port/path;params?query#fragment", |
515 | scheme = "scheme", | 584 | scheme = "scheme", |
516 | host = "host", | 585 | host = "host", |
517 | port = "port", | 586 | port = "port", |
518 | user = "user", | 587 | user = "user", |
@@ -527,7 +596,7 @@ check_build_url { | |||
527 | 596 | ||
528 | check_build_url { | 597 | check_build_url { |
529 | url = "scheme://user:password@host:port/path;params?query#fragment", | 598 | url = "scheme://user:password@host:port/path;params?query#fragment", |
530 | scheme = "scheme", | 599 | scheme = "scheme", |
531 | host = "host", | 600 | host = "host", |
532 | port = "port", | 601 | port = "port", |
533 | userinfo = "user:password", | 602 | userinfo = "user:password", |
@@ -540,7 +609,7 @@ check_build_url { | |||
540 | 609 | ||
541 | check_build_url { | 610 | check_build_url { |
542 | url = "scheme://user:password@host:port/path;params?query#fragment", | 611 | url = "scheme://user:password@host:port/path;params?query#fragment", |
543 | scheme = "scheme", | 612 | scheme = "scheme", |
544 | authority = "user:password@host:port", | 613 | authority = "user:password@host:port", |
545 | path = "/path", | 614 | path = "/path", |
546 | params = "params", | 615 | params = "params", |
@@ -558,25 +627,37 @@ check_absolute_url("http://a/b/c/d;p?q#f", "/g", "http://a/g") | |||
558 | check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g") | 627 | check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g") |
559 | check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y") | 628 | check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y") |
560 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y") | 629 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y") |
561 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/./x") | 630 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/x") |
562 | check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s") | 631 | check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s") |
563 | check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s") | 632 | check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s") |
564 | check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/./x") | 633 | check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/x") |
565 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s") | 634 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s") |
566 | check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x") | 635 | check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x") |
567 | check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x") | 636 | check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x") |
568 | check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s") | 637 | check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s") |
569 | check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/") | 638 | check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/") |
570 | check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/") | 639 | check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/") |
640 | check_absolute_url("http://a/b/c/d;p?q#f", "./g", "http://a/b/c/g") | ||
641 | check_absolute_url("http://a/b/c/d;p?q#f", "./g/", "http://a/b/c/g/") | ||
642 | check_absolute_url("http://a/b/c/d;p?q#f", "././g", "http://a/b/c/g") | ||
643 | check_absolute_url("http://a/b/c/d;p?q#f", "././g/", "http://a/b/c/g/") | ||
644 | check_absolute_url("http://a/b/c/d;p?q#f", "g/.", "http://a/b/c/g/") | ||
645 | check_absolute_url("http://a/b/c/d;p?q#f", "g/./", "http://a/b/c/g/") | ||
646 | check_absolute_url("http://a/b/c/d;p?q#f", "g/./.", "http://a/b/c/g/") | ||
647 | check_absolute_url("http://a/b/c/d;p?q#f", "g/././", "http://a/b/c/g/") | ||
648 | check_absolute_url("http://a/b/c/d;p?q#f", "./.", "http://a/b/c/") | ||
649 | check_absolute_url("http://a/b/c/d;p?q#f", "././.", "http://a/b/c/") | ||
650 | check_absolute_url("http://a/b/c/d;p?q#f", "././g/./.", "http://a/b/c/g/") | ||
571 | check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/") | 651 | check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/") |
572 | check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/") | 652 | check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/") |
573 | check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g") | 653 | check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g") |
574 | check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/") | 654 | check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/") |
575 | check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/") | 655 | check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/") |
576 | check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g") | 656 | check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g") |
657 | check_absolute_url("http://a/b/c/d;p?q#f", "../../../g", "http://a/g") | ||
577 | check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f") | 658 | check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f") |
578 | check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/./g") | 659 | check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/g") |
579 | check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/../g") | 660 | check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/g") |
580 | check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.") | 661 | check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.") |
581 | check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g") | 662 | check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g") |
582 | check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..") | 663 | check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..") |
@@ -586,31 +667,53 @@ check_absolute_url("http://a/b/c/d;p?q#f", "./g/.", "http://a/b/c/g/") | |||
586 | check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h") | 667 | check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h") |
587 | check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h") | 668 | check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h") |
588 | 669 | ||
670 | check_absolute_url("http://a/b/c/d:p?q#f/", "../g/", "http://a/b/g/") | ||
671 | check_absolute_url("http://a/b/c/d:p?q#f/", "../g", "http://a/b/g") | ||
672 | check_absolute_url("http://a/b/c/d:p?q#f/", "../.g/", "http://a/b/.g/") | ||
673 | check_absolute_url("http://a/b/c/d:p?q#f/", "../.g", "http://a/b/.g") | ||
674 | check_absolute_url("http://a/b/c/d:p?q#f/", "../.g.h/", "http://a/b/.g.h/") | ||
675 | check_absolute_url("http://a/b/c/d:p?q#f/", "../.g.h", "http://a/b/.g.h") | ||
676 | |||
677 | check_absolute_url("http://a/b/c/d:p?q#f/", "g.h/", "http://a/b/c/g.h/") | ||
678 | check_absolute_url("http://a/b/c/d:p?q#f/", "../g.h/", "http://a/b/g.h/") | ||
679 | check_absolute_url("http://a/", "../g.h/", "http://a/g.h/") | ||
680 | |||
589 | -- extra tests | 681 | -- extra tests |
590 | check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f") | 682 | check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f") |
591 | check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f") | 683 | check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f") |
592 | check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f") | 684 | check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f") |
593 | check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f") | 685 | check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f") |
594 | check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", | 686 | check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", |
595 | "http://velox.telemar.com.br/dashboard/index.html") | 687 | "http://velox.telemar.com.br/dashboard/index.html") |
688 | check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/") | ||
689 | check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/") | ||
690 | check_absolute_url("http://example.com/a/b/c/d/", "../q", "http://example.com/a/b/c/q") | ||
691 | check_absolute_url("http://example.com/a/b/c/d/", "../../q", "http://example.com/a/b/q") | ||
692 | check_absolute_url("http://example.com/a/b/c/d/", "../../../q", "http://example.com/a/q") | ||
693 | check_absolute_url("http://example.com", ".badhost.com", "http://example.com/.badhost.com") | ||
694 | check_absolute_url("http://example.com/a/b/c/d/", "..//../../../q", "http://example.com/a/q") | ||
695 | check_absolute_url("http://example.com/a/b/c/d/", "..//a/../../../../q", "http://example.com/a/q") | ||
696 | check_absolute_url("http://example.com/a/b/c/d/", "..//a/..//../../../q", "http://example.com/a/b/q") | ||
697 | check_absolute_url("http://example.com/a/b/c/d/", "..//a/..///../../../../q", "http://example.com/a/b/q") | ||
698 | check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q", "http://example.com/a/b/q") | ||
596 | 699 | ||
597 | print("testing path parsing and composition") | 700 | print("testing path parsing and composition") |
598 | check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) | 701 | check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) |
599 | check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) | 702 | check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) |
600 | check_parse_path("eu/tu/ele/nos/vos/eles/", | 703 | check_parse_path("eu/tu/ele/nos/vos/eles/", |
601 | { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) | 704 | { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) |
602 | check_parse_path("/", { is_absolute = 1, is_directory = 1}) | 705 | check_parse_path("/", { is_absolute = 1, is_directory = 1}) |
603 | check_parse_path("", { }) | 706 | check_parse_path("", { }) |
604 | check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", | 707 | check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", |
605 | { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) | 708 | { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) |
606 | check_parse_path("eu/tu", { "eu", "tu" }) | 709 | check_parse_path("eu/tu", { "eu", "tu" }) |
607 | 710 | ||
608 | print("testing path protection") | 711 | print("testing path protection") |
609 | check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") | 712 | check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") |
610 | check_protect({ "eu ", "~diego" }, "eu%20/~diego") | 713 | check_protect({ "eu ", "~diego" }, "eu%20/~diego") |
611 | check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") | 714 | check_protect({ "/eu>", "<diego?" }, "%2Feu%3E/%3Cdiego%3F") |
612 | check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") | 715 | check_protect({ "\\eu]", "[diego`" }, "%5Ceu%5D/%5Bdiego%60") |
613 | check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") | 716 | check_protect({ "{eu}", "|diego\127" }, "%7Beu%7D/%7Cdiego%7F") |
614 | check_protect({ "eu ", "~diego" }, "eu /~diego", 1) | 717 | check_protect({ "eu ", "~diego" }, "eu /~diego", 1) |
615 | check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1) | 718 | check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1) |
616 | check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1) | 719 | check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1) |
diff --git a/test/utestclnt.lua b/test/utestclnt.lua index 34a0718..7f10643 100644 --- a/test/utestclnt.lua +++ b/test/utestclnt.lua | |||
@@ -54,30 +54,30 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone) | |||
54 | if not err then warn("must be buffered") | 54 | if not err then warn("must be buffered") |
55 | elseif err == "timeout" then pass("proper timeout") | 55 | elseif err == "timeout" then pass("proper timeout") |
56 | else fail("unexpected error '%s'", err) end | 56 | else fail("unexpected error '%s'", err) end |
57 | else | 57 | else |
58 | if err ~= "timeout" then fail("should have timed out") | 58 | if err ~= "timeout" then fail("should have timed out") |
59 | else pass("proper timeout") end | 59 | else pass("proper timeout") end |
60 | end | 60 | end |
61 | else | 61 | else |
62 | if mode == "total" then | 62 | if mode == "total" then |
63 | if elapsed > tm then | 63 | if elapsed > tm then |
64 | if err ~= "timeout" then fail("should have timed out") | 64 | if err ~= "timeout" then fail("should have timed out") |
65 | else pass("proper timeout") end | 65 | else pass("proper timeout") end |
66 | elseif elapsed < tm then | 66 | elseif elapsed < tm then |
67 | if err then fail(err) | 67 | if err then fail(err) |
68 | else pass("ok") end | 68 | else pass("ok") end |
69 | else | 69 | else |
70 | if alldone then | 70 | if alldone then |
71 | if err then fail("unexpected error '%s'", err) | 71 | if err then fail("unexpected error '%s'", err) |
72 | else pass("ok") end | 72 | else pass("ok") end |
73 | else | 73 | else |
74 | if err ~= "timeout" then fail(err) | 74 | if err ~= "timeout" then fail(err) |
75 | else pass("proper timeoutk") end | 75 | else pass("proper timeoutk") end |
76 | end | 76 | end |
77 | end | 77 | end |
78 | else | 78 | else |
79 | if err then fail(err) | 79 | if err then fail(err) |
80 | else pass("ok") end | 80 | else pass("ok") end |
81 | end | 81 | end |
82 | end | 82 | end |
83 | end | 83 | end |
@@ -104,7 +104,7 @@ function reconnect() | |||
104 | print("done " .. i) | 104 | print("done " .. i) |
105 | ]] | 105 | ]] |
106 | data, err = uconnect(host, port) | 106 | data, err = uconnect(host, port) |
107 | if not data then fail(err) | 107 | if not data then fail(err) |
108 | else pass("connected!") end | 108 | else pass("connected!") end |
109 | end | 109 | end |
110 | 110 | ||
@@ -116,8 +116,8 @@ else pass("connected!") end | |||
116 | ------------------------------------------------------------------------ | 116 | ------------------------------------------------------------------------ |
117 | function test_methods(sock, methods) | 117 | function test_methods(sock, methods) |
118 | for _, v in pairs(methods) do | 118 | for _, v in pairs(methods) do |
119 | if type(sock[v]) ~= "function" then | 119 | if type(sock[v]) ~= "function" then |
120 | fail(sock.class .. " method '" .. v .. "' not registered") | 120 | fail(sock.class .. " method '" .. v .. "' not registered") |
121 | end | 121 | end |
122 | end | 122 | end |
123 | pass(sock.class .. " methods are ok") | 123 | pass(sock.class .. " methods are ok") |
@@ -132,7 +132,7 @@ function test_mixed(len) | |||
132 | local p3 = "raw " .. string.rep("z", inter) .. "bytes" | 132 | local p3 = "raw " .. string.rep("z", inter) .. "bytes" |
133 | local p4 = "end" .. string.rep("w", inter) .. "bytes" | 133 | local p4 = "end" .. string.rep("w", inter) .. "bytes" |
134 | local bp1, bp2, bp3, bp4 | 134 | local bp1, bp2, bp3, bp4 |
135 | remote (string.format("str = data:receive(%d)", | 135 | remote (string.format("str = data:receive(%d)", |
136 | string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) | 136 | string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) |
137 | sent, err = data:send(p1..p2..p3..p4) | 137 | sent, err = data:send(p1..p2..p3..p4) |
138 | if err then fail(err) end | 138 | if err then fail(err) end |
@@ -172,7 +172,7 @@ function test_rawline(len) | |||
172 | reconnect() | 172 | reconnect() |
173 | local str, str10, back, err | 173 | local str, str10, back, err |
174 | str = string.rep(string.char(47), math.mod(len, 10)) | 174 | str = string.rep(string.char(47), math.mod(len, 10)) |
175 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), | 175 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), |
176 | math.floor(len/10)) | 176 | math.floor(len/10)) |
177 | str = str .. str10 | 177 | str = str .. str10 |
178 | remote "str = data:receive()" | 178 | remote "str = data:receive()" |
@@ -221,7 +221,7 @@ function test_totaltimeoutreceive(len, tm, sl) | |||
221 | data:settimeout(tm, "total") | 221 | data:settimeout(tm, "total") |
222 | local t = socket.gettime() | 222 | local t = socket.gettime() |
223 | str, err, partial, elapsed = data:receive(2*len) | 223 | str, err, partial, elapsed = data:receive(2*len) |
224 | check_timeout(tm, sl, elapsed, err, "receive", "total", | 224 | check_timeout(tm, sl, elapsed, err, "receive", "total", |
225 | string.len(str or partial) == 2*len) | 225 | string.len(str or partial) == 2*len) |
226 | end | 226 | end |
227 | 227 | ||
@@ -241,7 +241,7 @@ function test_totaltimeoutsend(len, tm, sl) | |||
241 | data:settimeout(tm, "total") | 241 | data:settimeout(tm, "total") |
242 | str = string.rep("a", 2*len) | 242 | str = string.rep("a", 2*len) |
243 | total, err, partial, elapsed = data:send(str) | 243 | total, err, partial, elapsed = data:send(str) |
244 | check_timeout(tm, sl, elapsed, err, "send", "total", | 244 | check_timeout(tm, sl, elapsed, err, "send", "total", |
245 | total == 2*len) | 245 | total == 2*len) |
246 | end | 246 | end |
247 | 247 | ||
@@ -261,7 +261,7 @@ function test_blockingtimeoutreceive(len, tm, sl) | |||
261 | ]], 2*tm, len, sl, sl)) | 261 | ]], 2*tm, len, sl, sl)) |
262 | data:settimeout(tm) | 262 | data:settimeout(tm) |
263 | str, err, partial, elapsed = data:receive(2*len) | 263 | str, err, partial, elapsed = data:receive(2*len) |
264 | check_timeout(tm, sl, elapsed, err, "receive", "blocking", | 264 | check_timeout(tm, sl, elapsed, err, "receive", "blocking", |
265 | string.len(str or partial) == 2*len) | 265 | string.len(str or partial) == 2*len) |
266 | end | 266 | end |
267 | 267 | ||
@@ -294,10 +294,10 @@ function empty_connect() | |||
294 | data = server:accept() | 294 | data = server:accept() |
295 | ]] | 295 | ]] |
296 | data, err = socket.connect("", port) | 296 | data, err = socket.connect("", port) |
297 | if not data then | 297 | if not data then |
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 |
@@ -331,7 +331,7 @@ function test_closed() | |||
331 | data:close() | 331 | data:close() |
332 | data = nil | 332 | data = nil |
333 | ]], str)) | 333 | ]], str)) |
334 | -- try to get a line | 334 | -- try to get a line |
335 | back, err, partial = data:receive() | 335 | back, err, partial = data:receive() |
336 | if not err then fail("should have gotten 'closed'.") | 336 | if not err then fail("should have gotten 'closed'.") |
337 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") | 337 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") |
@@ -344,25 +344,25 @@ function test_closed() | |||
344 | data = nil | 344 | data = nil |
345 | ]] | 345 | ]] |
346 | total, err, partial = data:send(string.rep("ugauga", 100000)) | 346 | total, err, partial = data:send(string.rep("ugauga", 100000)) |
347 | if not err then | 347 | if not err then |
348 | pass("failed: output buffer is at least %d bytes long!", total) | 348 | pass("failed: output buffer is at least %d bytes long!", total) |
349 | elseif err ~= "closed" then | 349 | elseif err ~= "closed" then |
350 | fail("got '"..err.."' instead of 'closed'.") | 350 | fail("got '"..err.."' instead of 'closed'.") |
351 | else | 351 | else |
352 | pass("graceful 'closed' received after %d bytes were sent", partial) | 352 | pass("graceful 'closed' received after %d bytes were sent", partial) |
353 | end | 353 | end |
354 | end | 354 | end |
355 | 355 | ||
356 | ------------------------------------------------------------------------ | 356 | ------------------------------------------------------------------------ |
357 | function test_selectbugs() | 357 | function test_selectbugs() |
358 | local r, s, e = socket.select(nil, nil, 0.1) | 358 | local r, s, e = socket.select(nil, nil, 0.1) |
359 | assert(type(r) == "table" and type(s) == "table" and | 359 | assert(type(r) == "table" and type(s) == "table" and |
360 | (e == "timeout" or e == "error")) | 360 | (e == "timeout" or e == "error")) |
361 | pass("both nil: ok") | 361 | pass("both nil: ok") |
362 | local udp = socket.udp() | 362 | local udp = socket.udp() |
363 | udp:close() | 363 | udp:close() |
364 | r, s, e = socket.select({ udp }, { udp }, 0.1) | 364 | r, s, e = socket.select({ udp }, { udp }, 0.1) |
365 | assert(type(r) == "table" and type(s) == "table" and | 365 | assert(type(r) == "table" and type(s) == "table" and |
366 | (e == "timeout" or e == "error")) | 366 | (e == "timeout" or e == "error")) |
367 | pass("closed sockets: ok") | 367 | pass("closed sockets: ok") |
368 | e = pcall(socket.select, "wrong", 1, 0.1) | 368 | e = pcall(socket.select, "wrong", 1, 0.1) |
@@ -380,7 +380,7 @@ function accept_timeout() | |||
380 | local t = socket.gettime() | 380 | local t = socket.gettime() |
381 | s:settimeout(1) | 381 | s:settimeout(1) |
382 | local c, e = s:accept() | 382 | local c, e = s:accept() |
383 | assert(not c, "should not accept") | 383 | assert(not c, "should not accept") |
384 | assert(e == "timeout", string.format("wrong error message (%s)", e)) | 384 | assert(e == "timeout", string.format("wrong error message (%s)", e)) |
385 | t = socket.gettime() - t | 385 | t = socket.gettime() - t |
386 | assert(t < 2, string.format("took to long to give up (%gs)", t)) | 386 | assert(t < 2, string.format("took to long to give up (%gs)", t)) |
@@ -398,9 +398,9 @@ function connect_timeout() | |||
398 | local t = socket.gettime() | 398 | local t = socket.gettime() |
399 | local r, e = c:connect("127.0.0.2", 80) | 399 | local r, e = c:connect("127.0.0.2", 80) |
400 | assert(not r, "should not connect") | 400 | assert(not r, "should not connect") |
401 | assert(socket.gettime() - t < 2, "took too long to give up.") | 401 | assert(socket.gettime() - t < 2, "took too long to give up.") |
402 | c:close() | 402 | c:close() |
403 | print("ok") | 403 | print("ok") |
404 | end | 404 | end |
405 | 405 | ||
406 | ------------------------------------------------------------------------ | 406 | ------------------------------------------------------------------------ |
@@ -463,9 +463,9 @@ function getstats_test() | |||
463 | data:receive(c) | 463 | data:receive(c) |
464 | t = t + c | 464 | t = t + c |
465 | local r, s, a = data:getstats() | 465 | local r, s, a = data:getstats() |
466 | assert(r == t, "received count failed" .. tostring(r) | 466 | assert(r == t, "received count failed" .. tostring(r) |
467 | .. "/" .. tostring(t)) | 467 | .. "/" .. tostring(t)) |
468 | assert(s == t, "sent count failed" .. tostring(s) | 468 | assert(s == t, "sent count failed" .. tostring(s) |
469 | .. "/" .. tostring(t)) | 469 | .. "/" .. tostring(t)) |
470 | end | 470 | end |
471 | print("ok") | 471 | print("ok") |
@@ -473,7 +473,7 @@ end | |||
473 | 473 | ||
474 | 474 | ||
475 | ------------------------------------------------------------------------ | 475 | ------------------------------------------------------------------------ |
476 | function test_nonblocking(size) | 476 | function test_nonblocking(size) |
477 | reconnect() | 477 | reconnect() |
478 | print("Testing " .. 2*size .. " bytes") | 478 | print("Testing " .. 2*size .. " bytes") |
479 | remote(string.format([[ | 479 | remote(string.format([[ |
diff --git a/test/utestsrvr.lua b/test/utestsrvr.lua index a96b570..b6e4246 100644 --- a/test/utestsrvr.lua +++ b/test/utestsrvr.lua | |||
@@ -9,7 +9,7 @@ ack = "\n"; | |||
9 | while 1 do | 9 | while 1 do |
10 | print("server: waiting for client connection..."); | 10 | print("server: waiting for client connection..."); |
11 | control = assert(server:accept()); | 11 | control = assert(server:accept()); |
12 | while 1 do | 12 | while 1 do |
13 | command = assert(control:receive()); | 13 | command = assert(control:receive()); |
14 | assert(control:send(ack)); | 14 | assert(control:send(ack)); |
15 | ((loadstring or load)(command))(); | 15 | ((loadstring or load)(command))(); |