"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
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue