diff --git a/module/admin/model.php b/module/admin/model.php index ea9bbfee6b..eda09a490a 100755 --- a/module/admin/model.php +++ b/module/admin/model.php @@ -71,16 +71,16 @@ class adminModel extends model } /** + * 弱口令扫描。 * Check weak. * * @param object $user * @access public * @return bool */ - public function checkWeak($user) + public function checkWeak(object $user): bool { $weaks = array(); - foreach(explode(',', $this->config->safe->weak) as $weak) { $weak = md5(trim($weak)); diff --git a/module/admin/test/admin.class.php b/module/admin/test/admin.class.php index b9a9e209a8..67f2b1c81f 100644 --- a/module/admin/test/admin.class.php +++ b/module/admin/test/admin.class.php @@ -5,7 +5,7 @@ class adminTest { global $tester; $this->objectModel = $tester->loadModel('admin'); - $this->user = $tester->loadModel('user'); + $this->user = $tester->loadModel('user'); } /** @@ -24,20 +24,20 @@ class adminTest } /** - * Check weak. + * 测试弱口令扫描。 + * Test check weak. * - * @param object $user + * @param string $account * @access public * @return bool */ - public function checkWeakTest($account) + public function checkWeakTest(string $account): bool { - $user = $this->user->getById($account); - $objects = $this->objectModel->checkWeak($user); - + $user = $this->user->getById($account); + $result = $this->objectModel->checkWeak($user); if(dao::isError()) return dao::getError(); - return $objects; + return $result; } public function getMenuKeyTest($moduleName, $methodName, $params = array()) diff --git a/module/admin/test/model/checkweak.php b/module/admin/test/model/checkweak.php index 18dcebf3f5..da0e20fead 100755 --- a/module/admin/test/model/checkweak.php +++ b/module/admin/test/model/checkweak.php @@ -1,20 +1,22 @@ #!/usr/bin/env php checkWeak(); cid=1 pid=1 -正常测试 >> 0 - */ -$account = 'admin'; +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/admin.class.php'; + +zdTable('user')->config('user')->gen(6); $admin = new adminTest(); +r($admin->checkWeakTest('user1')) && p() && e('1'); //测试密码使用123456 +r($admin->checkWeakTest('user2')) && p() && e('1'); //测试密码与用户名相同 +r($admin->checkWeakTest('user3')) && p() && e('1'); //测试密码与手机相同 +r($admin->checkWeakTest('user4')) && p() && e('1'); //测试密码与电话相同 +r($admin->checkWeakTest('user5')) && p() && e('1'); //测试密码与生日相同 +r($admin->checkWeakTest('user6')) && p() && e('0'); //测试使用复杂密码 -r($admin->checkWeakTest($account)) && p() && e('0'); //正常测试 \ No newline at end of file diff --git a/module/admin/test/model/yaml/checkweak/user.yaml b/module/admin/test/model/yaml/checkweak/user.yaml new file mode 100644 index 0000000000..86a697bbbc --- /dev/null +++ b/module/admin/test/model/yaml/checkweak/user.yaml @@ -0,0 +1,24 @@ +title: zt_user +author: Qiyu Xie +version: "1.0" +fields: +- field: account + note: "用户名" + fields: + - field: account1 + range: user{6} + - field: account2 + range: "1-6" +- field: password + note: "密码" + range: "123456,user2,18812341234,88881234,`1995-01-01`,123Qwe!@#" + format: md5 +- field: phone + note: "手机" + range: "18812341234" +- field: mobile + note: "电话" + range: "88881234" +- field: birthday + note: "生日" + range: "`1995-01-01`"