aboutsummaryrefslogtreecommitdiff
path: root/test/ftptest.lua
diff options
context:
space:
mode:
authorCaleb Maclennan <caleb@alerque.com>2023-11-10 09:12:04 +0300
committerCaleb Maclennan <caleb@alerque.com>2023-11-10 09:12:04 +0300
commit5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch)
treea9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /test/ftptest.lua
parentccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff)
parent43a97b7f0053313b43906371dbdc226271e6c8ab (diff)
downloadluasocket-hjelmeland-patch-1.tar.gz
luasocket-hjelmeland-patch-1.tar.bz2
luasocket-hjelmeland-patch-1.zip
Merge branch 'master' into hjelmeland-patch-1hjelmeland-patch-1
Diffstat (limited to 'test/ftptest.lua')
-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}