assertStringNotContainsString('123456', $config, '配置中不应包含简单密码'); $this->assertStringNotContainsString('password', strtolower($config), '配置中不应包含 password 字符串'); } /** * 测试 SQL 注入防护 */ public function testConfigUsesPreparedStatements(): void { $config = file_get_contents(__DIR__ . '/../../config.php'); // 确保使用 PDO 预处理 $this->assertStringContainsString('prepare', $config, '应该使用 PDO 预处理语句'); $this->assertStringContainsString('execute', $config, '应该使用 execute 执行预处理'); } /** * 测试 XSS 防护 */ public function testOutputUsesHtmlspecialchars(): void { $files = [ __DIR__ . '/../../dashboard.php', __DIR__ . '/../../view.php', ]; foreach ($files as $file) { if (file_exists($file)) { $content = file_get_contents($file); $this->assertStringContainsString('htmlspecialchars', $content, basename($file) . ' 应该使用 htmlspecialchars 防止 XSS'); } } } /** * 测试 Session 安全 */ public function testSessionSecurity(): void { $config = file_get_contents(__DIR__ . '/../../config.php'); // 确保有 session 检查 $this->assertStringContainsString('session', strtolower($config), '应该有 session 相关配置'); } }