feat: add captcha-backed forum security hardening
This commit is contained in:
52
tests/Unit/BotRiskScorerTest.php
Normal file
52
tests/Unit/BotRiskScorerTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use cPad\Plugins\Forum\Services\Security\BotRiskScorer;
|
||||
|
||||
uses(Tests\TestCase::class);
|
||||
|
||||
it('maps bot risk thresholds to the expected decisions', function () {
|
||||
config()->set('forum_bot_protection.thresholds', [
|
||||
'allow' => 20,
|
||||
'log' => 20,
|
||||
'captcha' => 40,
|
||||
'moderate' => 60,
|
||||
'block' => 80,
|
||||
]);
|
||||
|
||||
$scorer = app(BotRiskScorer::class);
|
||||
|
||||
expect($scorer->score(['behavior' => 10]))->toMatchArray([
|
||||
'risk_score' => 10,
|
||||
'decision' => 'allow',
|
||||
'requires_review' => false,
|
||||
'blocked' => false,
|
||||
]);
|
||||
|
||||
expect($scorer->score(['behavior' => 20]))->toMatchArray([
|
||||
'risk_score' => 20,
|
||||
'decision' => 'log',
|
||||
'requires_review' => false,
|
||||
'blocked' => false,
|
||||
]);
|
||||
|
||||
expect($scorer->score(['behavior' => 40]))->toMatchArray([
|
||||
'risk_score' => 40,
|
||||
'decision' => 'captcha',
|
||||
'requires_review' => false,
|
||||
'blocked' => false,
|
||||
]);
|
||||
|
||||
expect($scorer->score(['behavior' => 60]))->toMatchArray([
|
||||
'risk_score' => 60,
|
||||
'decision' => 'moderate',
|
||||
'requires_review' => true,
|
||||
'blocked' => false,
|
||||
]);
|
||||
|
||||
expect($scorer->score(['behavior' => 80]))->toMatchArray([
|
||||
'risk_score' => 80,
|
||||
'decision' => 'block',
|
||||
'requires_review' => false,
|
||||
'blocked' => true,
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user