Add honeypot field to poll creation form
CI / Deploy / test (push) Successful in 41s
CI / Deploy / deploy (push) Skipped

An invisible "website" field is rendered off-screen in the create form.
If a bot fills it in, the poll is not created and no mail is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 14:34:55 +01:00
1 parent 04cbc5bcd3
commit ffe93a3256
5 files changed
+79 -1

No files matched your search

@@ -60,6 +60,44 @@ class HomeControllerTest extends TestCase
$this->assertResponseNotContains('/admin/', 'Admin link must not be shown when disabled');
}
public function testIndexRendersHiddenHoneypot(): void
{
$this->get('/');
$this->assertResponseContains('class="hp-field" aria-hidden="true"');
$this->assertResponseContains('name="website"');
$this->assertResponseContains('tabindex="-1"');
}
public function testCreateRejectsFilledHoneypot(): void
{
$this->session(['Captcha.math.create' => 7]);
$this->post('/create', [
'title' => 'Retro',
'email' => 'owner@example.org',
'captcha_answer' => '7',
'website' => 'https://spam.example',
]);
$this->assertResponseOk();
$this->assertResponseContains('Die Umfrage konnte nicht angelegt werden.');
$this->assertSame(0, $this->pollsTable()->find()->count());
$this->assertNoMailSent();
}
public function testCreateAcceptsEmptyHoneypot(): void
{
$this->session(['Captcha.math.create' => 7]);
$this->post('/create', [
'title' => 'Retro',
'email' => 'owner@example.org',
'captcha_answer' => '7',
'website' => '',
]);
$this->assertRedirect(['_name' => 'created']);
$this->assertSame(1, $this->pollsTable()->find()->count());
}
public function testCreateRejectsWrongCaptcha(): void
{
$this->session(['Captcha.math.create' => 7]);