From 7096b8df82eebfe857e0043bc8a853353bd78480 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 25 Jan 2001 21:59:39 +0000 Subject: Initial revision --- test/ftptest.lua | 33 +++++++++++++++++++++ test/httptest.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/tftptest.lua | 16 +++++++++++ 3 files changed, 134 insertions(+) create mode 100644 test/ftptest.lua create mode 100644 test/httptest.lua create mode 100644 test/tftptest.lua (limited to 'test') diff --git a/test/ftptest.lua b/test/ftptest.lua new file mode 100644 index 0000000..85dc16b --- /dev/null +++ b/test/ftptest.lua @@ -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") diff --git a/test/httptest.lua b/test/httptest.lua new file mode 100644 index 0000000..b88475d --- /dev/null +++ b/test/httptest.lua @@ -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") diff --git a/test/tftptest.lua b/test/tftptest.lua new file mode 100644 index 0000000..7fb8253 --- /dev/null +++ b/test/tftptest.lua @@ -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") -- cgit v1.2.3-55-g6feb