aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@impa.br>2015-02-18 20:51:37 -0200
committerDiego Nehab <diego@impa.br>2015-02-18 20:51:37 -0200
commitddf429282460323e24652e6beec8e750f8e4a958 (patch)
tree071ee7879bbd4c917c92e5383c759e98a90cf78e /test
parent5edf093643cceb329392aec9606ab3988579b821 (diff)
downloadluasocket-ddf429282460323e24652e6beec8e750f8e4a958.tar.gz
luasocket-ddf429282460323e24652e6beec8e750f8e4a958.tar.bz2
luasocket-ddf429282460323e24652e6beec8e750f8e4a958.zip
Out of the box support for Lua 5.3.
Diffstat (limited to 'test')
-rw-r--r--test/auth/.htaccess4
-rw-r--r--test/auth/.htpasswd2
-rw-r--r--test/httptest.lua30
3 files changed, 20 insertions, 16 deletions
diff --git a/test/auth/.htaccess b/test/auth/.htaccess
new file mode 100644
index 0000000..bb2794a
--- /dev/null
+++ b/test/auth/.htaccess
@@ -0,0 +1,4 @@
1AuthName "test-auth"
2 AuthType Basic
3 AuthUserFile /Users/diego/impa/luasocket/test/auth/.htpasswd
4 Require valid-user
diff --git a/test/auth/.htpasswd b/test/auth/.htpasswd
index fd9002b..cfb2603 100644
--- a/test/auth/.htpasswd
+++ b/test/auth/.htpasswd
@@ -1 +1 @@
luasocket:l8n2npozPB.sQ luasocket:$apr1$47u2O.Me$.m/5BWAtt7GVoxsouIPBR1
diff --git a/test/httptest.lua b/test/httptest.lua
index d5fbb37..63ff921 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -1,4 +1,4 @@
1-- needs Alias from /home/c/diego/tec/luasocket/test to 1-- needs Alias from /home/c/diego/tec/luasocket/test to
2-- "/luasocket-test" and "/luasocket-test/" 2-- "/luasocket-test" and "/luasocket-test/"
3-- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi 3-- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi
4-- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" 4-- to "/luasocket-test-cgi" and "/luasocket-test-cgi/"
@@ -36,22 +36,22 @@ index = readfile(index_file)
36local check_result = function(response, expect, ignore) 36local check_result = function(response, expect, ignore)
37 for i,v in pairs(response) do 37 for i,v in pairs(response) do
38 if not ignore[i] then 38 if not ignore[i] then
39 if v ~= expect[i] then 39 if v ~= expect[i] then
40 local f = io.open("err", "w") 40 local f = io.open("err", "w")
41 f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i])) 41 f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i]))
42 f:close() 42 f:close()
43 fail(i .. " differs!") 43 fail(i .. " differs!")
44 end 44 end
45 end 45 end
46 end 46 end
47 for i,v in pairs(expect) do 47 for i,v in pairs(expect) do
48 if not ignore[i] then 48 if not ignore[i] then
49 if v ~= response[i] then 49 if v ~= response[i] then
50 local f = io.open("err", "w") 50 local f = io.open("err", "w")
51 f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v)) 51 f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v))
52 v = string.sub(type(v) == "string" and v or "", 1, 70) 52 v = string.sub(type(v) == "string" and v or "", 1, 70)
53 f:close() 53 f:close()
54 fail(i .. " differs!") 54 fail(i .. " differs!")
55 end 55 end
56 end 56 end
57 end 57 end
@@ -61,10 +61,10 @@ end
61local check_request = function(request, expect, ignore) 61local check_request = function(request, expect, ignore)
62 local t 62 local t
63 if not request.sink then request.sink, t = ltn12.sink.table() end 63 if not request.sink then request.sink, t = ltn12.sink.table() end
64 request.source = request.source or 64 request.source = request.source or
65 (request.body and ltn12.source.string(request.body)) 65 (request.body and ltn12.source.string(request.body))
66 local response = {} 66 local response = {}
67 response.code, response.headers, response.status = 67 response.code, response.headers, response.status =
68 socket.skip(1, http.request(request)) 68 socket.skip(1, http.request(request))
69 if t and #t > 0 then response.body = table.concat(t) end 69 if t and #t > 0 then response.body = table.concat(t) end
70 check_result(response, expect, ignore) 70 check_result(response, expect, ignore)
@@ -82,7 +82,7 @@ else fail(back.query) end
82------------------------------------------------------------------------ 82------------------------------------------------------------------------
83io.write("testing query string correctness: ") 83io.write("testing query string correctness: ")
84forth = "this+is+the+query+string" 84forth = "this+is+the+query+string"
85back = http.request("http://" .. host .. cgiprefix .. 85back = http.request("http://" .. host .. cgiprefix ..
86 "/query-string?" .. forth) 86 "/query-string?" .. forth)
87if similar(back, forth) then print("ok") 87if similar(back, forth) then print("ok")
88else fail("failed!") end 88else fail("failed!") end
@@ -120,10 +120,10 @@ check_request(request, expect, ignore)
120------------------------------------------------------------------------ 120------------------------------------------------------------------------
121io.write("testing invalid url: ") 121io.write("testing invalid url: ")
122local r, e = http.request{url = host .. prefix} 122local r, e = http.request{url = host .. prefix}
123assert(r == nil and e == "invalid host ''") 123assert(r == nil and e == "invalid host ''")
124r, re = http.request(host .. prefix) 124r, re = http.request(host .. prefix)
125assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. 125assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) ..
126 " vs " .. tostring(e)) 126 " vs " .. tostring(e))
127print("ok") 127print("ok")
128 128
129io.write("testing invalid empty port: ") 129io.write("testing invalid empty port: ")
@@ -212,7 +212,7 @@ os.remove(index_file .. "-back")
212io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ") 212io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ")
213 213
214local function b64length(len) 214local function b64length(len)
215 local a = math.ceil(len/3)*4 215 local a = math.ceil(len/3)*4
216 local l = math.ceil(a/76) 216 local l = math.ceil(a/76)
217 return a + l*2 217 return a + l*2
218end 218end
@@ -313,7 +313,7 @@ ignore = {
313 headers = 1 313 headers = 1
314} 314}
315check_request(request, expect, ignore) 315check_request(request, expect, ignore)
316 316
317------------------------------------------------------------------------ 317------------------------------------------------------------------------
318io.write("testing document not found: ") 318io.write("testing document not found: ")
319request = { 319request = {
@@ -429,9 +429,9 @@ print("ok")
429io.write("testing host not found: ") 429io.write("testing host not found: ")
430local c, e = socket.connect("example.invalid", 80) 430local c, e = socket.connect("example.invalid", 80)
431local r, re = http.request{url = "http://example.invalid/does/not/exist"} 431local r, re = http.request{url = "http://example.invalid/does/not/exist"}
432assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) 432assert(r == nil and e == re, tostring(r) .. " " .. tostring(re))
433r, re = http.request("http://example.invalid/does/not/exist") 433r, re = http.request("http://example.invalid/does/not/exist")
434assert(r == nil and e == re) 434assert(r == nil and e == re)
435print("ok") 435print("ok")
436 436
437------------------------------------------------------------------------ 437------------------------------------------------------------------------