Use the reCAPTCHA Enterprise API.

This commit is contained in:
tim
2026-09-26 15:27:51 +02:00
parent cc47d0ee51
commit 77800174c9
11 changed files with 265 additions and 60 deletions
+14 -1
View File
@@ -50,7 +50,8 @@ class LoginTest extends PageTestCase {
public function testTheFormHasATokenAndTheCaptcha(): void {
$body = $this->get('/publish/login')['body'];
$this->assertSame($this->session()['csrf_token'], $this->csrfToken($body));
$this->assertStringContainsString('data-sitekey="test-site-key"', $body);
$this->assertStringContainsString('data-sitekey="test-site-key" data-action="login"', $body);
$this->assertStringContainsString('https://www.google.com/recaptcha/enterprise.js', $body);
}
public function testTheRightPasswordLogsIn(): void {
@@ -130,6 +131,18 @@ class LoginTest extends PageTestCase {
$this->assertSame(array(), $this->queries('/FROM editors/'));
}
public static function failedAssessments(): array {
return array(array('wrong-host'), array('wrong-action'), array('api-error'), array('unreachable'));
}
#[DataProvider('failedAssessments')]
public function testAFailedAssessmentBlocksTheLogin(string $response): void {
$answer = $this->login('secret', array('g-recaptcha-response' => $response));
$this->assertStringContainsString('Please complete the captcha.', $answer['body']);
$this->assertSame(array(), $this->queries('/FROM editors/'));
$this->assertArrayNotHasKey('editor', $this->session());
}
public function testFiveFailuresBlockTheLogin(): void {
for ($i = 0; $i < 5; $i++)
$this->login('wrong');