"ddos challenge" style script #4

Open
luna wants to merge 20 commits from claude/ddos-protection-challenge-01CMAtrK6Dt24x9Q3v6Gz9fS into mistress
2 changed files with 20 additions and 61 deletions
Showing only changes of commit 9dd95c82a7 - Show all commits

View file

@ -74,7 +74,9 @@ function createNgx()
ngx.ERR = 3 ngx.ERR = 3
-- only hold data here -- only hold data here
ngx.var = {} ngx.var = {
request_method = 'GET'
}
-- request params api -- request params api
ngx.req = {} ngx.req = {}
@ -87,6 +89,19 @@ function createNgx()
ngx._uri_args = val ngx._uri_args = val
end end
ngx.req.read_body = function() end
ngx.req.get_post_args = function()
return ngx._post_args or {}
end
ngx.req.get_headers = function()
return ngx._headers or {}
end
-- response headers
ngx.header = {}
-- regex api -- regex api
ngx.re = {} ngx.re = {}
ngx.re.match = rex.match ngx.re.match = rex.match

View file

@ -1,20 +1,9 @@
TestDDoSProtectionChallenge = {} TestDDoSProtectionChallenge = {}
function TestDDoSProtectionChallenge:setup() function TestDDoSProtectionChallenge:setup()
-- Reset ngx (includes shared dicts and time function) -- Reset ngx (includes shared dicts, time, and request functions)
resetNgx() resetNgx()
-- Add missing ngx.req functions
ngx.req.read_body = function() end
ngx.req.get_post_args = function()
return ngx._post_args or {}
end
ngx.req.get_headers = function()
return ngx._headers or {}
end
ngx.header = {}
ngx.var.request_method = 'GET'
-- Setup module manually (can't use setupTest because it calls resetNgx) -- Setup module manually (can't use setupTest because it calls resetNgx)
local ctx = require('ctx') local ctx = require('ctx')
local config = require('config') local config = require('config')
@ -170,9 +159,6 @@ function TestDDoSProtectionChallenge:testExpiredTokenShowsChallenge()
end end
function TestDDoSProtectionChallenge:teardown() function TestDDoSProtectionChallenge:teardown()
ngx.shared = nil
ngx.header = nil
ngx._post_args = nil
teardownNgx() teardownNgx()
end end
@ -180,20 +166,9 @@ end
TestDDoSProtectionChallengePaths = {} TestDDoSProtectionChallengePaths = {}
function TestDDoSProtectionChallengePaths:setup() function TestDDoSProtectionChallengePaths:setup()
-- Reset ngx (includes shared dicts and time function) -- Reset ngx (includes shared dicts, time, and request functions)
resetNgx() resetNgx()
-- Add missing ngx.req functions
ngx.req.read_body = function() end
ngx.req.get_post_args = function()
return ngx._post_args or {}
end
ngx.req.get_headers = function()
return ngx._headers or {}
end
ngx.header = {}
ngx.var.request_method = 'GET'
-- Setup module manually -- Setup module manually
local ctx = require('ctx') local ctx = require('ctx')
local config = require('config') local config = require('config')
@ -329,9 +304,6 @@ function TestDDoSProtectionChallengePaths:testBannedIPBlockedOnUnprotectedPath()
end end
function TestDDoSProtectionChallengePaths:teardown() function TestDDoSProtectionChallengePaths:teardown()
ngx.shared = nil
ngx.header = nil
ngx._post_args = nil
teardownNgx() teardownNgx()
end end
@ -339,20 +311,9 @@ end
TestDDoSProtectionChallengeQuestion = {} TestDDoSProtectionChallengeQuestion = {}
function TestDDoSProtectionChallengeQuestion:setup() function TestDDoSProtectionChallengeQuestion:setup()
-- Reset ngx (includes shared dicts and time function) -- Reset ngx (includes shared dicts, time, and request functions)
resetNgx() resetNgx()
-- Add missing ngx.req functions
ngx.req.read_body = function() end
ngx.req.get_post_args = function()
return ngx._post_args or {}
end
ngx.req.get_headers = function()
return ngx._headers or {}
end
ngx.header = {}
ngx.var.request_method = 'GET'
-- Setup module manually -- Setup module manually
local ctx = require('ctx') local ctx = require('ctx')
local config = require('config') local config = require('config')
@ -436,9 +397,6 @@ function TestDDoSProtectionChallengeQuestion:testWrongAnswerFailsChallenge()
end end
function TestDDoSProtectionChallengeQuestion:teardown() function TestDDoSProtectionChallengeQuestion:teardown()
ngx.shared = nil
ngx.header = nil
ngx._post_args = nil
teardownNgx() teardownNgx()
end end
@ -466,20 +424,9 @@ end
TestDDoSProtectionChallengePow = {} TestDDoSProtectionChallengePow = {}
function TestDDoSProtectionChallengePow:setup() function TestDDoSProtectionChallengePow:setup()
-- Reset ngx (includes shared dicts and time function) -- Reset ngx (includes shared dicts, time, and request functions)
resetNgx() resetNgx()
-- Add missing ngx.req functions
ngx.req.read_body = function() end
ngx.req.get_post_args = function()
return ngx._post_args or {}
end
ngx.req.get_headers = function()
return ngx._headers or {}
end
ngx.header = {}
ngx.var.request_method = 'GET'
-- Setup module manually -- Setup module manually
local ctx = require('ctx') local ctx = require('ctx')
local config = require('config') local config = require('config')
@ -570,8 +517,5 @@ function TestDDoSProtectionChallengePow:testInvalidPowFailsChallenge()
end end
function TestDDoSProtectionChallengePow:teardown() function TestDDoSProtectionChallengePow:teardown()
ngx.shared = nil
ngx.header = nil
ngx._post_args = nil
teardownNgx() teardownNgx()
end end