Finish port to Lua 5. Everything is working fine.
Still doesn't work in Windows.
This commit is contained in:
parent
7da19138e3
commit
53857360bb
11 changed files with 289 additions and 277 deletions
122
test/ftptest.lua
122
test/ftptest.lua
|
@ -1,29 +1,32 @@
|
|||
dofile("noglobals.lua")
|
||||
|
||||
local similar = function(s1, s2)
|
||||
return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", ""))
|
||||
end
|
||||
|
||||
local capture = function(cmd)
|
||||
readfrom("| " .. cmd)
|
||||
local s = read("*a")
|
||||
readfrom()
|
||||
return s
|
||||
return
|
||||
string.lower(string.gsub(s1, "%s", "")) ==
|
||||
string.lower(string.gsub(s2, "%s", ""))
|
||||
end
|
||||
|
||||
local readfile = function(name)
|
||||
local f = readfrom(name)
|
||||
if not f then return nil end
|
||||
local s = read("*a")
|
||||
readfrom()
|
||||
return s
|
||||
local f = io.open(name, "r")
|
||||
if not f then return nil end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local capture = function(cmd)
|
||||
local f = io.popen(cmd)
|
||||
if not f then return nil end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local check = function(v, e, o)
|
||||
e = e or "failed!"
|
||||
o = o or "ok"
|
||||
if v then print(o)
|
||||
else print(e) exit() end
|
||||
else print(e) os.exit() end
|
||||
end
|
||||
|
||||
-- needs an account luasocket:password
|
||||
|
@ -31,81 +34,82 @@ end
|
|||
|
||||
local index, err, saved, back, expected
|
||||
|
||||
local t = _time()
|
||||
local t = socket._time()
|
||||
|
||||
index = readfile("index.html")
|
||||
index = readfile("test/index.html")
|
||||
|
||||
write("testing file upload: ")
|
||||
remove("/var/ftp/dir1/index.up.html")
|
||||
err = FTP.put("ftp://localhost/dir1/index.up.html;type=i", index)
|
||||
saved = readfile("/var/ftp/dir1/index.up.html")
|
||||
io.write("testing wrong scheme: ")
|
||||
back, err = socket.ftp.get("wrong://banana.com/lixo")
|
||||
check(not back and err == "unknown scheme 'wrong'", err)
|
||||
|
||||
io.write("testing invalid url: ")
|
||||
back, err = socket.ftp.get("localhost/dir1/index.html;type=i")
|
||||
local c, e = socket.connect("", 21)
|
||||
check(not back and err == e, err)
|
||||
|
||||
io.write("testing anonymous file upload: ")
|
||||
os.remove("/var/ftp/pub/index.up.html")
|
||||
err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index)
|
||||
saved = readfile("/var/ftp/pub/index.up.html")
|
||||
check(not err and saved == index, err)
|
||||
|
||||
write("testing file download: ")
|
||||
back, err = FTP.get("ftp://localhost/dir1/index.up.html;type=i")
|
||||
io.write("testing anonymous file download: ")
|
||||
back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i")
|
||||
check(not err and back == index, err)
|
||||
|
||||
write("testing no directory changes: ")
|
||||
back, err = FTP.get("ftp://localhost/index.html;type=i")
|
||||
io.write("testing no directory changes: ")
|
||||
back, err = socket.ftp.get("ftp://localhost/index.html;type=i")
|
||||
check(not err and back == index, err)
|
||||
|
||||
write("testing multiple directory changes: ")
|
||||
back, err = FTP.get("ftp://localhost/dir1/dir2/dir3/dir4/dir5/dir6/index.html;type=i")
|
||||
io.write("testing multiple directory changes: ")
|
||||
back, err = socket.ftp.get("ftp://localhost/pub/dir1/dir2/dir3/dir4/dir5/index.html;type=i")
|
||||
check(not err and back == index, err)
|
||||
|
||||
write("testing authenticated upload: ")
|
||||
remove("/home/luasocket/index.up.html")
|
||||
err = FTP.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
|
||||
io.write("testing authenticated upload: ")
|
||||
os.remove("/home/luasocket/index.up.html")
|
||||
err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
|
||||
saved = readfile("/home/luasocket/index.up.html")
|
||||
check(not err and saved == index, err)
|
||||
|
||||
write("testing authenticated download: ")
|
||||
back, err = FTP.get("ftp://luasocket:password@localhost/index.up.html;type=i")
|
||||
io.write("testing authenticated download: ")
|
||||
back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i")
|
||||
check(not err and back == index, err)
|
||||
|
||||
write("testing weird-character translation: ")
|
||||
back, err = FTP.get("ftp://luasocket:password@localhost/%2fvar/ftp/dir1/index.html;type=i")
|
||||
io.write("testing weird-character translation: ")
|
||||
back, err = socket.ftp.get("ftp://luasocket:password@localhost/%2fvar/ftp/pub/index.html;type=i")
|
||||
check(not err and back == index, err)
|
||||
|
||||
write("testing parameter overriding: ")
|
||||
back, err = FTP.get {
|
||||
url = "//stupid:mistake@localhost/dir1/index.html",
|
||||
io.write("testing parameter overriding: ")
|
||||
back, err = socket.ftp.get {
|
||||
url = "//stupid:mistake@localhost/index.html",
|
||||
user = "luasocket",
|
||||
password = "password",
|
||||
type = "i"
|
||||
}
|
||||
check(not err and back == index, err)
|
||||
|
||||
write("testing wrong scheme: ")
|
||||
back, err = FTP.get("wrong://banana.com/lixo")
|
||||
check(not back and err == "unknown scheme 'wrong'", err)
|
||||
|
||||
write("testing invalid url: ")
|
||||
back, err = FTP.get("localhost/dir1/index.html;type=i")
|
||||
local c, e = connect("", 21)
|
||||
check(not back and err == e, err)
|
||||
|
||||
write("testing directory listing: ")
|
||||
expected = capture("ls -F /var/ftp/dir1 | grep -v /")
|
||||
back, err = FTP.get("ftp://localhost/dir1;type=d")
|
||||
check(similar(back, expected))
|
||||
|
||||
write("testing home directory listing: ")
|
||||
io.write("testing home directory listing: ")
|
||||
expected = capture("ls -F /var/ftp | grep -v /")
|
||||
back, err = FTP.get("ftp://localhost/")
|
||||
back, err = socket.ftp.get("ftp://localhost/")
|
||||
check(back and similar(back, expected), nil, err)
|
||||
|
||||
write("testing upload denial: ")
|
||||
err = FTP.put("ftp://localhost/index.up.html;type=a", index)
|
||||
io.write("testing directory listing: ")
|
||||
expected = capture("ls -F /var/ftp/pub | grep -v /")
|
||||
back, err = socket.ftp.get("ftp://localhost/pub;type=d")
|
||||
check(similar(back, expected))
|
||||
|
||||
io.write("testing upload denial: ")
|
||||
err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index)
|
||||
check(err, err)
|
||||
|
||||
write("testing authentication failure: ")
|
||||
err = FTP.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
|
||||
io.write("testing authentication failure: ")
|
||||
err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
|
||||
print(err)
|
||||
check(err, err)
|
||||
|
||||
write("testing wrong file: ")
|
||||
back, err = FTP.get("ftp://localhost/index.wrong.html;type=a")
|
||||
io.write("testing wrong file: ")
|
||||
back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a")
|
||||
check(err, err)
|
||||
|
||||
print("passed all tests")
|
||||
print(format("done in %.2fs", _time() - t))
|
||||
print(string.format("done in %.2fs", socket._time() - t))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue