Files
xamxam/app/tests/Unit/RateLimitTest.php
Pontoporeia a2cba6d3c0 feat: prevent duplicate TFE submissions with logging and user feedback
- Add DuplicateThesisException (typed, carries existing thesis metadata)
- Add Database::findDuplicateThesis(): matches on year + author + normalised
  title (exact, prefix, Levenshtein ≤10% of longer string)
- ThesisCreateController::submit() runs duplicate check before any DB write
  and throws DuplicateThesisException on match
- AppLogger::logDuplicate() writes status=duplicate entries to the JSON-lines
  log for audit purposes
- App::flash/consumeFlash extended to support 'warning' flash type
- admin/actions/formulaire.php: catches DuplicateThesisException, logs it,
  flashes an HTML warning toast with a clickable link to the existing thesis,
  and repopulates the form fields
- partage/index.php: same catch block; surfaces a plain-text flash-warning
  banner on the student form with identifier, title, and year of the match;
  form is repopulated via session
- toast.php: renders toast--warning variant
- admin.css: .toast--warning + link colour rules
- form.css: .flash-warning style for the partage form
2026-05-05 11:04:52 +02:00

56 lines
1.5 KiB
PHP

<?php
/**
* Rate Limit Test
* Tests rate limiting functionality
*/
require_once __DIR__ . '/../../src/RateLimit.php';
echo "Rate Limit Test\n";
echo "===============\n\n";
try {
// Test 1: Rate limit initialization
echo "Test 1: Rate Limit Initialization\n";
$rateLimit = new RateLimit(5, 60); // 5 requests per minute
echo "✓ PASS: RateLimit object created\n\n";
// Test 2: Check method exists and works
echo "Test 2: Check Method\n";
$allowed = $rateLimit->check();
if (is_bool($allowed)) {
echo '✓ PASS: check() returns boolean (allowed: ' . ($allowed ? 'yes' : 'no') . ")\n\n";
} else {
throw new Exception('check() did not return boolean');
}
// Test 3: Headers method
echo "Test 3: Send Headers Method\n";
ob_start();
$rateLimit->sendHeaders();
ob_end_clean();
echo "✓ PASS: sendHeaders() executed without error\n\n";
// Test 4: Get reset time
echo "Test 4: Get Reset Time\n";
$resetTime = $rateLimit->getResetTime();
if (is_int($resetTime) && $resetTime >= 0) {
echo "✓ PASS: getResetTime() returns valid value ($resetTime seconds)\n\n";
} else {
throw new Exception('Invalid reset time');
}
// Test 5: Cleanup method
echo "Test 5: Cleanup Method\n";
$rateLimit->cleanup();
echo "✓ PASS: cleanup() executed without error\n\n";
echo "✅ All rate limit tests passed!\n";
return true;
} catch (Exception $e) {
echo '❌ FAIL: ' . $e->getMessage() . "\n";
return false;
}