aboutsummaryrefslogtreecommitdiff
path: root/test/ftptest.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2001-09-25 21:34:43 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2001-09-25 21:34:43 +0000
commitd36460a249261680a4a920f05767b7f7cf2868ba (patch)
tree363b45dc2a34ffc33496df8268af350f389db026 /test/ftptest.lua
parentb319e6a1e86a54c23b4848c5be7c0670f349a63f (diff)
downloadluasocket-d36460a249261680a4a920f05767b7f7cf2868ba.tar.gz
luasocket-d36460a249261680a4a920f05767b7f7cf2868ba.tar.bz2
luasocket-d36460a249261680a4a920f05767b7f7cf2868ba.zip
updated for luasocket 1.4
Diffstat (limited to 'test/ftptest.lua')
-rw-r--r--test/ftptest.lua149
1 files changed, 118 insertions, 31 deletions
diff --git a/test/ftptest.lua b/test/ftptest.lua
index 41f314d..7b0d3ab 100644
--- a/test/ftptest.lua
+++ b/test/ftptest.lua
@@ -1,34 +1,121 @@
1function mysetglobal (varname, oldvalue, newvalue)
2 print("changing " .. varname)
3 %rawset(%globals(), varname, newvalue)
4end
5function mygetglobal (varname, newvalue)
6 print("checking " .. varname)
7 return %rawget(%globals(), varname)
8end
9settagmethod(tag(nil), "setglobal", mysetglobal)
10settagmethod(tag(nil), "getglobal", mygetglobal)
11
1assert(dofile("../lua/ftp.lua")) 12assert(dofile("../lua/ftp.lua"))
2assert(dofile("../lua/buffer.lua")) 13assert(dofile("../lua/url.lua"))
3assert(dofile("auxiliar.lua")) 14assert(dofile("../lua/concat.lua"))
4 15assert(dofile("../lua/code.lua"))
5pdir = "/home/i/diego/public/html/luasocket/test/" 16
6ldir = "/home/luasocket/" 17local similar = function(s1, s2)
7adir = "/home/ftp/test/" 18 return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", ""))
8 19end
9-- needs an accound luasocket:password 20
10-- and a copy of /home/i/diego/public/html/luasocket/test in ~ftp/test 21local capture = function(cmd)
11 22 readfrom("| " .. cmd)
12print("testing authenticated upload") 23 local s = read("*a")
13bf = readfile(pdir .. "index.html") 24 readfrom()
14e = ftp_put("ftp://luasocket:password@localhost/index.html", bf, "b") 25 return s
15assert(not e, e) 26end
16assert(compare(ldir .. "index.html", bf), "files differ") 27
17remove(ldir .. "index.html") 28local readfile = function(name)
18 29 local f = readfrom(name)
19print("testing authenticated download") 30 if not f then return nil end
20f, e = ftp_get("ftp://luasocket:password@localhost/test/index.html", "b") 31 local s = read("*a")
21assert(f, e) 32 readfrom()
22assert(compare(pdir .. "index.html", f), "files differ") 33 return s
23 34end
24print("testing anonymous download") 35
25f, e = ftp_get("ftp://localhost/test/index.html", "b") 36local check = function(v, e, o)
26assert(f, e) 37 e = e or "failed!"
27assert(compare(adir .. "index.html", f), "files differ") 38 o = o or "ok"
28 39 if v then print(o)
29print("testing directory listing") 40 else print(e) exit() end
30f, e = ftp_get("ftp://localhost/test/") 41end
31assert(f, e) 42
32assert(f == "index.html\r\n", "files differ") 43-- needs an account luasocket:password
44-- and some directories and files in ~ftp
45
46local index, err, saved, back, expected
47
48local t = _time()
49
50index = readfile("index.html")
51
52write("testing file upload: ")
53remove("/home/ftp/dir1/index.up.html")
54err = FTP.put("ftp://localhost/dir1/index.up.html;type=i", index)
55saved = readfile("/home/ftp/dir1/index.up.html")
56check(not err and saved == index, err)
57
58write("testing file download: ")
59back, err = FTP.get("ftp://localhost/dir1/index.up.html;type=i")
60check(not err and back == index, err)
61
62write("testing no directory changes: ")
63back, err = FTP.get("ftp://localhost/index.html;type=i")
64check(not err and back == index, err)
65
66write("testing multiple directory changes: ")
67back, err = FTP.get("ftp://localhost/dir1/dir2/dir3/dir4/dir5/dir6/index.html;type=i")
68check(not err and back == index, err)
69
70write("testing authenticated upload: ")
71remove("/home/luasocket/index.up.html")
72err = FTP.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
73saved = readfile("/home/luasocket/index.up.html")
74check(not err and saved == index, err)
75
76write("testing authenticated download: ")
77back, err = FTP.get("ftp://luasocket:password@localhost/index.up.html;type=i")
78check(not err and back == index, err)
79
80write("testing weird-character translation: ")
81back, err = FTP.get("ftp://luasocket:password@localhost/%2fhome/ftp/dir1/index.html;type=i")
82check(not err and back == index, err)
83
84write("testing parameter overriding: ")
85back, err = FTP.get {
86 url = "//stupid:mistake@localhost/dir1/index.html",
87 user = "luasocket",
88 password = "password",
89 type = "i"
90}
91check(not err and back == index, err)
92
93write("testing invalid url: ")
94back, err = FTP.get("localhost/dir1/index.html;type=i")
95local c, e = connect("", 21)
96check(not back and err == e, err)
97
98write("testing directory listing: ")
99expected = capture("ls -F /home/ftp/dir1 | grep -v /")
100back, err = FTP.get("ftp://localhost/dir1;type=d")
101check(similar(back, expected))
102
103write("testing home directory listing: ")
104expected = capture("ls -F /home/ftp | grep -v /")
105back, err = FTP.get("ftp://localhost/")
106check(back and similar(back, expected), nil, err)
107
108write("testing upload denial: ")
109err = FTP.put("ftp://localhost/index.up.html;type=a", index)
110check(err, err)
111
112write("testing authentication failure: ")
113err = FTP.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
114check(err, err)
115
116write("testing wrong file: ")
117back, err = FTP.get("ftp://localhost/index.wrong.html;type=a")
118check(err, err)
33 119
34print("passed all tests") 120print("passed all tests")
121print(format("done in %.2fs", _time() - t))