diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-01-25 21:59:39 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-01-25 21:59:39 +0000 |
commit | 7096b8df82eebfe857e0043bc8a853353bd78480 (patch) | |
tree | f5cdc12138e9526896ff5f8fe9e3ffaa0c47fc0c /test/httptest.lua | |
parent | 68f51243b38bf1e32d471e9cc9ddf12a25110e80 (diff) | |
download | luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.tar.gz luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.tar.bz2 luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.zip |
Initial revision
Diffstat (limited to 'test/httptest.lua')
-rw-r--r-- | test/httptest.lua | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/httptest.lua b/test/httptest.lua new file mode 100644 index 0000000..b88475d --- /dev/null +++ b/test/httptest.lua | |||
@@ -0,0 +1,85 @@ | |||
1 | -- load http | ||
2 | assert(dofile("../lua/http.lua")) | ||
3 | assert(dofile("../lua/base64.lua")) | ||
4 | assert(dofile("auxiliar.lua")) | ||
5 | |||
6 | -- needs Alias from /home/i/diego/public/html/luasocket/test to | ||
7 | -- /luasocket-test | ||
8 | -- needs ScriptAlias from /home/i/diego/public/html/luasocket/test/cgi-bin | ||
9 | -- to /luasocket-cgi-bin/ | ||
10 | |||
11 | function join(s, e) | ||
12 | return tostring(s) .. ":" .. tostring(e) | ||
13 | end | ||
14 | |||
15 | function status(s) | ||
16 | local code | ||
17 | _,_, code = strfind(s, "(%d%d%d)") | ||
18 | return tonumber(code) | ||
19 | end | ||
20 | |||
21 | pdir = pdir or "/home/i/diego/public/html/luasocket/test/" | ||
22 | host = host or "localhost" | ||
23 | |||
24 | print("testing document retrieval") | ||
25 | url = "http://" .. host .. "/luasocket-test/index.html" | ||
26 | f, m, s, e = http_get(url) | ||
27 | assert(f and m and s and not e, join(s, e)) | ||
28 | assert(compare(pdir .. "index.html", f), "documents differ") | ||
29 | |||
30 | print("testing HTTP redirection") | ||
31 | url = "http://" .. host .. "/luasocket-test" | ||
32 | f, m, s, e = http_get(url) | ||
33 | assert(f and m and s and not e, join(s, e)) | ||
34 | assert(compare(pdir .. "index.html", f), "documents differ") | ||
35 | |||
36 | print("testing cgi output retrieval (probably chunked...)") | ||
37 | url = "http://" .. host .. "/luasocket-cgi-bin/cat-index-html" | ||
38 | f, m, s, e = http_get(url) | ||
39 | assert(f and m and s and not e, join(s, e)) | ||
40 | assert(compare(pdir .. "index.html", f), "documents differ") | ||
41 | |||
42 | print("testing post method") | ||
43 | url = "http://" .. host .. "/luasocket-cgi-bin/cat" | ||
44 | rf = strrep("!@#$!@#%", 80000) | ||
45 | f, m, s, e = http_post(url, rf) | ||
46 | assert(f and m and s and not e) | ||
47 | assert(rf == f, "files differ") | ||
48 | |||
49 | print("testing automatic auth failure") | ||
50 | url = "http://really:wrong@" .. host .. "/luasocket-test/auth/index.html" | ||
51 | f, m, s, e = http_get(url) | ||
52 | assert(f and m and s and not e and status(s) == 401) | ||
53 | |||
54 | write("testing host not found: ") | ||
55 | url = "http://wronghost/luasocket-test/index.html" | ||
56 | f, m, s, e = http_get(url) | ||
57 | assert(not f and not m and not s and e) | ||
58 | print(e) | ||
59 | |||
60 | write("testing auth failure: ") | ||
61 | url = "http://" .. host .. "/luasocket-test/auth/index.html" | ||
62 | f, m, s, e = http_get(url) | ||
63 | assert(f and m and s and not e and status(s) == 401) | ||
64 | print(s) | ||
65 | |||
66 | write("testing document not found: ") | ||
67 | url = "http://" .. host .. "/luasocket-test/wrongdocument.html" | ||
68 | f, m, s, e = http_get(url) | ||
69 | assert(f and m and s and not e and status(s) == 404) | ||
70 | print(s) | ||
71 | |||
72 | print("testing manual auth") | ||
73 | url = "http://" .. host .. "/luasocket-test/auth/index.html" | ||
74 | h = {authorization = "Basic " .. base64("luasocket:password")} | ||
75 | f, m, s, e = http_get(url, h) | ||
76 | assert(f and m and s and not e, join(s, e)) | ||
77 | assert(compare(pdir .. "auth/index.html", f), "documents differ") | ||
78 | |||
79 | print("testing automatic auth") | ||
80 | url = "http://luasocket:password@" .. host .. "/luasocket-test/auth/index.html" | ||
81 | f, m, s, e = http_get(url) | ||
82 | assert(f and m and s and not e, join(s, e)) | ||
83 | assert(compare(pdir .. "auth/index.html", f), "documents differ") | ||
84 | |||
85 | print("passed all tests") | ||