aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2001-01-25 21:59:39 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2001-01-25 21:59:39 +0000
commit7096b8df82eebfe857e0043bc8a853353bd78480 (patch)
treef5cdc12138e9526896ff5f8fe9e3ffaa0c47fc0c /test
parent68f51243b38bf1e32d471e9cc9ddf12a25110e80 (diff)
downloadluasocket-7096b8df82eebfe857e0043bc8a853353bd78480.tar.gz
luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.tar.bz2
luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.zip
Initial revision
Diffstat (limited to 'test')
-rw-r--r--test/ftptest.lua33
-rw-r--r--test/httptest.lua85
-rw-r--r--test/tftptest.lua16
3 files changed, 134 insertions, 0 deletions
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 @@
1assert(dofile("../lua/ftp.lua"))
2assert(dofile("auxiliar.lua"))
3
4pdir = "/home/i/diego/public/html/luasocket/test/"
5ldir = "/home/luasocket/"
6adir = "/home/ftp/test/"
7
8-- needs an accound luasocket:password
9-- and a copy of /home/i/diego/public/html/luasocket/test in ~ftp/test
10
11print("testing authenticated upload")
12bf = readfile(pdir .. "index.html")
13e = ftp_put("ftp://luasocket:password@localhost/index.html", bf, "b")
14assert(not e, e)
15assert(compare(ldir .. "index.html", bf), "files differ")
16remove(ldir .. "index.html")
17
18print("testing authenticated download")
19f, e = ftp_get("ftp://luasocket:password@localhost/test/index.html", "b")
20assert(f, e)
21assert(compare(pdir .. "index.html", f), "files differ")
22
23print("testing anonymous download")
24f, e = ftp_get("ftp://localhost/test/index.html", "b")
25assert(f, e)
26assert(compare(adir .. "index.html", f), "files differ")
27
28print("testing directory listing")
29f, e = ftp_get("ftp://localhost/test/")
30assert(f, e)
31assert(f == "index.html\r\n", "files differ")
32
33print("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 @@
1-- load http
2assert(dofile("../lua/http.lua"))
3assert(dofile("../lua/base64.lua"))
4assert(dofile("auxiliar.lua"))
5
6-- needs Alias from /home/i/diego/public/html/luasocket/test to
7-- /luasocket-test
8-- needs ScriptAlias from /home/i/diego/public/html/luasocket/test/cgi-bin
9-- to /luasocket-cgi-bin/
10
11function join(s, e)
12 return tostring(s) .. ":" .. tostring(e)
13end
14
15function status(s)
16 local code
17 _,_, code = strfind(s, "(%d%d%d)")
18 return tonumber(code)
19end
20
21pdir = pdir or "/home/i/diego/public/html/luasocket/test/"
22host = host or "localhost"
23
24print("testing document retrieval")
25url = "http://" .. host .. "/luasocket-test/index.html"
26f, m, s, e = http_get(url)
27assert(f and m and s and not e, join(s, e))
28assert(compare(pdir .. "index.html", f), "documents differ")
29
30print("testing HTTP redirection")
31url = "http://" .. host .. "/luasocket-test"
32f, m, s, e = http_get(url)
33assert(f and m and s and not e, join(s, e))
34assert(compare(pdir .. "index.html", f), "documents differ")
35
36print("testing cgi output retrieval (probably chunked...)")
37url = "http://" .. host .. "/luasocket-cgi-bin/cat-index-html"
38f, m, s, e = http_get(url)
39assert(f and m and s and not e, join(s, e))
40assert(compare(pdir .. "index.html", f), "documents differ")
41
42print("testing post method")
43url = "http://" .. host .. "/luasocket-cgi-bin/cat"
44rf = strrep("!@#$!@#%", 80000)
45f, m, s, e = http_post(url, rf)
46assert(f and m and s and not e)
47assert(rf == f, "files differ")
48
49print("testing automatic auth failure")
50url = "http://really:wrong@" .. host .. "/luasocket-test/auth/index.html"
51f, m, s, e = http_get(url)
52assert(f and m and s and not e and status(s) == 401)
53
54write("testing host not found: ")
55url = "http://wronghost/luasocket-test/index.html"
56f, m, s, e = http_get(url)
57assert(not f and not m and not s and e)
58print(e)
59
60write("testing auth failure: ")
61url = "http://" .. host .. "/luasocket-test/auth/index.html"
62f, m, s, e = http_get(url)
63assert(f and m and s and not e and status(s) == 401)
64print(s)
65
66write("testing document not found: ")
67url = "http://" .. host .. "/luasocket-test/wrongdocument.html"
68f, m, s, e = http_get(url)
69assert(f and m and s and not e and status(s) == 404)
70print(s)
71
72print("testing manual auth")
73url = "http://" .. host .. "/luasocket-test/auth/index.html"
74h = {authorization = "Basic " .. base64("luasocket:password")}
75f, m, s, e = http_get(url, h)
76assert(f and m and s and not e, join(s, e))
77assert(compare(pdir .. "auth/index.html", f), "documents differ")
78
79print("testing automatic auth")
80url = "http://luasocket:password@" .. host .. "/luasocket-test/auth/index.html"
81f, m, s, e = http_get(url)
82assert(f and m and s and not e, join(s, e))
83assert(compare(pdir .. "auth/index.html", f), "documents differ")
84
85print("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 @@
1-- load tftpclng.lua
2assert(dofile("../examples/tftpclnt.lua"))
3assert(dofile("auxiliar.lua"))
4
5-- needs tftp server running on localhost, with root pointing to
6-- /home/i/diego/public/html/luasocket/test
7
8host = host or "localhost"
9print("downloading")
10err = tftp_get(host, 69, "test/index.html")
11assert(not err, err)
12original = readfile("/home/i/diego/public/html/luasocket/test/index.html")
13retrieved = readfile("index.html")
14remove("index.html")
15assert(original == retrieved, "files differ!")
16print("passed")