diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/dicttest.lua | 2 | ||||
-rw-r--r-- | test/ftptest.lua | 155 | ||||
-rw-r--r-- | test/httptest.lua | 2 | ||||
-rw-r--r-- | test/testclnt.lua | 5 | ||||
-rw-r--r-- | test/testmesg.lua | 7 | ||||
-rw-r--r-- | test/testsrvr.lua | 2 | ||||
-rw-r--r-- | test/tftptest.lua | 2 |
7 files changed, 92 insertions, 83 deletions
diff --git a/test/dicttest.lua b/test/dicttest.lua index fcdd61f..a37ec8d 100644 --- a/test/dicttest.lua +++ b/test/dicttest.lua | |||
@@ -1,3 +1,3 @@ | |||
1 | local dict = require"socket.dict" | 1 | local dict = require"socket.dict" |
2 | 2 | ||
3 | for i,v in dict.get("dict://localhost/d:banana") do print(v) end | 3 | for i,v in dict.get("dict://dell-diego/d:banana") do print(v) end |
diff --git a/test/ftptest.lua b/test/ftptest.lua index f578c82..ef1bf0f 100644 --- a/test/ftptest.lua +++ b/test/ftptest.lua | |||
@@ -1,103 +1,110 @@ | |||
1 | local similar = function(s1, s2) | 1 | local socket = require("socket") |
2 | return | 2 | local ftp = require("socket.ftp") |
3 | string.lower(string.gsub(s1, "%s", "")) == | 3 | local url = require("socket.url") |
4 | string.lower(string.gsub(s2, "%s", "")) | 4 | local ltn12 = require("ltn12") |
5 | end | ||
6 | 5 | ||
7 | local readfile = function(name) | 6 | -- override protection to make sure we see all errors |
8 | local f = io.open(name, "r") | 7 | --socket.protect = function(s) return s end |
9 | if not f then return nil end | ||
10 | local s = f:read("*a") | ||
11 | f:close() | ||
12 | return s | ||
13 | end | ||
14 | 8 | ||
15 | local capture = function(cmd) | 9 | dofile("testsupport.lua") |
16 | local f = io.popen(cmd) | ||
17 | if not f then return nil end | ||
18 | local s = f:read("*a") | ||
19 | f:close() | ||
20 | return s | ||
21 | end | ||
22 | 10 | ||
23 | local check = function(v, e, o) | 11 | local host, port, index_file, index, back, err, ret |
24 | e = e or "failed!" | ||
25 | o = o or "ok" | ||
26 | if v then print(o) | ||
27 | else print(e) os.exit() end | ||
28 | end | ||
29 | 12 | ||
30 | -- needs an account luasocket:password | 13 | local t = socket.gettime() |
31 | -- and some directories and files in ~ftp | ||
32 | 14 | ||
33 | local index, err, saved, back, expected | 15 | host = host or "diego.student.princeton.edu" |
16 | index_file = "test/index.html" | ||
34 | 17 | ||
35 | local t = socket.time() | ||
36 | 18 | ||
37 | index = readfile("test/index.html") | 19 | -- a function that returns a directory listing |
20 | local function nlst(u) | ||
21 | local t = {} | ||
22 | local p = url.parse(u) | ||
23 | p.command = "nlst" | ||
24 | p.sink = ltn12.sink.table(t) | ||
25 | local r, e = ftp.get(p) | ||
26 | return r and table.concat(t), e | ||
27 | end | ||
28 | |||
29 | -- function that removes a remote file | ||
30 | local function dele(u) | ||
31 | local p = url.parse(u) | ||
32 | p.command = "dele" | ||
33 | p.argument = string.gsub(p.path, "^/", "") | ||
34 | if p.argumet == "" then p.argument = nil end | ||
35 | p.check = 250 | ||
36 | return ftp.command(p) | ||
37 | end | ||
38 | |||
39 | -- read index with CRLF convention | ||
40 | index = readfile(index_file) | ||
38 | 41 | ||
39 | io.write("testing wrong scheme: ") | 42 | io.write("testing wrong scheme: ") |
40 | back, err = socket.ftp.get("wrong://banana.com/lixo") | 43 | back, err = ftp.get("wrong://banana.com/lixo") |
41 | check(not back and err == "unknown scheme 'wrong'", err) | 44 | assert(not back and err == "wrong scheme 'wrong'", err) |
45 | print("ok") | ||
42 | 46 | ||
43 | io.write("testing invalid url: ") | 47 | io.write("testing invalid url: ") |
44 | back, err = socket.ftp.get("localhost/dir1/index.html;type=i") | 48 | back, err = ftp.get("localhost/dir1/index.html;type=i") |
45 | local c, e = socket.connect("", 21) | 49 | assert(not back and err) |
46 | check(not back and err == e, err) | 50 | print("ok") |
47 | |||
48 | io.write("testing anonymous file upload: ") | ||
49 | os.remove("/var/ftp/pub/index.up.html") | ||
50 | ret, err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index) | ||
51 | saved = readfile("/var/ftp/pub/index.up.html") | ||
52 | check(ret and not err and saved == index, err) | ||
53 | 51 | ||
54 | io.write("testing anonymous file download: ") | 52 | io.write("testing anonymous file download: ") |
55 | back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i") | 53 | back, err = socket.ftp.get("ftp://" .. host .. "/pub/index.html;type=i") |
56 | check(not err and back == index, err) | 54 | assert(not err and back == index, err) |
57 | 55 | print("ok") | |
58 | io.write("testing no directory changes: ") | 56 | |
59 | back, err = socket.ftp.get("ftp://localhost/index.html;type=i") | 57 | io.write("erasing before upload: ") |
60 | check(not err and back == index, err) | 58 | ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") |
61 | 59 | if not ret then print(err) | |
62 | io.write("testing multiple directory changes: ") | 60 | else print("ok") end |
63 | back, err = socket.ftp.get("ftp://localhost/pub/dir1/dir2/dir3/dir4/dir5/index.html;type=i") | 61 | |
64 | check(not err and back == index, err) | 62 | io.write("testing upload: ") |
65 | 63 | ret, err = ftp.put("ftp://luasocket:password@" .. host .. "/index.up.html;type=i", index) | |
66 | io.write("testing authenticated upload: ") | 64 | assert(ret and not err, err) |
67 | os.remove("/home/luasocket/index.up.html") | 65 | print("ok") |
68 | ret, err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) | 66 | |
69 | saved = readfile("/home/luasocket/index.up.html") | 67 | io.write("downloading uploaded file: ") |
70 | check(ret and not err and saved == index, err) | 68 | back, err = ftp.get("ftp://luasocket:password@" .. host .. "/index.up.html;type=i") |
71 | 69 | assert(ret and not err and index == back, err) | |
72 | io.write("testing authenticated download: ") | 70 | print("ok") |
73 | back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i") | 71 | |
74 | check(not err and back == index, err) | 72 | io.write("erasing after upload/download: ") |
73 | ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") | ||
74 | assert(ret and not err, err) | ||
75 | print("ok") | ||
75 | 76 | ||
76 | io.write("testing weird-character translation: ") | 77 | io.write("testing weird-character translation: ") |
77 | back, err = socket.ftp.get("ftp://luasocket:password@localhost/%2fvar/ftp/pub/index.html;type=i") | 78 | back, err = ftp.get("ftp://luasocket:password@" .. host .. "/%23%3f;type=i") |
78 | check(not err and back == index, err) | 79 | assert(not err and back == index, err) |
80 | print("ok") | ||
79 | 81 | ||
80 | io.write("testing parameter overriding: ") | 82 | io.write("testing parameter overriding: ") |
81 | back, err = socket.ftp.get { | 83 | local back = {} |
82 | url = "//stupid:mistake@localhost/index.html", | 84 | ret, err = ftp.get{ |
85 | url = "//stupid:mistake@" .. host .. "/index.html", | ||
83 | user = "luasocket", | 86 | user = "luasocket", |
84 | password = "password", | 87 | password = "password", |
85 | type = "i" | 88 | type = "i", |
89 | sink = ltn12.sink.table(back) | ||
86 | } | 90 | } |
87 | check(not err and back == index, err) | 91 | assert(ret and not err and table.concat(back) == index, err) |
92 | print("ok") | ||
88 | 93 | ||
89 | io.write("testing upload denial: ") | 94 | io.write("testing upload denial: ") |
90 | ret, err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index) | 95 | ret, err = ftp.put("ftp://" .. host .. "/index.up.html;type=a", index) |
91 | check(err, err) | 96 | assert(not ret and err, "should have failed") |
97 | print(err) | ||
92 | 98 | ||
93 | io.write("testing authentication failure: ") | 99 | io.write("testing authentication failure: ") |
94 | ret, err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) | 100 | ret, err = ftp.get("ftp://luasocket:wrong@".. host .. "/index.html;type=a") |
101 | assert(not ret and err, "should have failed") | ||
95 | print(err) | 102 | print(err) |
96 | check(not ret and err, err) | ||
97 | 103 | ||
98 | io.write("testing wrong file: ") | 104 | io.write("testing wrong file: ") |
99 | back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a") | 105 | back, err = ftp.get("ftp://".. host .. "/index.wrong.html;type=a") |
100 | check(err, err) | 106 | assert(not back and err, "should have failed") |
107 | print(err) | ||
101 | 108 | ||
102 | print("passed all tests") | 109 | print("passed all tests") |
103 | print(string.format("done in %.2fs", socket.time() - t)) | 110 | print(string.format("done in %.2fs", socket.gettime() - t)) |
diff --git a/test/httptest.lua b/test/httptest.lua index 71021a4..cade837 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -23,7 +23,7 @@ http.TIMEOUT = 10 | |||
23 | local t = socket.gettime() | 23 | local t = socket.gettime() |
24 | 24 | ||
25 | host = host or "diego.student.princeton.edu" | 25 | host = host or "diego.student.princeton.edu" |
26 | proxy = proxy or "http://localhost:3128" | 26 | proxy = proxy or "http://dell-diego.cs.princeton.edu:3128" |
27 | prefix = prefix or "/luasocket-test" | 27 | prefix = prefix or "/luasocket-test" |
28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
29 | index_file = "test/index.html" | 29 | index_file = "test/index.html" |
diff --git a/test/testclnt.lua b/test/testclnt.lua index f838533..c2c782c 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
@@ -1,7 +1,7 @@ | |||
1 | local socket = require"socket" | 1 | local socket = require"socket" |
2 | 2 | ||
3 | host = host or "localhost" | 3 | host = host or "localhost" |
4 | port = port or "8080" | 4 | port = port or "8383" |
5 | 5 | ||
6 | function pass(...) | 6 | function pass(...) |
7 | local s = string.format(unpack(arg)) | 7 | local s = string.format(unpack(arg)) |
@@ -590,7 +590,6 @@ test_mixed(200) | |||
590 | test_mixed(17) | 590 | test_mixed(17) |
591 | test_mixed(1) | 591 | test_mixed(1) |
592 | 592 | ||
593 | |||
594 | test("binary line") | 593 | test("binary line") |
595 | test_rawline(1) | 594 | test_rawline(1) |
596 | test_rawline(17) | 595 | test_rawline(17) |
@@ -630,14 +629,12 @@ test_nonblocking(200) | |||
630 | test_nonblocking(17) | 629 | test_nonblocking(17) |
631 | test_nonblocking(1) | 630 | test_nonblocking(1) |
632 | 631 | ||
633 | |||
634 | test("total timeout on send") | 632 | test("total timeout on send") |
635 | test_totaltimeoutsend(800091, 1, 3) | 633 | test_totaltimeoutsend(800091, 1, 3) |
636 | test_totaltimeoutsend(800091, 2, 3) | 634 | test_totaltimeoutsend(800091, 2, 3) |
637 | test_totaltimeoutsend(800091, 5, 2) | 635 | test_totaltimeoutsend(800091, 5, 2) |
638 | test_totaltimeoutsend(800091, 3, 1) | 636 | test_totaltimeoutsend(800091, 3, 1) |
639 | 637 | ||
640 | |||
641 | test("total timeout on receive") | 638 | test("total timeout on receive") |
642 | test_totaltimeoutreceive(800091, 1, 3) | 639 | test_totaltimeoutreceive(800091, 1, 3) |
643 | test_totaltimeoutreceive(800091, 2, 3) | 640 | test_totaltimeoutreceive(800091, 2, 3) |
diff --git a/test/testmesg.lua b/test/testmesg.lua index e29b3cb..5350921 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | -- load the smtp support and its friends | 1 | -- load the smtp support and its friends |
2 | local smtp = require("smtp") | 2 | local smtp = require("socket.smtp") |
3 | local mime = require("mime") | 3 | local mime = require("mime") |
4 | local ltn12 = require("ltn12") | 4 | local ltn12 = require("ltn12") |
5 | 5 | ||
@@ -48,6 +48,11 @@ source = smtp.message{ | |||
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | --[[ | ||
52 | sink = ltn12.sink.file(io.stdout) | ||
53 | ltn12.pump.all(source, sink) | ||
54 | ]] | ||
55 | |||
51 | -- finally send it | 56 | -- finally send it |
52 | r, e = smtp.send{ | 57 | r, e = smtp.send{ |
53 | rcpt = {"<diego@tecgraf.puc-rio.br>", | 58 | rcpt = {"<diego@tecgraf.puc-rio.br>", |
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index 23e3850..2408e83 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | socket = require("socket"); | 1 | socket = require("socket"); |
2 | host = host or "localhost"; | 2 | host = host or "localhost"; |
3 | port = port or "8080"; | 3 | port = port or "8383"; |
4 | server = assert(socket.bind(host, port)); | 4 | server = assert(socket.bind(host, port)); |
5 | ack = "\n"; | 5 | ack = "\n"; |
6 | while 1 do | 6 | while 1 do |
diff --git a/test/tftptest.lua b/test/tftptest.lua index edb6484..35078e8 100644 --- a/test/tftptest.lua +++ b/test/tftptest.lua | |||
@@ -12,7 +12,7 @@ function readfile(file) | |||
12 | return a | 12 | return a |
13 | end | 13 | end |
14 | 14 | ||
15 | host = host or "localhost" | 15 | host = host or "diego.student.princeton.edu" |
16 | retrieved, err = tftp.get("tftp://" .. host .."/index.html") | 16 | retrieved, err = tftp.get("tftp://" .. host .."/index.html") |
17 | assert(not err, err) | 17 | assert(not err, err) |
18 | original = readfile("test/index.html") | 18 | original = readfile("test/index.html") |