"ddos challenge" style script #4
1 changed files with 13 additions and 3 deletions
|
|
@ -550,7 +550,7 @@ function TestDDoSProtectionChallengePow:setup()
|
||||||
shared_dict_tokens = 'aproxy_tokens',
|
shared_dict_tokens = 'aproxy_tokens',
|
||||||
protected_paths = {},
|
protected_paths = {},
|
||||||
challenge_type = 'pow',
|
challenge_type = 'pow',
|
||||||
pow_difficulty = 4
|
pow_difficulty = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
self.mod = require('scripts.ddos_protection_challenge')
|
self.mod = require('scripts.ddos_protection_challenge')
|
||||||
|
|
@ -578,12 +578,22 @@ function TestDDoSProtectionChallengePow:testPowChallengeShown()
|
||||||
lu.assertStrContains(ngx._say, '<script>')
|
lu.assertStrContains(ngx._say, '<script>')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function generateToken()
|
||||||
|
local chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
|
local token = {}
|
||||||
|
for i = 1, 32 do
|
||||||
|
local idx = math.random(1, #chars)
|
||||||
|
token[i] = chars:sub(idx, idx)
|
||||||
|
end
|
||||||
|
return table.concat(token)
|
||||||
|
end
|
||||||
|
|
||||||
function TestDDoSProtectionChallengePow:testValidPowPassesChallenge()
|
function TestDDoSProtectionChallengePow:testValidPowPassesChallenge()
|
||||||
local test_challenge = 'test_pow_challenge'
|
local test_challenge = generateToken()
|
||||||
ngx.shared.aproxy_tokens:set('pow:' .. test_challenge, true, 300)
|
ngx.shared.aproxy_tokens:set('pow:' .. test_challenge, true, 300)
|
||||||
|
|
||||||
-- Compute a valid nonce that satisfies the PoW requirement
|
-- Compute a valid nonce that satisfies the PoW requirement
|
||||||
local valid_nonce = computeValidNonce(test_challenge, 4)
|
local valid_nonce = computeValidNonce(test_challenge, 1)
|
||||||
|
|
||||||
setupFakeRequest('/__aproxy_challenge_verify', {})
|
setupFakeRequest('/__aproxy_challenge_verify', {})
|
||||||
ngx.var.remote_addr = '192.168.4.2'
|
ngx.var.remote_addr = '192.168.4.2'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue