Initial revision
This commit is contained in:
parent
68f51243b3
commit
7096b8df82
6 changed files with 191 additions and 0 deletions
33
test/ftptest.lua
Normal file
33
test/ftptest.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
assert(dofile("../lua/ftp.lua"))
|
||||
assert(dofile("auxiliar.lua"))
|
||||
|
||||
pdir = "/home/i/diego/public/html/luasocket/test/"
|
||||
ldir = "/home/luasocket/"
|
||||
adir = "/home/ftp/test/"
|
||||
|
||||
-- needs an accound luasocket:password
|
||||
-- and a copy of /home/i/diego/public/html/luasocket/test in ~ftp/test
|
||||
|
||||
print("testing authenticated upload")
|
||||
bf = readfile(pdir .. "index.html")
|
||||
e = ftp_put("ftp://luasocket:password@localhost/index.html", bf, "b")
|
||||
assert(not e, e)
|
||||
assert(compare(ldir .. "index.html", bf), "files differ")
|
||||
remove(ldir .. "index.html")
|
||||
|
||||
print("testing authenticated download")
|
||||
f, e = ftp_get("ftp://luasocket:password@localhost/test/index.html", "b")
|
||||
assert(f, e)
|
||||
assert(compare(pdir .. "index.html", f), "files differ")
|
||||
|
||||
print("testing anonymous download")
|
||||
f, e = ftp_get("ftp://localhost/test/index.html", "b")
|
||||
assert(f, e)
|
||||
assert(compare(adir .. "index.html", f), "files differ")
|
||||
|
||||
print("testing directory listing")
|
||||
f, e = ftp_get("ftp://localhost/test/")
|
||||
assert(f, e)
|
||||
assert(f == "index.html\r\n", "files differ")
|
||||
|
||||
print("passed all tests")
|
85
test/httptest.lua
Normal file
85
test/httptest.lua
Normal file
|
@ -0,0 +1,85 @@
|
|||
-- load http
|
||||
assert(dofile("../lua/http.lua"))
|
||||
assert(dofile("../lua/base64.lua"))
|
||||
assert(dofile("auxiliar.lua"))
|
||||
|
||||
-- needs Alias from /home/i/diego/public/html/luasocket/test to
|
||||
-- /luasocket-test
|
||||
-- needs ScriptAlias from /home/i/diego/public/html/luasocket/test/cgi-bin
|
||||
-- to /luasocket-cgi-bin/
|
||||
|
||||
function join(s, e)
|
||||
return tostring(s) .. ":" .. tostring(e)
|
||||
end
|
||||
|
||||
function status(s)
|
||||
local code
|
||||
_,_, code = strfind(s, "(%d%d%d)")
|
||||
return tonumber(code)
|
||||
end
|
||||
|
||||
pdir = pdir or "/home/i/diego/public/html/luasocket/test/"
|
||||
host = host or "localhost"
|
||||
|
||||
print("testing document retrieval")
|
||||
url = "http://" .. host .. "/luasocket-test/index.html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e, join(s, e))
|
||||
assert(compare(pdir .. "index.html", f), "documents differ")
|
||||
|
||||
print("testing HTTP redirection")
|
||||
url = "http://" .. host .. "/luasocket-test"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e, join(s, e))
|
||||
assert(compare(pdir .. "index.html", f), "documents differ")
|
||||
|
||||
print("testing cgi output retrieval (probably chunked...)")
|
||||
url = "http://" .. host .. "/luasocket-cgi-bin/cat-index-html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e, join(s, e))
|
||||
assert(compare(pdir .. "index.html", f), "documents differ")
|
||||
|
||||
print("testing post method")
|
||||
url = "http://" .. host .. "/luasocket-cgi-bin/cat"
|
||||
rf = strrep("!@#$!@#%", 80000)
|
||||
f, m, s, e = http_post(url, rf)
|
||||
assert(f and m and s and not e)
|
||||
assert(rf == f, "files differ")
|
||||
|
||||
print("testing automatic auth failure")
|
||||
url = "http://really:wrong@" .. host .. "/luasocket-test/auth/index.html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e and status(s) == 401)
|
||||
|
||||
write("testing host not found: ")
|
||||
url = "http://wronghost/luasocket-test/index.html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(not f and not m and not s and e)
|
||||
print(e)
|
||||
|
||||
write("testing auth failure: ")
|
||||
url = "http://" .. host .. "/luasocket-test/auth/index.html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e and status(s) == 401)
|
||||
print(s)
|
||||
|
||||
write("testing document not found: ")
|
||||
url = "http://" .. host .. "/luasocket-test/wrongdocument.html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e and status(s) == 404)
|
||||
print(s)
|
||||
|
||||
print("testing manual auth")
|
||||
url = "http://" .. host .. "/luasocket-test/auth/index.html"
|
||||
h = {authorization = "Basic " .. base64("luasocket:password")}
|
||||
f, m, s, e = http_get(url, h)
|
||||
assert(f and m and s and not e, join(s, e))
|
||||
assert(compare(pdir .. "auth/index.html", f), "documents differ")
|
||||
|
||||
print("testing automatic auth")
|
||||
url = "http://luasocket:password@" .. host .. "/luasocket-test/auth/index.html"
|
||||
f, m, s, e = http_get(url)
|
||||
assert(f and m and s and not e, join(s, e))
|
||||
assert(compare(pdir .. "auth/index.html", f), "documents differ")
|
||||
|
||||
print("passed all tests")
|
16
test/tftptest.lua
Normal file
16
test/tftptest.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
-- load tftpclng.lua
|
||||
assert(dofile("../examples/tftpclnt.lua"))
|
||||
assert(dofile("auxiliar.lua"))
|
||||
|
||||
-- needs tftp server running on localhost, with root pointing to
|
||||
-- /home/i/diego/public/html/luasocket/test
|
||||
|
||||
host = host or "localhost"
|
||||
print("downloading")
|
||||
err = tftp_get(host, 69, "test/index.html")
|
||||
assert(not err, err)
|
||||
original = readfile("/home/i/diego/public/html/luasocket/test/index.html")
|
||||
retrieved = readfile("index.html")
|
||||
remove("index.html")
|
||||
assert(original == retrieved, "files differ!")
|
||||
print("passed")
|
Loading…
Add table
Add a link
Reference in a new issue