Adding upstream version 2.4.63.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
parent
93c6f9029a
commit
7263481e48
3104 changed files with 900776 additions and 0 deletions
36
modules/lua/test/helpers.lua
Normal file
36
modules/lua/test/helpers.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
module("helpers", package.seeall)
|
||||
|
||||
local io = require("io")
|
||||
local http = require("socket.http")
|
||||
local string = require("string")
|
||||
|
||||
base_url = "http://localhost"
|
||||
|
||||
function get(uri)
|
||||
return http.request(base_url .. uri)
|
||||
end
|
||||
|
||||
function post(uri, body)
|
||||
local function do_it(body)
|
||||
local flat
|
||||
if (type(body) == "table") then
|
||||
i = 1
|
||||
for k, v in pairs(body) do
|
||||
if i == 1 then
|
||||
flat = k .. "=" ..v
|
||||
else
|
||||
flat = flat .. "&" .. k .. "=" .. v
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
else
|
||||
flat = body;
|
||||
end
|
||||
return http.request(base_url .. uri, flat)
|
||||
end
|
||||
if body then
|
||||
return do_it(body)
|
||||
else
|
||||
return do_it
|
||||
end
|
||||
end
|
37
modules/lua/test/htdocs/config_tests.lua
Normal file
37
modules/lua/test/htdocs/config_tests.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
-- contributor license agreements. See the NOTICE file distributed with
|
||||
-- this work for additional information regarding copyright ownership.
|
||||
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
-- (the "License"); you may not use this file except in compliance with
|
||||
-- the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing, software
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
|
||||
require 'string'
|
||||
|
||||
local count = 0
|
||||
|
||||
function handle(r)
|
||||
r:puts("success in handle " .. count)
|
||||
end
|
||||
|
||||
function handle_server_vm(r)
|
||||
r:puts("hello from server scope " .. count)
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
function handle_request_vm(r)
|
||||
r:puts("hello from request scope " .. count)
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
function handle_conn_vm(r)
|
||||
r:puts("hello from request scope " .. count)
|
||||
count = count + 1
|
||||
end
|
7
modules/lua/test/htdocs/filters.lua
Normal file
7
modules/lua/test/htdocs/filters.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
local s = require 'string'
|
||||
|
||||
function handle_simple(r)
|
||||
-- r:addoutputfilter("wombathood")
|
||||
r:puts("added wombathood")
|
||||
end
|
1
modules/lua/test/htdocs/find_me.txt
Normal file
1
modules/lua/test/htdocs/find_me.txt
Normal file
|
@ -0,0 +1 @@
|
|||
please find me
|
6
modules/lua/test/htdocs/headers.lua
Normal file
6
modules/lua/test/htdocs/headers.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
function handle(r)
|
||||
local host = r.headers_in['host']
|
||||
r:debug(host)
|
||||
r:puts(host)
|
||||
r.headers_out['wombat'] = 'lua'
|
||||
end
|
29
modules/lua/test/htdocs/hooks.lua
Normal file
29
modules/lua/test/htdocs/hooks.lua
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'string'
|
||||
require 'apache2'
|
||||
|
||||
function translate_name(r)
|
||||
if r.uri == "/translate-name" then
|
||||
r.uri = "/find_me.txt"
|
||||
return apache2.DECLINED
|
||||
end
|
||||
return apache2.DECLINED
|
||||
end
|
||||
|
||||
function translate_name2(r)
|
||||
if r.uri == "/translate-name2" then
|
||||
r.uri = "/find_me.txt"
|
||||
return apache2.DECLINED
|
||||
end
|
||||
return apache2.DECLINED
|
||||
end
|
||||
|
||||
function fixups_test(r)
|
||||
-- r:err("KABAZ")
|
||||
if r.uri == "/test_fixupstest" then
|
||||
-- r:err("KABIZ")
|
||||
r.status = 201
|
||||
return apache2.OK
|
||||
end
|
||||
-- r:err("ZIBAK")
|
||||
return apache2.DECLINED
|
||||
end
|
21
modules/lua/test/htdocs/other.lua
Normal file
21
modules/lua/test/htdocs/other.lua
Normal file
|
@ -0,0 +1,21 @@
|
|||
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
-- contributor license agreements. See the NOTICE file distributed with
|
||||
-- this work for additional information regarding copyright ownership.
|
||||
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
-- (the "License"); you may not use this file except in compliance with
|
||||
-- the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing, software
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
|
||||
module("other")
|
||||
|
||||
function doit(r)
|
||||
r:debug("doing it...")
|
||||
r:puts("Do It!\n")
|
||||
end
|
4
modules/lua/test/htdocs/simple.lua
Normal file
4
modules/lua/test/htdocs/simple.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
function handle(r)
|
||||
r.content_type = "text/plain"
|
||||
r:puts("Hi there!")
|
||||
end
|
129
modules/lua/test/htdocs/test.lua
Normal file
129
modules/lua/test/htdocs/test.lua
Normal file
|
@ -0,0 +1,129 @@
|
|||
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
-- contributor license agreements. See the NOTICE file distributed with
|
||||
-- this work for additional information regarding copyright ownership.
|
||||
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
-- (the "License"); you may not use this file except in compliance with
|
||||
-- the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing, software
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
|
||||
require 'string'
|
||||
|
||||
function print_args(r, simple, complex)
|
||||
local s = " %s: %s\n"
|
||||
r:puts(" simple:\n")
|
||||
for k, v in pairs(simple) do
|
||||
r:puts(s:format(k, v))
|
||||
end
|
||||
|
||||
s = " %s: "
|
||||
r:puts(" complex:\n")
|
||||
for k, ary in pairs(complex) do
|
||||
r:puts(s:format(k))
|
||||
for i=1, #ary do
|
||||
r:puts(ary[i])
|
||||
if i < #ary then r:puts(", ") end
|
||||
end
|
||||
r:puts("\n")
|
||||
end
|
||||
end
|
||||
|
||||
function debug_stuff(r)
|
||||
r:debug("This is a debug log message")
|
||||
-- r:info("This is an info log message")
|
||||
-- r:notice("This is an notice log message")
|
||||
-- r:warn("This is an warn log message")
|
||||
-- r:err("This is an err log message")
|
||||
-- r:alert("This is an alert log message")
|
||||
-- r:crit("This is an crit log message")
|
||||
-- r:emerg("This is an emerg log message")
|
||||
end
|
||||
|
||||
function handle(r)
|
||||
r:puts("hello Lua world\n")
|
||||
r:puts("Query args:\n")
|
||||
|
||||
print_args(r, r:parseargs());
|
||||
|
||||
debug_stuff(r)
|
||||
|
||||
r:puts("HTTP Method:\n " .. r.method .. "\n")
|
||||
|
||||
if r.method == 'POST' then
|
||||
print_args(r, r:parsebody())
|
||||
end
|
||||
|
||||
require("other")
|
||||
r:puts("loaded relative to script:\n ")
|
||||
other.doit(r)
|
||||
|
||||
r:puts("loaded from LuaPackagePath:\n")
|
||||
require("kangaroo");
|
||||
kangaroo.hop(r);
|
||||
end
|
||||
|
||||
function handle_foo(r)
|
||||
r:puts("Handler FOO!\n")
|
||||
r.status = 201
|
||||
r:debug("set status to 201")
|
||||
end
|
||||
|
||||
|
||||
function handle_attributes(r)
|
||||
local function pf(name)
|
||||
r:puts(("%s: %s\n"):format(name, tostring(r[name])))
|
||||
end
|
||||
|
||||
pf("status")
|
||||
r.status = 201
|
||||
pf("status")
|
||||
r:puts("\n")
|
||||
|
||||
pf("content_type")
|
||||
r.content_type = "text/plain?charset=ascii"
|
||||
pf("content_type")
|
||||
r:puts("\n")
|
||||
|
||||
pf("method")
|
||||
pf("protocol")
|
||||
pf("assbackwards")
|
||||
pf("the_request")
|
||||
pf("range")
|
||||
pf("content_encoding")
|
||||
pf("user")
|
||||
pf("unparsed_uri")
|
||||
pf("ap_auth_type")
|
||||
pf("uri")
|
||||
pf("filename")
|
||||
pf("canonical_filename")
|
||||
pf("path_info")
|
||||
pf("args")
|
||||
|
||||
r:puts("\n")
|
||||
end
|
||||
|
||||
function test_headers(r)
|
||||
r:puts("test getting and setting headers here\n")
|
||||
end
|
||||
|
||||
function handle_quietly(r)
|
||||
r:puts("hello!")
|
||||
end
|
||||
|
||||
function handle_regex(r)
|
||||
r:puts("matched in handle_regex")
|
||||
end
|
||||
|
||||
function handle_serverversion(r)
|
||||
r:puts(apache2.version)
|
||||
end
|
||||
|
||||
function handle_fixupstest(r)
|
||||
r:puts("status is " .. r.status)
|
||||
end
|
19
modules/lua/test/lib/kangaroo.lua
Normal file
19
modules/lua/test/lib/kangaroo.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
-- contributor license agreements. See the NOTICE file distributed with
|
||||
-- this work for additional information regarding copyright ownership.
|
||||
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
-- (the "License"); you may not use this file except in compliance with
|
||||
-- the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing, software
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
module("kangaroo")
|
||||
|
||||
function hop(r)
|
||||
r:puts(" hop hop!\n")
|
||||
end
|
52
modules/lua/test/moonunit.lua
Normal file
52
modules/lua/test/moonunit.lua
Normal file
|
@ -0,0 +1,52 @@
|
|||
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
-- contributor license agreements. See the NOTICE file distributed with
|
||||
-- this work for additional information regarding copyright ownership.
|
||||
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
-- (the "License"); you may not use this file except in compliance with
|
||||
-- the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing, software
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
|
||||
module("moonunit", package.seeall)
|
||||
|
||||
TestCase = {}
|
||||
|
||||
function TestCase:new(it)
|
||||
it = it or {}
|
||||
setmetatable(it, self)
|
||||
self.__index = self
|
||||
return it
|
||||
end
|
||||
|
||||
function TestCase:run(args)
|
||||
args = args or arg
|
||||
local function run_test(t, name)
|
||||
local status, err = pcall(t, self)
|
||||
if status then
|
||||
print(("%-39s \27[32mpass\27[39m"):format("[" .. name .. "]"))
|
||||
else
|
||||
print(("%-39s \27[31mFAIL\27[39m %s"):format("[" .. name .. "]", err))
|
||||
end
|
||||
end
|
||||
|
||||
if (args and #args > 0) then
|
||||
for _, v in ipairs(args) do
|
||||
if type(self[v]) == "function" then
|
||||
run_test(self[v], v)
|
||||
else
|
||||
print(("%-39s FAIL %s"):format("[" .. v .. "]",
|
||||
"'" .. v .. "' doesn't appear to be a test function"))
|
||||
end
|
||||
end
|
||||
else
|
||||
for k, v in pairs(self) do
|
||||
run_test(v, k)
|
||||
end
|
||||
end
|
||||
end
|
126
modules/lua/test/test.lua
Executable file
126
modules/lua/test/test.lua
Executable file
|
@ -0,0 +1,126 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
-- contributor license agreements. See the NOTICE file distributed with
|
||||
-- this work for additional information regarding copyright ownership.
|
||||
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
-- (the "License"); you may not use this file except in compliance with
|
||||
-- the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing, software
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
|
||||
local mu = require "moonunit"
|
||||
local http = require "helpers"
|
||||
|
||||
http.base_url = "http://localhost:8008"
|
||||
|
||||
local test = mu.TestCase:new{}
|
||||
|
||||
function test:document_root()
|
||||
local b, c = http.get "/document_root.lua"
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(b:find("test"), "test not found in document root")
|
||||
end
|
||||
|
||||
function test:basic_get()
|
||||
local b, c = http.get "/basic"
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(b:find("hello Lua world"), "'hello Lua world' not found in response")
|
||||
end
|
||||
|
||||
function test:quietly()
|
||||
local b, c = http.get "/test_quietly"
|
||||
assert(200 == c, "unexpected response code " .. c)
|
||||
assert(b == 'hello!', "unexpected response body [" .. b .. "]")
|
||||
end
|
||||
|
||||
function test.basic_post()
|
||||
local b, c = http.post "/basic" "hello=7&hello=1"
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(b:find("complex:%s+hello: 7, 1\n"), "didn't find complex post parsing")
|
||||
assert(b:find("simple:%s+hello: 7\n"), "didn't find simple post parsing")
|
||||
end
|
||||
|
||||
function test.basic_post_alt()
|
||||
local b, c = http.post("/test_foo", "hello=7&hello=1")
|
||||
assert(201 == c, "expected status code 200, got " .. c)
|
||||
assert(b:find("Handler FOO!"), "unexpected output!")
|
||||
end
|
||||
|
||||
function test.post_with_table()
|
||||
local b, c = http.post "/basic" { hello = "7" }
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(b:find("hello: 7"), "didn't get expected post data [" .. b .."]")
|
||||
|
||||
b, c = http.post "/basic" { hello = "7", goodbye = "8" }
|
||||
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(b:find("hello: 7"), "didn't get expected post data [" .. b .."]")
|
||||
assert(b:find("goodbye: 8"), "didn't get expected post data [" .. b .."]")
|
||||
end
|
||||
|
||||
function test:simple_filter()
|
||||
local b, c = http.get "/filter/simple"
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
end
|
||||
|
||||
function test:request_attributes()
|
||||
local r, c = http.get "/test_attributes?yes=no"
|
||||
assert(201 == c, "expected status code 201, got " .. c)
|
||||
|
||||
assert(r:find("status: 200\nstatus: 201"), "changing status code failed")
|
||||
assert(r:find("method: GET"), "method wasn't reported correctly")
|
||||
assert(r:find("protocol: HTTP/1.1"), "protocol reported incorrectly")
|
||||
assert(r:find("assbackwards: false"), "assbackwards reported incorrectly")
|
||||
assert(r:find("args: yes=no"), "args not reported correctly")
|
||||
end
|
||||
|
||||
function test:map_regex()
|
||||
local r, c = http.get "/test_regex"
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(r:find("matched in handle_regex"), "didn't find 'matched in handle_regex'")
|
||||
end
|
||||
|
||||
function test:map_regex2()
|
||||
local r, c = http.get "/test_regex?a=8"
|
||||
assert(200 == c, "expected status code 200, got " .. c)
|
||||
assert(r:find("matched in handle_regex"), "didn't find 'matched in handle_regex'")
|
||||
end
|
||||
|
||||
function test:translate_name_hook()
|
||||
local r, c = http.get "/translate-name"
|
||||
assert(200 == c, "expected 200 got " .. c)
|
||||
assert(r:find("please find me"), "didn't get expected static file :-(, instead got " .. r)
|
||||
end
|
||||
|
||||
function test:translate_name_hook2()
|
||||
local r, c = http.get "/translate-name2"
|
||||
assert(200 == c, "expected 200 got " .. c)
|
||||
assert(r:find("please find me"), "didn't get expected static file :-(, instead got " .. r)
|
||||
end
|
||||
|
||||
function test:server_version()
|
||||
local r, c = http.get "/test_serverversion"
|
||||
assert(200 == c)
|
||||
assert(r:find("Apache/2"), "version isn't Apache/2, but is " .. r)
|
||||
end
|
||||
|
||||
function test:fixups_hook()
|
||||
local r, c = http.get "/test_fixupstest"
|
||||
assert(201 == c, "incorrect status code returned, expected 201 got " .. c)
|
||||
assert(r:find("status is 201"), "handler sees incorrect status")
|
||||
end
|
||||
|
||||
function test:simple()
|
||||
local r, c = http.get "/simple.lua"
|
||||
assert(200 == c, "incorrect status code returned, expected 200 got " .. c)
|
||||
assert(r:find("Hi"), "Didn't find 'Hi'")
|
||||
end
|
||||
|
||||
test:run()
|
31
modules/lua/test/test_httpd.conf
Normal file
31
modules/lua/test/test_httpd.conf
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Customize these two values for your Apache2 install
|
||||
ServerRoot "/Users/brianm/.opt/httpd-2.2.3-worker-for-lua"
|
||||
DocumentRoot "/Users/brianm/src/wombat/test/htdocs"
|
||||
|
||||
# Customize this value to point to the top of mod_wombat's test dir
|
||||
LuaRoot /Users/brianm/src/wombat/test
|
||||
|
||||
Listen 8000
|
||||
|
||||
LoadModule lua_module modules/mod_lua.so
|
||||
|
||||
AddHandler lua-script .lua
|
||||
|
||||
#LuaConfig httpd_config.lua configure
|
||||
|
||||
LuaMapHandler /basic /Users/brianm/src/wombat/test/htdocs/test.lua
|
||||
LuaMapHandler /filter/simple /Users/brianm/src/wombat/test/htdocs/filters.lua handle_simple
|
||||
LuaMapHandler ^/(\w+)_(\w+)$ /Users/brianm/src/wombat/test/htdocs/$1.lua handle_$2
|
||||
|
||||
LuaHookTranslateName htdocs/hooks.lua translate_name
|
||||
LuaHookTranslateName htdocs/hooks.lua translate_name2
|
||||
|
||||
LuaHookFixups htdocs/hooks.lua fixups_test
|
||||
|
||||
LuaPackagePath lib/?.lua
|
||||
|
||||
# stat | forever | never
|
||||
LuaCodeCache stat
|
||||
|
||||
ErrorLog logs/error_log
|
||||
LogLevel debug
|
Loading…
Add table
Add a link
Reference in a new issue