From b984d09db7a68d42ad2cf4245f800417cea3d636 Mon Sep 17 00:00:00 2001 From: liugang Date: Sun, 7 Sep 2025 16:50:00 +0800 Subject: [PATCH] + [misc] Add unit tests for commonModel::checkIP() 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 | 15 +++++++++ module/common/test/model/checkip.php | 33 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 module/common/test/model/checkip.php diff --git a/module/common/test/lib/common.unittest.class.php b/module/common/test/lib/common.unittest.class.php index 67231263f0..104816966d 100644 --- a/module/common/test/lib/common.unittest.class.php +++ b/module/common/test/lib/common.unittest.class.php @@ -345,4 +345,19 @@ class commonTest return $result; } + + /** + * Test checkIP method. + * + * @param string $ipWhiteList + * @access public + * @return mixed + */ + public function checkIPTest($ipWhiteList = '') + { + $result = $this->objectModel->checkIP($ipWhiteList); + if(dao::isError()) return dao::getError(); + + return $result ? '1' : '0'; + } } diff --git a/module/common/test/model/checkip.php b/module/common/test/model/checkip.php new file mode 100755 index 0000000000..7e24ab4cb9 --- /dev/null +++ b/module/common/test/model/checkip.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +checkIPTest('*')) && p() && e('1'); +r($commonTest->checkIPTest('127.0.0.1')) && p() && e('1'); +r($commonTest->checkIPTest('192.168.1.1,127.0.0.1,10.0.0.1')) && p() && e('1'); +r($commonTest->checkIPTest('127.0.0.1-127.0.0.255')) && p() && e('1'); +r($commonTest->checkIPTest('127.0.0.*')) && p() && e('1'); +r($commonTest->checkIPTest('127.0.0.0/24')) && p() && e('1'); +r($commonTest->checkIPTest('192.168.1.1')) && p() && e('0'); \ No newline at end of file