From 7c97e8e40aaa665226fb54449773dc3134e755b2 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sat, 27 Nov 2004 07:58:04 +0000 Subject: Almost ready for beta3 --- test/dicttest.lua | 2 +- test/ftptest.lua | 155 ++++++++++++++++++++++++++++-------------------------- test/httptest.lua | 2 +- test/testclnt.lua | 5 +- test/testmesg.lua | 7 ++- test/testsrvr.lua | 2 +- test/tftptest.lua | 2 +- 7 files changed, 92 insertions(+), 83 deletions(-) (limited to 'test') 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 @@ local dict = require"socket.dict" -for i,v in dict.get("dict://localhost/d:banana") do print(v) end +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 @@ -local similar = function(s1, s2) - return - string.lower(string.gsub(s1, "%s", "")) == - string.lower(string.gsub(s2, "%s", "")) -end +local socket = require("socket") +local ftp = require("socket.ftp") +local url = require("socket.url") +local ltn12 = require("ltn12") -local readfile = function(name) - local f = io.open(name, "r") - if not f then return nil end - local s = f:read("*a") - f:close() - return s -end +-- override protection to make sure we see all errors +--socket.protect = function(s) 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 +dofile("testsupport.lua") -local check = function(v, e, o) - e = e or "failed!" - o = o or "ok" - if v then print(o) - else print(e) os.exit() end -end +local host, port, index_file, index, back, err, ret --- needs an account luasocket:password --- and some directories and files in ~ftp +local t = socket.gettime() -local index, err, saved, back, expected +host = host or "diego.student.princeton.edu" +index_file = "test/index.html" -local t = socket.time() -index = readfile("test/index.html") +-- a function that returns a directory listing +local function nlst(u) + local t = {} + local p = url.parse(u) + p.command = "nlst" + p.sink = ltn12.sink.table(t) + local r, e = ftp.get(p) + return r and table.concat(t), e +end + +-- function that removes a remote file +local function dele(u) + local p = url.parse(u) + p.command = "dele" + p.argument = string.gsub(p.path, "^/", "") + if p.argumet == "" then p.argument = nil end + p.check = 250 + return ftp.command(p) +end + +-- read index with CRLF convention +index = readfile(index_file) io.write("testing wrong scheme: ") -back, err = socket.ftp.get("wrong://banana.com/lixo") -check(not back and err == "unknown scheme 'wrong'", err) +back, err = ftp.get("wrong://banana.com/lixo") +assert(not back and err == "wrong scheme 'wrong'", err) +print("ok") 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") -ret, err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index) -saved = readfile("/var/ftp/pub/index.up.html") -check(ret and not err and saved == index, err) +back, err = ftp.get("localhost/dir1/index.html;type=i") +assert(not back and err) +print("ok") 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) - -io.write("testing no directory changes: ") -back, err = socket.ftp.get("ftp://localhost/index.html;type=i") -check(not err and back == index, err) - -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) - -io.write("testing authenticated upload: ") -os.remove("/home/luasocket/index.up.html") -ret, err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) -saved = readfile("/home/luasocket/index.up.html") -check(ret and not err and saved == index, err) - -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) +back, err = socket.ftp.get("ftp://" .. host .. "/pub/index.html;type=i") +assert(not err and back == index, err) +print("ok") + +io.write("erasing before upload: ") +ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") +if not ret then print(err) +else print("ok") end + +io.write("testing upload: ") +ret, err = ftp.put("ftp://luasocket:password@" .. host .. "/index.up.html;type=i", index) +assert(ret and not err, err) +print("ok") + +io.write("downloading uploaded file: ") +back, err = ftp.get("ftp://luasocket:password@" .. host .. "/index.up.html;type=i") +assert(ret and not err and index == back, err) +print("ok") + +io.write("erasing after upload/download: ") +ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") +assert(ret and not err, err) +print("ok") 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) +back, err = ftp.get("ftp://luasocket:password@" .. host .. "/%23%3f;type=i") +assert(not err and back == index, err) +print("ok") io.write("testing parameter overriding: ") -back, err = socket.ftp.get { - url = "//stupid:mistake@localhost/index.html", +local back = {} +ret, err = ftp.get{ + url = "//stupid:mistake@" .. host .. "/index.html", user = "luasocket", password = "password", - type = "i" + type = "i", + sink = ltn12.sink.table(back) } -check(not err and back == index, err) +assert(ret and not err and table.concat(back) == index, err) +print("ok") io.write("testing upload denial: ") -ret, err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index) -check(err, err) +ret, err = ftp.put("ftp://" .. host .. "/index.up.html;type=a", index) +assert(not ret and err, "should have failed") +print(err) io.write("testing authentication failure: ") -ret, err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) +ret, err = ftp.get("ftp://luasocket:wrong@".. host .. "/index.html;type=a") +assert(not ret and err, "should have failed") print(err) -check(not ret and err, err) io.write("testing wrong file: ") -back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a") -check(err, err) +back, err = ftp.get("ftp://".. host .. "/index.wrong.html;type=a") +assert(not back and err, "should have failed") +print(err) print("passed all tests") -print(string.format("done in %.2fs", socket.time() - t)) +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 local t = socket.gettime() host = host or "diego.student.princeton.edu" -proxy = proxy or "http://localhost:3128" +proxy = proxy or "http://dell-diego.cs.princeton.edu:3128" prefix = prefix or "/luasocket-test" cgiprefix = cgiprefix or "/luasocket-test-cgi" 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 @@ local socket = require"socket" host = host or "localhost" -port = port or "8080" +port = port or "8383" function pass(...) local s = string.format(unpack(arg)) @@ -590,7 +590,6 @@ test_mixed(200) test_mixed(17) test_mixed(1) - test("binary line") test_rawline(1) test_rawline(17) @@ -630,14 +629,12 @@ test_nonblocking(200) test_nonblocking(17) test_nonblocking(1) - test("total timeout on send") test_totaltimeoutsend(800091, 1, 3) test_totaltimeoutsend(800091, 2, 3) test_totaltimeoutsend(800091, 5, 2) test_totaltimeoutsend(800091, 3, 1) - test("total timeout on receive") test_totaltimeoutreceive(800091, 1, 3) 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 @@ -- load the smtp support and its friends -local smtp = require("smtp") +local smtp = require("socket.smtp") local mime = require("mime") local ltn12 = require("ltn12") @@ -48,6 +48,11 @@ source = smtp.message{ } } +--[[ +sink = ltn12.sink.file(io.stdout) +ltn12.pump.all(source, sink) +]] + -- finally send it r, e = smtp.send{ rcpt = {"", 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 @@ socket = require("socket"); host = host or "localhost"; -port = port or "8080"; +port = port or "8383"; server = assert(socket.bind(host, port)); ack = "\n"; 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) return a end -host = host or "localhost" +host = host or "diego.student.princeton.edu" retrieved, err = tftp.get("tftp://" .. host .."/index.html") assert(not err, err) original = readfile("test/index.html") -- cgit v1.2.3-55-g6feb