"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 4cbd4e04ad - Show all commits

Fix test setup: call resetNgx() before accessing ngx global

All test setup methods were trying to access ngx.shared before the ngx
global was initialized, causing 'attempt to index global ngx (a nil value)'
errors.

Fixed by calling resetNgx() at the start of each setup() method to ensure
the ngx global exists before setting up ngx.shared and other mock properties.
Claude 2025-11-22 14:44:06 +00:00 committed by Luna

View file

@ -27,6 +27,9 @@ local function createMockSharedDict()
end
function TestDDoSProtectionChallenge:setup()
-- First reset ngx to get the base ngx object
resetNgx()
-- Create mock shared dictionaries
ngx.shared = {
aproxy_bans = createMockSharedDict(),
@ -206,6 +209,9 @@ end
TestDDoSProtectionChallengePaths = {}
function TestDDoSProtectionChallengePaths:setup()
-- First reset ngx to get the base ngx object
resetNgx()
-- Create mock shared dictionaries
ngx.shared = {
aproxy_bans = createMockSharedDict(),
@ -352,6 +358,9 @@ end
TestDDoSProtectionChallengeQuestion = {}
function TestDDoSProtectionChallengeQuestion:setup()
-- First reset ngx to get the base ngx object
resetNgx()
ngx.shared = {
aproxy_bans = createMockSharedDict(),
aproxy_tokens = createMockSharedDict()
@ -464,6 +473,9 @@ end
TestDDoSProtectionChallengePow = {}
function TestDDoSProtectionChallengePow:setup()
-- First reset ngx to get the base ngx object
resetNgx()
ngx.shared = {
aproxy_bans = createMockSharedDict(),
aproxy_tokens = createMockSharedDict()