"ddos challenge" style script #4
2 changed files with 20 additions and 61 deletions
17
test.lua
17
test.lua
|
|
@ -74,7 +74,9 @@ function createNgx()
|
|||
ngx.ERR = 3
|
||||
|
||||
-- only hold data here
|
||||
ngx.var = {}
|
||||
ngx.var = {
|
||||
request_method = 'GET'
|
||||
}
|
||||
|
||||
-- request params api
|
||||
ngx.req = {}
|
||||
|
|
@ -87,6 +89,19 @@ function createNgx()
|
|||
ngx._uri_args = val
|
||||
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
|
||||
ngx.re = {}
|
||||
ngx.re.match = rex.match
|
||||
|
|
|
|||
|
|
@ -1,20 +1,9 @@
|
|||
TestDDoSProtectionChallenge = {}
|
||||
|
||||
function TestDDoSProtectionChallenge:setup()
|
||||
-- Reset ngx (includes shared dicts and time function)
|
||||
-- Reset ngx (includes shared dicts, time, and request functions)
|
||||
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)
|
||||
local ctx = require('ctx')
|
||||
local config = require('config')
|
||||
|
|
@ -170,9 +159,6 @@ function TestDDoSProtectionChallenge:testExpiredTokenShowsChallenge()
|
|||
end
|
||||
|
||||
function TestDDoSProtectionChallenge:teardown()
|
||||
ngx.shared = nil
|
||||
ngx.header = nil
|
||||
ngx._post_args = nil
|
||||
teardownNgx()
|
||||
end
|
||||
|
||||
|
|
@ -180,20 +166,9 @@ end
|
|||
TestDDoSProtectionChallengePaths = {}
|
||||
|
||||
function TestDDoSProtectionChallengePaths:setup()
|
||||
-- Reset ngx (includes shared dicts and time function)
|
||||
-- Reset ngx (includes shared dicts, time, and request functions)
|
||||
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
|
||||
local ctx = require('ctx')
|
||||
local config = require('config')
|
||||
|
|
@ -329,9 +304,6 @@ function TestDDoSProtectionChallengePaths:testBannedIPBlockedOnUnprotectedPath()
|
|||
end
|
||||
|
||||
function TestDDoSProtectionChallengePaths:teardown()
|
||||
ngx.shared = nil
|
||||
ngx.header = nil
|
||||
ngx._post_args = nil
|
||||
teardownNgx()
|
||||
end
|
||||
|
||||
|
|
@ -339,20 +311,9 @@ end
|
|||
TestDDoSProtectionChallengeQuestion = {}
|
||||
|
||||
function TestDDoSProtectionChallengeQuestion:setup()
|
||||
-- Reset ngx (includes shared dicts and time function)
|
||||
-- Reset ngx (includes shared dicts, time, and request functions)
|
||||
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
|
||||
local ctx = require('ctx')
|
||||
local config = require('config')
|
||||
|
|
@ -436,9 +397,6 @@ function TestDDoSProtectionChallengeQuestion:testWrongAnswerFailsChallenge()
|
|||
end
|
||||
|
||||
function TestDDoSProtectionChallengeQuestion:teardown()
|
||||
ngx.shared = nil
|
||||
ngx.header = nil
|
||||
ngx._post_args = nil
|
||||
teardownNgx()
|
||||
end
|
||||
|
||||
|
|
@ -466,20 +424,9 @@ end
|
|||
TestDDoSProtectionChallengePow = {}
|
||||
|
||||
function TestDDoSProtectionChallengePow:setup()
|
||||
-- Reset ngx (includes shared dicts and time function)
|
||||
-- Reset ngx (includes shared dicts, time, and request functions)
|
||||
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
|
||||
local ctx = require('ctx')
|
||||
local config = require('config')
|
||||
|
|
@ -570,8 +517,5 @@ function TestDDoSProtectionChallengePow:testInvalidPowFailsChallenge()
|
|||
end
|
||||
|
||||
function TestDDoSProtectionChallengePow:teardown()
|
||||
ngx.shared = nil
|
||||
ngx.header = nil
|
||||
ngx._post_args = nil
|
||||
teardownNgx()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue