Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Rules/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Challenge extends Rule
{
public const TYPE_CAPTCHA = 'captcha';
public const TYPE_CUSTOM = 'custom';
public const TYPE_COMPUTE = 'compute';

private string $type;

Expand All @@ -17,7 +18,7 @@ class Challenge extends Rule
public function __construct(array $conditions = [], string $type = self::TYPE_CAPTCHA)
{
parent::__construct($conditions);
if (!in_array($type, [self::TYPE_CAPTCHA, self::TYPE_CUSTOM], true)) {
if (!in_array($type, [self::TYPE_CAPTCHA, self::TYPE_CUSTOM, self::TYPE_COMPUTE], true)) {
throw new \InvalidArgumentException('Invalid challenge type: ' . $type);
}
$this->type = $type;
Expand Down
8 changes: 8 additions & 0 deletions tests/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ public function testChallengeRuleTypeDefaults(): void
{
$defaultRule = new Challenge();
$customRule = new Challenge([], Challenge::TYPE_CUSTOM);
$computeRule = new Challenge([], Challenge::TYPE_COMPUTE);

$this->assertSame('challenge', $defaultRule->getAction());
$this->assertSame(Challenge::TYPE_CAPTCHA, $defaultRule->getType());
$this->assertSame(Challenge::TYPE_CUSTOM, $customRule->getType());
$this->assertSame(Challenge::TYPE_COMPUTE, $computeRule->getType());
}

public function testChallengeRuleRejectsUnknownType(): void
{
$this->expectException(\InvalidArgumentException::class);
new Challenge([], 'not-a-real-type');
}

public function testRateLimitMetadata(): void
Expand Down
Loading