diff options
author | Diego Nehab <diego@impa.br> | 2016-03-07 01:30:30 -0300 |
---|---|---|
committer | Diego Nehab <diego@impa.br> | 2016-03-07 01:30:30 -0300 |
commit | 916b548240b1513410b13f964d80f329aec9c13a (patch) | |
tree | dee1cfd05ca7ad72a3db2673fbc7ce005098bb2a /test | |
parent | 5b4b9158799293eeaf8439d40a7845b5b0a5e125 (diff) | |
download | luasocket-916b548240b1513410b13f964d80f329aec9c13a.tar.gz luasocket-916b548240b1513410b13f964d80f329aec9c13a.tar.bz2 luasocket-916b548240b1513410b13f964d80f329aec9c13a.zip |
Family agostic FTP and expose HTTP/FTP url parsing
Diffstat (limited to 'test')
-rw-r--r-- | test/ftptest.lua | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/test/ftptest.lua b/test/ftptest.lua index fb13326..3ea0d39 100644 --- a/test/ftptest.lua +++ b/test/ftptest.lua | |||
@@ -3,19 +3,31 @@ local ftp = require("socket.ftp") | |||
3 | local url = require("socket.url") | 3 | local url = require("socket.url") |
4 | local ltn12 = require("ltn12") | 4 | local ltn12 = require("ltn12") |
5 | 5 | ||
6 | -- use dscl to create user "luasocket" with password "password" | ||
7 | -- with home in /Users/diego/luasocket/test/ftp | ||
8 | -- with group com.apple.access_ftp | ||
9 | -- with shell set to /sbin/nologin | ||
10 | -- set /etc/ftpchroot to chroot luasocket | ||
11 | -- must set group com.apple.access_ftp on user _ftp (for anonymous access) | ||
12 | -- copy index.html to /var/empty/pub (home of user ftp) | ||
13 | -- start ftp server with | ||
14 | -- sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist | ||
15 | -- copy index.html to /Users/diego/luasocket/test/ftp | ||
16 | -- stop with | ||
17 | -- sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist | ||
18 | |||
6 | -- override protection to make sure we see all errors | 19 | -- override protection to make sure we see all errors |
7 | --socket.protect = function(s) return s end | 20 | --socket.protect = function(s) return s end |
8 | 21 | ||
9 | dofile("testsupport.lua") | 22 | dofile("testsupport.lua") |
10 | 23 | ||
11 | local host, port, index_file, index, back, err, ret | 24 | local host = host or "localhost" |
25 | local port, index_file, index, back, err, ret | ||
12 | 26 | ||
13 | local t = socket.gettime() | 27 | local t = socket.gettime() |
14 | 28 | ||
15 | host = host or "localhost" | ||
16 | index_file = "index.html" | 29 | index_file = "index.html" |
17 | 30 | ||
18 | |||
19 | -- a function that returns a directory listing | 31 | -- a function that returns a directory listing |
20 | local function nlst(u) | 32 | local function nlst(u) |
21 | local t = {} | 33 | local t = {} |
@@ -55,27 +67,27 @@ assert(not err and back == index, err) | |||
55 | print("ok") | 67 | print("ok") |
56 | 68 | ||
57 | io.write("erasing before upload: ") | 69 | io.write("erasing before upload: ") |
58 | ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") | 70 | ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") |
59 | if not ret then print(err) | 71 | if not ret then print(err) |
60 | else print("ok") end | 72 | else print("ok") end |
61 | 73 | ||
62 | io.write("testing upload: ") | 74 | io.write("testing upload: ") |
63 | ret, err = ftp.put("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i", index) | 75 | ret, err = ftp.put("ftp://luasocket:password@" .. host .. "/index.up.html;type=i", index) |
64 | assert(ret and not err, err) | 76 | assert(ret and not err, err) |
65 | print("ok") | 77 | print("ok") |
66 | 78 | ||
67 | io.write("downloading uploaded file: ") | 79 | io.write("downloading uploaded file: ") |
68 | back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i") | 80 | back, err = ftp.get("ftp://luasocket:password@" .. host .. "/index.up.html;type=i") |
69 | assert(ret and not err and index == back, err) | 81 | assert(ret and not err and index == back, err) |
70 | print("ok") | 82 | print("ok") |
71 | 83 | ||
72 | io.write("erasing after upload/download: ") | 84 | io.write("erasing after upload/download: ") |
73 | ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") | 85 | ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html") |
74 | assert(ret and not err, err) | 86 | assert(ret and not err, err) |
75 | print("ok") | 87 | print("ok") |
76 | 88 | ||
77 | io.write("testing weird-character translation: ") | 89 | io.write("testing weird-character translation: ") |
78 | back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/%23%3f;type=i") | 90 | back, err = ftp.get("ftp://luasocket:password@" .. host .. "/%23%3f;type=i") |
79 | assert(not err and back == index, err) | 91 | assert(not err and back == index, err) |
80 | print("ok") | 92 | print("ok") |
81 | 93 | ||
@@ -84,7 +96,7 @@ local back = {} | |||
84 | ret, err = ftp.get{ | 96 | ret, err = ftp.get{ |
85 | url = "//stupid:mistake@" .. host .. "/index.html", | 97 | url = "//stupid:mistake@" .. host .. "/index.html", |
86 | user = "luasocket", | 98 | user = "luasocket", |
87 | password = "pedrovian", | 99 | password = "password", |
88 | type = "i", | 100 | type = "i", |
89 | sink = ltn12.sink.table(back) | 101 | sink = ltn12.sink.table(back) |
90 | } | 102 | } |