aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2002-07-08 21:54:28 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2002-07-08 21:54:28 +0000
commitdaff3db32ed52aa18dbe1e8c613535fbe0c622c7 (patch)
tree2e33926020353496960d81d7999486a5a473086e
parent65dd6185533031421fef4a9fb5f1c919124c86a6 (diff)
downloadluasocket-daff3db32ed52aa18dbe1e8c613535fbe0c622c7.tar.gz
luasocket-daff3db32ed52aa18dbe1e8c613535fbe0c622c7.tar.bz2
luasocket-daff3db32ed52aa18dbe1e8c613535fbe0c622c7.zip
Using noglobals.lua
Não carrega mais os modulos. Ajeitados alguns nomes.
-rw-r--r--test/httptest.lua71
1 files changed, 30 insertions, 41 deletions
diff --git a/test/httptest.lua b/test/httptest.lua
index 86cb8af..85c8bd8 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -1,21 +1,14 @@
1-- needs Alias from /home/i/diego/public/html/luasocket/test to 1-- needs Alias from /home/c/diego/tec/luasocket/test to
2-- /luasocket-test 2-- /luasocket-test
3-- needs ScriptAlias from /home/i/diego/public/html/luasocket/test/cgi 3-- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi
4-- to /luasocket-test/cgi 4-- to /luasocket-test-cgi
5-- needs AllowOverride AuthConfig on /home/c/diego/tec/luasocket/test/auth
5 6
6function mysetglobal (varname, oldvalue, newvalue) 7dofile("noglobals.lua")
7 print("changing " .. varname)
8 %rawset(%globals(), varname, newvalue)
9end
10function mygetglobal (varname, newvalue)
11 print("checking " .. varname)
12 return %rawget(%globals(), varname)
13end
14settagmethod(tag(nil), "setglobal", mysetglobal)
15settagmethod(tag(nil), "getglobal", mygetglobal)
16 8
17local similar = function(s1, s2) 9local similar = function(s1, s2)
18 return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) 10 return strlower(gsub(s1 or "", "%s", "")) ==
11 strlower(gsub(s2 or "", "%s", ""))
19end 12end
20 13
21local fail = function(s) 14local fail = function(s)
@@ -52,36 +45,32 @@ local check_request = function(request, expect, ignore)
52 print("ok") 45 print("ok")
53end 46end
54 47
55local host, request, response, ignore, expect, index, prefix, cgiprefix 48dofile("../src/modules/http.lua")
56 49
57-- load http 50local request, response, ignore, expect, index, prefix, cgiprefix
58assert(dofile("../lua/http.lua"))
59assert(dofile("../lua/code.lua"))
60assert(dofile("../lua/concat.lua"))
61assert(dofile("../lua/url.lua"))
62 51
63local t = _time() 52local t = _time()
64 53
65host = host or "localhost" 54HOST = HOST or "localhost"
66prefix = prefix or "/luasocket-test" 55prefix = prefix or "/luasocket-test"
67cgiprefix = cgiprefix or "/luasocket-test-cgi" 56cgiprefix = cgiprefix or "/luasocket-test-cgi"
68index = readfile("index.html") 57index = readfile("index.html")
69 58
70write("testing request uri correctness: ") 59write("testing request uri correctness: ")
71local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" 60local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string"
72local back = HTTP.get("http://" .. host .. forth) 61local back = HTTP.get("http://" .. HOST .. forth)
73if similar(back, forth) then print("ok") 62if similar(back, forth) then print("ok")
74else fail("failed!") end 63else fail("failed!") end
75 64
76write("testing query string correctness: ") 65write("testing query string correctness: ")
77forth = "this+is+the+query+string" 66forth = "this+is+the+query+string"
78back = HTTP.get("http://" .. host .. cgiprefix .. "/query-string?" .. forth) 67back = HTTP.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth)
79if similar(back, forth) then print("ok") 68if similar(back, forth) then print("ok")
80else fail("failed!") end 69else fail("failed!") end
81 70
82write("testing document retrieval: ") 71write("testing document retrieval: ")
83request = { 72request = {
84 url = "http://" .. host .. prefix .. "/index.html" 73 url = "http://" .. HOST .. prefix .. "/index.html"
85} 74}
86expect = { 75expect = {
87 body = index, 76 body = index,
@@ -95,7 +84,7 @@ check_request(request, expect, ignore)
95 84
96write("testing HTTP redirection: ") 85write("testing HTTP redirection: ")
97request = { 86request = {
98 url = "http://" .. host .. prefix 87 url = "http://" .. HOST .. prefix
99} 88}
100expect = { 89expect = {
101 body = index, 90 body = index,
@@ -110,7 +99,7 @@ check_request(request, expect, ignore)
110 99
111write("testing automatic auth failure: ") 100write("testing automatic auth failure: ")
112request = { 101request = {
113 url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html" 102 url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html"
114} 103}
115expect = { 104expect = {
116 code = 401 105 code = 401
@@ -124,7 +113,7 @@ check_request(request, expect, ignore)
124 113
125write("testing HTTP redirection failure: ") 114write("testing HTTP redirection failure: ")
126request = { 115request = {
127 url = "http://" .. host .. prefix, 116 url = "http://" .. HOST .. prefix,
128 stay = 1 117 stay = 1
129} 118}
130expect = { 119expect = {
@@ -150,7 +139,7 @@ check_request(request, expect, ignore)
150 139
151write("testing invalid url: ") 140write("testing invalid url: ")
152request = { 141request = {
153 url = host .. prefix 142 url = HOST .. prefix
154} 143}
155local c, e = connect("", 80) 144local c, e = connect("", 80)
156expect = { 145expect = {
@@ -161,7 +150,7 @@ check_request(request, expect, ignore)
161 150
162write("testing document not found: ") 151write("testing document not found: ")
163request = { 152request = {
164 url = "http://" .. host .. "/wrongdocument.html" 153 url = "http://" .. HOST .. "/wrongdocument.html"
165} 154}
166expect = { 155expect = {
167 code = 404 156 code = 404
@@ -175,7 +164,7 @@ check_request(request, expect, ignore)
175 164
176write("testing auth failure: ") 165write("testing auth failure: ")
177request = { 166request = {
178 url = "http://" .. host .. prefix .. "/auth/index.html" 167 url = "http://" .. HOST .. prefix .. "/auth/index.html"
179} 168}
180expect = { 169expect = {
181 code = 401 170 code = 401
@@ -189,7 +178,7 @@ check_request(request, expect, ignore)
189 178
190write("testing manual basic auth: ") 179write("testing manual basic auth: ")
191request = { 180request = {
192 url = "http://" .. host .. prefix .. "/auth/index.html", 181 url = "http://" .. HOST .. prefix .. "/auth/index.html",
193 headers = { 182 headers = {
194 authorization = "Basic " .. Code.base64("luasocket:password") 183 authorization = "Basic " .. Code.base64("luasocket:password")
195 } 184 }
@@ -206,7 +195,7 @@ check_request(request, expect, ignore)
206 195
207write("testing automatic basic auth: ") 196write("testing automatic basic auth: ")
208request = { 197request = {
209 url = "http://luasocket:password@" .. host .. prefix .. "/auth/index.html" 198 url = "http://luasocket:password@" .. HOST .. prefix .. "/auth/index.html"
210} 199}
211expect = { 200expect = {
212 code = 200, 201 code = 200,
@@ -220,7 +209,7 @@ check_request(request, expect, ignore)
220 209
221write("testing auth info overriding: ") 210write("testing auth info overriding: ")
222request = { 211request = {
223 url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", 212 url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html",
224 user = "luasocket", 213 user = "luasocket",
225 password = "password" 214 password = "password"
226} 215}
@@ -236,7 +225,7 @@ check_request(request, expect, ignore)
236 225
237write("testing cgi output retrieval (probably chunked...): ") 226write("testing cgi output retrieval (probably chunked...): ")
238request = { 227request = {
239 url = "http://" .. host .. cgiprefix .. "/cat-index-html" 228 url = "http://" .. HOST .. cgiprefix .. "/cat-index-html"
240} 229}
241expect = { 230expect = {
242 body = index, 231 body = index,
@@ -250,7 +239,7 @@ check_request(request, expect, ignore)
250 239
251write("testing redirect loop: ") 240write("testing redirect loop: ")
252request = { 241request = {
253 url = "http://" .. host .. cgiprefix .. "/redirect-loop" 242 url = "http://" .. HOST .. cgiprefix .. "/redirect-loop"
254} 243}
255expect = { 244expect = {
256 code = 302 245 code = 302
@@ -264,7 +253,7 @@ check_request(request, expect, ignore)
264 253
265write("testing post method: ") 254write("testing post method: ")
266request = { 255request = {
267 url = "http://" .. host .. cgiprefix .. "/cat", 256 url = "http://" .. HOST .. cgiprefix .. "/cat",
268 method = "POST", 257 method = "POST",
269 body = index 258 body = index
270} 259}
@@ -280,7 +269,7 @@ check_request(request, expect, ignore)
280 269
281write("testing wrong scheme: ") 270write("testing wrong scheme: ")
282request = { 271request = {
283 url = "wrong://" .. host .. cgiprefix .. "/cat", 272 url = "wrong://" .. HOST .. cgiprefix .. "/cat",
284 method = "GET" 273 method = "GET"
285} 274}
286expect = { 275expect = {
@@ -292,24 +281,24 @@ check_request(request, expect, ignore)
292 281
293local body 282local body
294write("testing simple get function: ") 283write("testing simple get function: ")
295body = HTTP.get("http://" .. host .. prefix .. "/index.html") 284body = HTTP.get("http://" .. HOST .. prefix .. "/index.html")
296check(body == index) 285check(body == index)
297 286
298write("testing simple get function with table args: ") 287write("testing simple get function with table args: ")
299body = HTTP.get { 288body = HTTP.get {
300 url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", 289 url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html",
301 user = "luasocket", 290 user = "luasocket",
302 password = "password" 291 password = "password"
303} 292}
304check(body == index) 293check(body == index)
305 294
306write("testing simple post function: ") 295write("testing simple post function: ")
307body = HTTP.post("http://" .. host .. cgiprefix .. "/cat", index) 296body = HTTP.post("http://" .. HOST .. cgiprefix .. "/cat", index)
308check(body == index) 297check(body == index)
309 298
310write("testing simple post function with table args: ") 299write("testing simple post function with table args: ")
311body = HTTP.post { 300body = HTTP.post {
312 url = "http://" .. host .. cgiprefix .. "/cat", 301 url = "http://" .. HOST .. cgiprefix .. "/cat",
313 body = index 302 body = index
314} 303}
315check(body == index) 304check(body == index)