20 lines
596 B
PHP
20 lines
596 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once PLUGIN_ROOT . '/exec/lib/RateLimiter.php';
|
|
|
|
test('rate limiter enforces limit across sequential requests', function (): void {
|
|
$limiter = new RateLimiter(TEST_TMP . '/rate-limit');
|
|
|
|
$limiter->assertAllowed('user-mxtest', 2, 60);
|
|
$limiter->assertAllowed('user-mxtest', 2, 60);
|
|
|
|
try {
|
|
$limiter->assertAllowed('user-mxtest', 2, 60);
|
|
throw new RuntimeException('Expected third request to be rate limited');
|
|
} catch (RuntimeException $e) {
|
|
assert_contains('rate limit', strtolower($e->getMessage()));
|
|
}
|
|
});
|
|
|