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