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