"ddos challenge" style script #4
1 changed files with 15 additions and 5 deletions
20
test.lua
20
test.lua
|
|
@ -36,6 +36,19 @@ local function createMockSharedDict()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Create a proxy table that dynamically creates mock dictionaries on access
|
||||||
|
local function createSharedProxy()
|
||||||
|
local dicts = {}
|
||||||
|
return setmetatable({}, {
|
||||||
|
__index = function(_, key)
|
||||||
|
if not dicts[key] then
|
||||||
|
dicts[key] = createMockSharedDict()
|
||||||
|
end
|
||||||
|
return dicts[key]
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function createNgx()
|
function createNgx()
|
||||||
local ngx = {
|
local ngx = {
|
||||||
status = nil
|
status = nil
|
||||||
|
|
@ -79,11 +92,8 @@ function createNgx()
|
||||||
ngx.re.match = rex.match
|
ngx.re.match = rex.match
|
||||||
ngx.re.search = rex.find
|
ngx.re.search = rex.find
|
||||||
|
|
||||||
-- shared memory dictionaries for testing
|
-- shared memory dictionaries for testing (dynamically created on access)
|
||||||
ngx.shared = {
|
ngx.shared = createSharedProxy()
|
||||||
aproxy_bans = createMockSharedDict(),
|
|
||||||
aproxy_tokens = createMockSharedDict()
|
|
||||||
}
|
|
||||||
|
|
||||||
-- time function for testing
|
-- time function for testing
|
||||||
ngx.time = function() return 1000000 end
|
ngx.time = function() return 1000000 end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue