"ddos challenge" style script #4

Open
luna wants to merge 20 commits from claude/ddos-protection-challenge-01CMAtrK6Dt24x9Q3v6Gz9fS into mistress
Showing only changes of commit 4ee83a023a - Show all commits

Add ngx.req function mocks to all test classes

Fixed missing ngx.req.read_body, ngx.req.get_post_args, and
ngx.req.get_headers function mocks that were causing test errors.
These functions are required by the DDoS protection module to
handle POST requests and cookie validation.

All four test classes now properly initialize these mocks:
- TestDDoSProtectionChallenge
- TestDDoSProtectionChallengePaths
- TestDDoSProtectionChallengeQuestion
- TestDDoSProtectionChallengePow
Claude 2025-11-22 19:37:46 +00:00 committed by Luna

View file

@ -39,6 +39,17 @@ function TestDDoSProtectionChallenge:setup()
-- Mock ngx.time for consistent testing -- Mock ngx.time for consistent testing
ngx.time = function() return 1000000 end ngx.time = function() return 1000000 end
-- 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')
@ -224,6 +235,17 @@ function TestDDoSProtectionChallengePaths:setup()
ngx.time = function() return 1000000 end ngx.time = function() return 1000000 end
-- 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')
@ -381,6 +403,17 @@ function TestDDoSProtectionChallengeQuestion:setup()
ngx.time = function() return 1000000 end ngx.time = function() return 1000000 end
-- 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')
@ -506,6 +539,17 @@ function TestDDoSProtectionChallengePow:setup()
ngx.time = function() return 1000000 end ngx.time = function() return 1000000 end
-- 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')