diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-16 07:06:31 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-16 07:06:31 +0000 |
| commit | 89f3ecf7820857f91c4039536d2bbe3cf12d5f95 (patch) | |
| tree | 76e6cc9ff403a8c5ee52448d7ae9311bdf499039 /test | |
| parent | 3febb302ad28fd25de51cbc686739469b92d8921 (diff) | |
| download | luasocket-89f3ecf7820857f91c4039536d2bbe3cf12d5f95.tar.gz luasocket-89f3ecf7820857f91c4039536d2bbe3cf12d5f95.tar.bz2 luasocket-89f3ecf7820857f91c4039536d2bbe3cf12d5f95.zip | |
http.lua updated. still needs proxy support.
code.lua updated. looks neat.
Diffstat (limited to 'test')
| -rw-r--r-- | test/auth/.htaccess | 2 | ||||
| -rw-r--r-- | test/httptest.lua | 89 | ||||
| -rw-r--r-- | test/testclnt.lua | 6 |
3 files changed, 56 insertions, 41 deletions
diff --git a/test/auth/.htaccess b/test/auth/.htaccess index b9f100e..31e1123 100644 --- a/test/auth/.htaccess +++ b/test/auth/.htaccess | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | AuthName "Test Realm" | 1 | AuthName "Test Realm" |
| 2 | AuthType Basic | 2 | AuthType Basic |
| 3 | AuthUserFile /home/diego/tec/luasocket/test/auth/.htpasswd | 3 | AuthUserFile /Users/diego/tec/luasocket/test/auth/.htpasswd |
| 4 | require valid-user | 4 | require valid-user |
diff --git a/test/httptest.lua b/test/httptest.lua index 030974c..9d9fa25 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -1,8 +1,8 @@ | |||
| 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 | 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 | 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" |
| 5 | -- needs AllowOverride AuthConfig on /home/c/diego/tec/luasocket/test/auth | 5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth |
| 6 | local similar = function(s1, s2) | 6 | local similar = function(s1, s2) |
| 7 | return string.lower(string.gsub(s1 or "", "%s", "")) == | 7 | return string.lower(string.gsub(s1 or "", "%s", "")) == |
| 8 | string.lower(string.gsub(s2 or "", "%s", "")) | 8 | string.lower(string.gsub(s2 or "", "%s", "")) |
| @@ -31,12 +31,18 @@ local check_request = function(request, expect, ignore) | |||
| 31 | local response = socket.http.request(request) | 31 | local response = socket.http.request(request) |
| 32 | for i,v in response do | 32 | for i,v in response do |
| 33 | if not ignore[i] then | 33 | if not ignore[i] then |
| 34 | if v ~= expect[i] then fail(i .. " differs!") end | 34 | if v ~= expect[i] then |
| 35 | if string.len(v) < 80 then print(v) end | ||
| 36 | fail(i .. " differs!") | ||
| 37 | end | ||
| 35 | end | 38 | end |
| 36 | end | 39 | end |
| 37 | for i,v in expect do | 40 | for i,v in expect do |
| 38 | if not ignore[i] then | 41 | if not ignore[i] then |
| 39 | if v ~= response[i] then fail(i .. " differs!") end | 42 | if v ~= response[i] then |
| 43 | if string.len(v) < 80 then print(v) end | ||
| 44 | fail(i .. " differs!") | ||
| 45 | end | ||
| 40 | end | 46 | end |
| 41 | end | 47 | end |
| 42 | print("ok") | 48 | print("ok") |
| @@ -47,15 +53,18 @@ local host, request, response, ignore, expect, index, prefix, cgiprefix | |||
| 47 | local t = socket.time() | 53 | local t = socket.time() |
| 48 | 54 | ||
| 49 | host = host or "localhost" | 55 | host = host or "localhost" |
| 50 | prefix = prefix or "/luasocket" | 56 | prefix = prefix or "/luasocket-test" |
| 51 | cgiprefix = cgiprefix or "/luasocket/cgi" | 57 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
| 52 | index = readfile("test/index.html") | 58 | index = readfile("test/index.html") |
| 53 | 59 | ||
| 54 | io.write("testing request uri correctness: ") | 60 | io.write("testing request uri correctness: ") |
| 55 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 61 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
| 56 | local back = socket.http.get("http://" .. host .. forth) | 62 | local back, h, c, e = socket.http.get("http://" .. host .. forth) |
| 57 | if similar(back, forth) then print("ok") | 63 | if similar(back, forth) then print("ok") |
| 58 | else fail("failed!") end | 64 | else |
| 65 | print(h, c, e) | ||
| 66 | fail() | ||
| 67 | end | ||
| 59 | 68 | ||
| 60 | io.write("testing query string correctness: ") | 69 | io.write("testing query string correctness: ") |
| 61 | forth = "this+is+the+query+string" | 70 | forth = "this+is+the+query+string" |
| @@ -77,6 +86,38 @@ ignore = { | |||
| 77 | } | 86 | } |
| 78 | check_request(request, expect, ignore) | 87 | check_request(request, expect, ignore) |
| 79 | 88 | ||
| 89 | socket.http.get("http://" .. host .. prefix .. "/lixo.html") | ||
| 90 | |||
| 91 | io.write("testing post method: ") | ||
| 92 | -- wanted to test chunked post, but apache doesn't support it... | ||
| 93 | request = { | ||
| 94 | url = "http://" .. host .. cgiprefix .. "/cat", | ||
| 95 | method = "POST", | ||
| 96 | body = index, | ||
| 97 | -- remove content-length header to send chunked body | ||
| 98 | headers = { ["content-length"] = string.len(index) } | ||
| 99 | } | ||
| 100 | expect = { | ||
| 101 | body = index, | ||
| 102 | code = 200 | ||
| 103 | } | ||
| 104 | ignore = { | ||
| 105 | status = 1, | ||
| 106 | headers = 1 | ||
| 107 | } | ||
| 108 | check_request(request, expect, ignore) | ||
| 109 | |||
| 110 | io.write("testing simple post function: ") | ||
| 111 | body = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) | ||
| 112 | check(body == index) | ||
| 113 | |||
| 114 | io.write("testing simple post function with table args: ") | ||
| 115 | body = socket.http.post { | ||
| 116 | url = "http://" .. host .. cgiprefix .. "/cat", | ||
| 117 | body = index | ||
| 118 | } | ||
| 119 | check(body == index) | ||
| 120 | |||
| 80 | io.write("testing http redirection: ") | 121 | io.write("testing http redirection: ") |
| 81 | request = { | 122 | request = { |
| 82 | url = "http://" .. host .. prefix | 123 | url = "http://" .. host .. prefix |
| @@ -175,7 +216,8 @@ io.write("testing manual basic auth: ") | |||
| 175 | request = { | 216 | request = { |
| 176 | url = "http://" .. host .. prefix .. "/auth/index.html", | 217 | url = "http://" .. host .. prefix .. "/auth/index.html", |
| 177 | headers = { | 218 | headers = { |
| 178 | authorization = "Basic " .. socket.code.base64("luasocket:password") | 219 | authorization = "Basic " .. |
| 220 | socket.code.base64.encode("luasocket:password") | ||
| 179 | } | 221 | } |
| 180 | } | 222 | } |
| 181 | expect = { | 223 | expect = { |
| @@ -246,22 +288,6 @@ ignore = { | |||
| 246 | } | 288 | } |
| 247 | check_request(request, expect, ignore) | 289 | check_request(request, expect, ignore) |
| 248 | 290 | ||
| 249 | io.write("testing post method: ") | ||
| 250 | request = { | ||
| 251 | url = "http://" .. host .. cgiprefix .. "/cat", | ||
| 252 | method = "POST", | ||
| 253 | body = index | ||
| 254 | } | ||
| 255 | expect = { | ||
| 256 | body = index, | ||
| 257 | code = 200 | ||
| 258 | } | ||
| 259 | ignore = { | ||
| 260 | status = 1, | ||
| 261 | headers = 1 | ||
| 262 | } | ||
| 263 | check_request(request, expect, ignore) | ||
| 264 | |||
| 265 | io.write("testing wrong scheme: ") | 291 | io.write("testing wrong scheme: ") |
| 266 | request = { | 292 | request = { |
| 267 | url = "wrong://" .. host .. cgiprefix .. "/cat", | 293 | url = "wrong://" .. host .. cgiprefix .. "/cat", |
| @@ -287,17 +313,6 @@ body = socket.http.get { | |||
| 287 | } | 313 | } |
| 288 | check(body == index) | 314 | check(body == index) |
| 289 | 315 | ||
| 290 | io.write("testing simple post function: ") | ||
| 291 | body = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) | ||
| 292 | check(body == index) | ||
| 293 | |||
| 294 | io.write("testing simple post function with table args: ") | ||
| 295 | body = socket.http.post { | ||
| 296 | url = "http://" .. host .. cgiprefix .. "/cat", | ||
| 297 | body = index | ||
| 298 | } | ||
| 299 | check(body == index) | ||
| 300 | |||
| 301 | io.write("testing HEAD method: ") | 316 | io.write("testing HEAD method: ") |
| 302 | response = socket.http.request { | 317 | response = socket.http.request { |
| 303 | method = "HEAD", | 318 | method = "HEAD", |
diff --git a/test/testclnt.lua b/test/testclnt.lua index 3f217bd..2420711 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
| @@ -84,19 +84,19 @@ function reconnect() | |||
| 84 | remote [[ | 84 | remote [[ |
| 85 | if data then data:close() data = nil end | 85 | if data then data:close() data = nil end |
| 86 | data = server:accept() | 86 | data = server:accept() |
| 87 | -- data:setoption("nodelay", true) | 87 | data:setoption("tcp-nodelay", true) |
| 88 | ]] | 88 | ]] |
| 89 | data, err = socket.connect(host, port) | 89 | data, err = socket.connect(host, port) |
| 90 | if not data then fail(err) | 90 | if not data then fail(err) |
| 91 | else pass("connected!") end | 91 | else pass("connected!") end |
| 92 | -- data:setoption("nodelay", true) | 92 | data:setoption("tcp-nodelay", true) |
| 93 | end | 93 | end |
| 94 | 94 | ||
| 95 | pass("attempting control connection...") | 95 | pass("attempting control connection...") |
| 96 | control, err = socket.connect(host, port) | 96 | control, err = socket.connect(host, port) |
| 97 | if err then fail(err) | 97 | if err then fail(err) |
| 98 | else pass("connected!") end | 98 | else pass("connected!") end |
| 99 | -- control:setoption("nodelay", true) | 99 | control:setoption("tcp-nodelay", true) |
| 100 | 100 | ||
| 101 | ------------------------------------------------------------------------ | 101 | ------------------------------------------------------------------------ |
| 102 | test("method registration") | 102 | test("method registration") |
