diff options
author | Diego Nehab <diego@impa.br> | 2015-02-18 20:51:37 -0200 |
---|---|---|
committer | Diego Nehab <diego@impa.br> | 2015-02-18 20:51:37 -0200 |
commit | ddf429282460323e24652e6beec8e750f8e4a958 (patch) | |
tree | 071ee7879bbd4c917c92e5383c759e98a90cf78e /test | |
parent | 5edf093643cceb329392aec9606ab3988579b821 (diff) | |
download | luasocket-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/.htaccess | 4 | ||||
-rw-r--r-- | test/auth/.htpasswd | 2 | ||||
-rw-r--r-- | test/httptest.lua | 30 |
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 @@ | |||
1 | AuthName "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) | |||
36 | local check_result = function(response, expect, ignore) | 36 | local 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 | |||
61 | local check_request = function(request, expect, ignore) | 61 | local 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 | ------------------------------------------------------------------------ |
83 | io.write("testing query string correctness: ") | 83 | io.write("testing query string correctness: ") |
84 | forth = "this+is+the+query+string" | 84 | forth = "this+is+the+query+string" |
85 | back = http.request("http://" .. host .. cgiprefix .. | 85 | back = http.request("http://" .. host .. cgiprefix .. |
86 | "/query-string?" .. forth) | 86 | "/query-string?" .. forth) |
87 | if similar(back, forth) then print("ok") | 87 | if similar(back, forth) then print("ok") |
88 | else fail("failed!") end | 88 | else fail("failed!") end |
@@ -120,10 +120,10 @@ check_request(request, expect, ignore) | |||
120 | ------------------------------------------------------------------------ | 120 | ------------------------------------------------------------------------ |
121 | io.write("testing invalid url: ") | 121 | io.write("testing invalid url: ") |
122 | local r, e = http.request{url = host .. prefix} | 122 | local r, e = http.request{url = host .. prefix} |
123 | assert(r == nil and e == "invalid host ''") | 123 | assert(r == nil and e == "invalid host ''") |
124 | r, re = http.request(host .. prefix) | 124 | r, re = http.request(host .. prefix) |
125 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. | 125 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. |
126 | " vs " .. tostring(e)) | 126 | " vs " .. tostring(e)) |
127 | print("ok") | 127 | print("ok") |
128 | 128 | ||
129 | io.write("testing invalid empty port: ") | 129 | io.write("testing invalid empty port: ") |
@@ -212,7 +212,7 @@ os.remove(index_file .. "-back") | |||
212 | io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ") | 212 | io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ") |
213 | 213 | ||
214 | local function b64length(len) | 214 | local 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 |
218 | end | 218 | end |
@@ -313,7 +313,7 @@ ignore = { | |||
313 | headers = 1 | 313 | headers = 1 |
314 | } | 314 | } |
315 | check_request(request, expect, ignore) | 315 | check_request(request, expect, ignore) |
316 | 316 | ||
317 | ------------------------------------------------------------------------ | 317 | ------------------------------------------------------------------------ |
318 | io.write("testing document not found: ") | 318 | io.write("testing document not found: ") |
319 | request = { | 319 | request = { |
@@ -429,9 +429,9 @@ print("ok") | |||
429 | io.write("testing host not found: ") | 429 | io.write("testing host not found: ") |
430 | local c, e = socket.connect("example.invalid", 80) | 430 | local c, e = socket.connect("example.invalid", 80) |
431 | local r, re = http.request{url = "http://example.invalid/does/not/exist"} | 431 | local r, re = http.request{url = "http://example.invalid/does/not/exist"} |
432 | assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) | 432 | assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) |
433 | r, re = http.request("http://example.invalid/does/not/exist") | 433 | r, re = http.request("http://example.invalid/does/not/exist") |
434 | assert(r == nil and e == re) | 434 | assert(r == nil and e == re) |
435 | print("ok") | 435 | print("ok") |
436 | 436 | ||
437 | ------------------------------------------------------------------------ | 437 | ------------------------------------------------------------------------ |