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