Update tests

This commit is contained in:
2026-08-04 21:00:01 +02:00
parent 9dcf13a62e
commit 71d679cc5e
18 changed files with 822 additions and 426 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Tests\Support;
use AltchaOrg\Altcha\Algorithm\Pbkdf2;
use AltchaOrg\Altcha\Altcha;
use AltchaOrg\Altcha\CreateChallengeOptions;
use AltchaOrg\Altcha\SolveChallengeOptions;
/**
* Builds a valid altcha payload for tests using the fixed ALTCHA_HMAC_KEY,
* mirroring the payload shape produced by the browser widget (base64 JSON with
* a challenge array and a solution array).
*/
final class AltchaPayload
{
public static function valid(?int $counter = null): string
{
$pbkdf2 = new Pbkdf2;
$altcha = new Altcha(
hmacSignatureSecret: config('captcha.hmac_key'),
);
$counter ??= random_int(1, 100);
$challenge = $altcha->createChallenge(new CreateChallengeOptions(
algorithm: $pbkdf2,
cost: 5000,
counter: $counter,
expiresAt: time() + 600,
));
$solution = $altcha->solveChallenge(new SolveChallengeOptions(
challenge: $challenge,
algorithm: $pbkdf2,
start: $counter,
step: 1,
timeout: 5,
));
return base64_encode(json_encode([
'challenge' => $challenge->toArray(),
'solution' => $solution->toArray(),
]));
}
}