From 70aefd59402e3fe128fe8998bf17d36d1d3b8573 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 26 Sep 2025 09:50:46 +0800 Subject: [PATCH] * [misc] Fix unit tests for commonModel::sendHeader() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../common/test/lib/common.unittest.class.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/module/common/test/lib/common.unittest.class.php b/module/common/test/lib/common.unittest.class.php index 9889fbd451..d50c64f585 100755 --- a/module/common/test/lib/common.unittest.class.php +++ b/module/common/test/lib/common.unittest.class.php @@ -92,6 +92,64 @@ class commonTest } } + /** + * Test sendHeader method. + * + * @param string $scenario + * @access public + * @return mixed + */ + public function sendHeaderTest($scenario = 'basic') + { + global $config; + + // 根据场景设置配置 + switch($scenario) { + case 'basic': + $config->charset = 'UTF-8'; + $config->framework->sendXCTO = false; + $config->framework->sendXXP = false; + $config->framework->sendHSTS = false; + $config->framework->sendRP = false; + $config->framework->sendXPCDP = false; + $config->framework->sendXDO = false; + $config->CSPs = array(); + $config->xFrameOptions = ''; + break; + + case 'security_headers': + $config->framework->sendXCTO = true; + $config->framework->sendXXP = true; + $config->framework->sendHSTS = true; + $config->framework->sendRP = true; + $config->framework->sendXPCDP = true; + $config->framework->sendXDO = true; + break; + + case 'csp': + $config->CSPs = array("default-src 'self'", "script-src 'self' 'unsafe-inline'"); + break; + + case 'xframe': + $config->xFrameOptions = 'DENY'; + break; + } + + try { + // 使用输出缓冲来捕获可能的输出 + ob_start(); + $this->objectModel->sendHeader(); + ob_end_clean(); + return 1; + } catch (Exception $e) { + ob_end_clean(); + return 0; + } catch (Error $e) { + ob_end_clean(); + return 0; + } + } + /** * Test checkSafeFile method. *