Story 5.4: reCAPTCHA v3

This commit is contained in:
2026-02-04 21:17:02 +01:00
parent a4e0cb71e9
commit 267b6ff7fa
7 changed files with 153 additions and 30 deletions

34
tests/recaptcha.test.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
function assertTrue($cond, $msg) {
if (!$cond) {
fwrite(STDERR, $msg . PHP_EOL);
exit(1);
}
}
$envPath = __DIR__ . '/../.env';
assertTrue(file_exists($envPath), 'missing .env');
$envContent = file_get_contents($envPath);
assertTrue(strpos($envContent, 'RECAPTCHA_SITE_KEY') !== false, 'missing site key');
assertTrue(strpos($envContent, 'RECAPTCHA_SECRET_KEY') !== false, 'missing secret key');
$configPath = __DIR__ . '/../includes/config.php';
assertTrue(file_exists($configPath), 'missing config.php');
$configContent = file_get_contents($configPath);
assertTrue(strpos($configContent, 'RECAPTCHA_SITE_KEY') !== false, 'config missing site key');
assertTrue(strpos($configContent, 'RECAPTCHA_SECRET_KEY') !== false, 'config missing secret key');
$indexContent = file_get_contents(__DIR__ . '/../index.php');
assertTrue(strpos($indexContent, 'includes/config.php') !== false, 'index missing config require');
$footerContent = file_get_contents(__DIR__ . '/../templates/footer.php');
assertTrue(strpos($footerContent, 'recaptcha/api.js') !== false, 'missing recaptcha script');
assertTrue(strpos($footerContent, 'RECAPTCHA_SITE_KEY') !== false, 'missing site key exposure');
$contactJs = file_get_contents(__DIR__ . '/../assets/js/contact-form.js');
assertTrue(strpos($contactJs, 'RecaptchaService') !== false, 'missing RecaptchaService');
assertTrue(strpos($contactJs, 'getToken') !== false, 'missing getToken');
assertTrue(strpos($contactJs, 'grecaptcha.execute') !== false, 'missing grecaptcha execute');
assertTrue(strpos($contactJs, 'console.warn') !== false, 'missing graceful warning');
fwrite(STDOUT, "OK\n");

View File

@@ -23,4 +23,5 @@ php (Join-Path $here 'testimonials.test.php')
php (Join-Path $here 'contact.test.php')
php (Join-Path $here 'contact-validation.test.php')
php (Join-Path $here 'contact-state.test.php')
php (Join-Path $here 'recaptcha.test.php')
'OK'