aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@impa.br>2016-03-07 01:30:30 -0300
committerDiego Nehab <diego@impa.br>2016-03-07 01:30:30 -0300
commit916b548240b1513410b13f964d80f329aec9c13a (patch)
treedee1cfd05ca7ad72a3db2673fbc7ce005098bb2a /test
parent5b4b9158799293eeaf8439d40a7845b5b0a5e125 (diff)
downloadluasocket-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.lua34
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")
3local url = require("socket.url") 3local url = require("socket.url")
4local ltn12 = require("ltn12") 4local 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
9dofile("testsupport.lua") 22dofile("testsupport.lua")
10 23
11local host, port, index_file, index, back, err, ret 24local host = host or "localhost"
25local port, index_file, index, back, err, ret
12 26
13local t = socket.gettime() 27local t = socket.gettime()
14 28
15host = host or "localhost"
16index_file = "index.html" 29index_file = "index.html"
17 30
18
19-- a function that returns a directory listing 31-- a function that returns a directory listing
20local function nlst(u) 32local function nlst(u)
21 local t = {} 33 local t = {}
@@ -55,27 +67,27 @@ assert(not err and back == index, err)
55print("ok") 67print("ok")
56 68
57io.write("erasing before upload: ") 69io.write("erasing before upload: ")
58ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") 70ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html")
59if not ret then print(err) 71if not ret then print(err)
60else print("ok") end 72else print("ok") end
61 73
62io.write("testing upload: ") 74io.write("testing upload: ")
63ret, err = ftp.put("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i", index) 75ret, err = ftp.put("ftp://luasocket:password@" .. host .. "/index.up.html;type=i", index)
64assert(ret and not err, err) 76assert(ret and not err, err)
65print("ok") 77print("ok")
66 78
67io.write("downloading uploaded file: ") 79io.write("downloading uploaded file: ")
68back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i") 80back, err = ftp.get("ftp://luasocket:password@" .. host .. "/index.up.html;type=i")
69assert(ret and not err and index == back, err) 81assert(ret and not err and index == back, err)
70print("ok") 82print("ok")
71 83
72io.write("erasing after upload/download: ") 84io.write("erasing after upload/download: ")
73ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") 85ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html")
74assert(ret and not err, err) 86assert(ret and not err, err)
75print("ok") 87print("ok")
76 88
77io.write("testing weird-character translation: ") 89io.write("testing weird-character translation: ")
78back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/%23%3f;type=i") 90back, err = ftp.get("ftp://luasocket:password@" .. host .. "/%23%3f;type=i")
79assert(not err and back == index, err) 91assert(not err and back == index, err)
80print("ok") 92print("ok")
81 93
@@ -84,7 +96,7 @@ local back = {}
84ret, err = ftp.get{ 96ret, 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}