Harden NordVPN reconciliation and WebGUI testing

This commit is contained in:
ms2k 2026-08-07 02:30:26 +09:00
commit b4a30ca190

View file

@ -27,6 +27,44 @@ final class StoreAndInspectorTest extends TestCase
$this->assertSame(1, $requests);
unlink($path);
unlink($path . '.refreshed');
rmdir($directory);
}
public function testEndpointRefreshDefersAfterFailure(): void
{
$directory = sys_get_temp_dir() . '/nordvpn-endpoints-' . bin2hex(random_bytes(8));
$path = $directory . '/endpoints.txt';
$now = time();
$requests = 0;
$api = new NordApi(static function () use (&$requests): array {
$requests++;
throw new RuntimeException('Synthetic endpoint failure.');
});
$store = new EndpointStore($path, static function () use (&$now): int {
return $now;
});
try {
$store->refreshIfStale($api);
$this->fail('Expected endpoint refresh to fail.');
} catch (RuntimeException $exception) {
$this->assertSame('Synthetic endpoint failure.', $exception->getMessage());
}
$this->assertTrue($store->retryPending());
$this->assertFalse($store->refreshIfStale($api));
$this->assertSame(1, $requests);
$now += 301;
try {
$store->refreshIfStale($api);
$this->fail('Expected endpoint refresh retry to fail.');
} catch (RuntimeException $exception) {
$this->assertSame('Synthetic endpoint failure.', $exception->getMessage());
}
$this->assertSame(2, $requests);
unlink($path . '.retry');
rmdir($directory);
}