From 4336d9b35223cd1b7b19cc1643ff42a0f394ec43 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 4 Aug 2022 15:48:22 +0800 Subject: [PATCH 1/5] * Add test case. --- test/data/pipeline.yaml | 18 +++++------ test/data/zt_repo.yaml | 16 +++++++++- test/model/gogs/checktokenaccess.php | 40 ++++++++++++++++++++++++ test/model/gogs/getgogslistbyaccount.php | 17 ++++++++++ 4 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 test/model/gogs/checktokenaccess.php create mode 100644 test/model/gogs/getgogslistbyaccount.php diff --git a/test/data/pipeline.yaml b/test/data/pipeline.yaml index c4295ea9d7..d09e701877 100644 --- a/test/data/pipeline.yaml +++ b/test/data/pipeline.yaml @@ -3,24 +3,24 @@ author: Zeng gang version: "1.0" fields: - field: id - range: 1-3 + range: 1-5 - field: type - range: gitlab,sonarqube,jenkins + range: gitlab,sonarqube,jenkins,gitea,gogs - field: name - range: gitlab服务器,sonarqube服务器,jenkins服务器 + range: GitLab服务器,SonarQube服务器,Jenkins服务器,Gitea服务器,Gogs服务器 - field: url - range: [http://10.0.1.161:51080],[http://10.0.1.161:59001],[http://10.0.1.161:58080] + range: [http://10.0.1.161:51080],[http://10.0.1.161:59001],[http://10.0.1.161:58080],[http://10.0.7.242:9020],[http://10.0.7.242:9021] - field: account - range: [],[admin]{2} + range: [],[admin]{2},[]{2} - field: password - range: [],[UDJzc3cwcmQ=],[] + range: [],[UDJzc3cwcmQ=],[]{3} - field: token - range: x88fZokrp5hShia2jyBN,YWRtaW46UDJzc3cwcmQ=,1196c85ba525a268570df9da627e3a7b2d + range: x88fZokrp5hShia2jyBN,YWRtaW46UDJzc3cwcmQ=,1196c85ba525a268570df9da627e3a7b2d,c6769e6761a7d719129b2421dcb3112d936e2b1f,9ff43f9d1a369465bcf0781a3785f46bcef782d1 - field: private - range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41 + range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41,a56af13f4c4a6a4ed77f24e59794cf39,4fabcbd31314365506ebc56c0c83c1ec - field: createdBy range: admin - field: createdDate - range: [2021-12-09 11:23:35],[2022-01-12 08:47:37],[2022-01-12 08:47:37] + range: [2021-12-09 11:23:35],[2022-01-12 08:47:37],[2022-01-12 08:47:37],[2022-08-01 09:07:37],[2022-08-01 09:09:37] - field: deleted range: 0 diff --git a/test/data/zt_repo.yaml b/test/data/zt_repo.yaml index 0c7d1a9c9f..0e189c2946 100644 --- a/test/data/zt_repo.yaml +++ b/test/data/zt_repo.yaml @@ -47,7 +47,7 @@ fields: format: "" - field: SCM note: "类型" - range: Subversion,Git + range: Subversion,Git,Gitlab,Gitea,Gogs prefix: "" postfix: "" loop: 0 @@ -59,6 +59,20 @@ fields: postfix: "" loop: 0 format: "" + - field: serviceHost + note: "服务器ID" + range: 0,0,1,4,5 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: serviceProject + note: "项目地址" + range: []{2},1569,root/repo121,root/yuyu_project + prefix: "" + postfix: "" + loop: 0 + format: "" - field: commits note: "提交数" range: 1-10000:R diff --git a/test/model/gogs/checktokenaccess.php b/test/model/gogs/checktokenaccess.php new file mode 100644 index 0000000000..0a65a35396 --- /dev/null +++ b/test/model/gogs/checktokenaccess.php @@ -0,0 +1,40 @@ +#!/usr/bin/env php +loadModel('gitlab'); + +$host = ''; +$token = ''; + +$result = $gitlab->checkTokenAccess($host, $token); +if($result === false) $result = 'return false'; +r($result) && p() && e('return false'); //使用空的数据验证token权限 + +$host = 'http://10.0.1.161:5108'; +$result = $gitlab->checkTokenAccess($host, $token); +if(!$result) $result = 'return false'; +r($result) && p() && e('return false'); //使用错误的host验证token权限 + +$host = 'http://10.0.1.161:51080'; +$result = $gitlab->checkTokenAccess($host, $token); +if(empty($result)) $result = 'return null'; +r($result) && p() && e('return null'); //使用正确的host,错误的token验证token权限 + +$token = 'x88fZokrp5hShia2jyBN'; +$result = $gitlab->checkTokenAccess($host, $token); +if(isset($result->id)) $result = 'success'; +r($result) && p() && e('success'); //通过host,token验证token权限 + +$token = 'wVFHE6NZA-cJy-3U2y2J'; +$result = $gitlab->checkTokenAccess($host, $token); +if(!isset($result->id)) $result = 'no access'; +r($result) && p() && e('no access'); //通过host,权限不足的token验证token权限 diff --git a/test/model/gogs/getgogslistbyaccount.php b/test/model/gogs/getgogslistbyaccount.php new file mode 100644 index 0000000000..d7d8b14f8d --- /dev/null +++ b/test/model/gogs/getgogslistbyaccount.php @@ -0,0 +1,17 @@ +#!/usr/bin/env php +loadModel('gogs'); + +r(count($gogs->getGogsListByAccount())) && p() && e('0'); //默认admin用户查询绑定的gogs服务器 +r(count($gogs->getGogsListByAccount('user3'))) && p() && e('1'); //使用已绑定一个gogs服务器的用户查询 +r(count($gogs->getGogsListByAccount('test1'))) && p() && e('0'); //使用未绑定gogs服务器的用户查询 From 07c4dd5dfc636b729d8cac8ab1ab35f761b77123 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 26 Aug 2022 14:29:14 +0800 Subject: [PATCH 2/5] * Add gogs test case. --- test/class/gogs.class.php | 88 +++++++++++++++++++++++++++ test/data/pipeline.yaml | 4 +- test/model/gitea/checktokenaccess.php | 40 ++++++++++++ test/model/gitea/create.php | 2 +- test/model/gitea/update.php | 2 +- test/model/gogs/checktokenaccess.php | 20 +++--- test/model/gogs/create.php | 36 +++++++++++ test/model/gogs/getbyid.php | 31 ++++++++++ test/model/gogs/getlist.php | 23 +++++++ test/model/gogs/getpairs.php | 22 +++++++ test/model/gogs/update.php | 38 ++++++++++++ test/ztest | 3 + 12 files changed, 295 insertions(+), 14 deletions(-) create mode 100644 test/class/gogs.class.php create mode 100644 test/model/gitea/checktokenaccess.php create mode 100644 test/model/gogs/create.php create mode 100755 test/model/gogs/getbyid.php create mode 100755 test/model/gogs/getlist.php create mode 100755 test/model/gogs/getpairs.php create mode 100644 test/model/gogs/update.php diff --git a/test/class/gogs.class.php b/test/class/gogs.class.php new file mode 100644 index 0000000000..68d7c74435 --- /dev/null +++ b/test/class/gogs.class.php @@ -0,0 +1,88 @@ +tester = $tester; + $this->gogs = $this->tester->loadModel('gogs'); + } + + /** + * Get by id. + * + * @param int $id + * @access public + * @return object + */ + public function getByID($id) + { + $gogs = $this->gogs->getByID($id); + if(empty($gogs)) return 0; + return $gogs; + } + + /** + * Get gogs list. + * + * @param string $orderBy + * @access public + * @return object + */ + public function getList($orderBy = 'id_desc') + { + $gogs = $this->gogs->getList($orderBy); + if(empty($gogs)) return 0; + return array_shift($gogs); + } + + /** + * Get gogs pairs + * + * @return string + */ + public function getPairs() + { + $pairs = $this->gogs->getPairs(); + return key($pairs); + } + + /** + * Create a gogs. + * + * @access public + * @return object|string + */ + public function create() + { + $gogsID = $this->gogs->create(); + if(dao::isError()) + { + $errors = dao::getError(); + return key($errors); + } + + return $this->gogs->getById($gogsID); + } + + /** + * Update a gogs. + * + * @param int $id + * @access public + * @return object|string + */ + public function update($id) + { + $this->gogs->update($id); + if(dao::isError()) + { + $errors = dao::getError(); + return key($errors); + } + + return $this->gogs->getById($id); + } +} diff --git a/test/data/pipeline.yaml b/test/data/pipeline.yaml index d09e701877..3d70e5b100 100644 --- a/test/data/pipeline.yaml +++ b/test/data/pipeline.yaml @@ -13,7 +13,7 @@ fields: - field: account range: [],[admin]{2},[]{2} - field: password - range: [],[UDJzc3cwcmQ=],[]{3} + range: [],[UDJzc3cwcmQ=],[RWFzeXNvZnRAcWQyMDEwIQ==],[]{2} - field: token range: x88fZokrp5hShia2jyBN,YWRtaW46UDJzc3cwcmQ=,1196c85ba525a268570df9da627e3a7b2d,c6769e6761a7d719129b2421dcb3112d936e2b1f,9ff43f9d1a369465bcf0781a3785f46bcef782d1 - field: private @@ -21,6 +21,6 @@ fields: - field: createdBy range: admin - field: createdDate - range: [2021-12-09 11:23:35],[2022-01-12 08:47:37],[2022-01-12 08:47:37],[2022-08-01 09:07:37],[2022-08-01 09:09:37] + range: [2022-08-01 09:09:37] - field: deleted range: 0 diff --git a/test/model/gitea/checktokenaccess.php b/test/model/gitea/checktokenaccess.php new file mode 100644 index 0000000000..bbdabbf680 --- /dev/null +++ b/test/model/gitea/checktokenaccess.php @@ -0,0 +1,40 @@ +#!/usr/bin/env php +loadModel('gitea'); + +$host = ''; +$token = ''; + +$result = $gitea->checkTokenAccess($host, $token); +if($result === false) $result = 'return false'; +r($result) && p() && e('return false'); //使用空的数据验证token权限 + +$host = 'http://10.0.7.242:9020'; +$result = $gitea->checkTokenAccess($host, $token); +if(!$result) $result = 'return false'; +r($result) && p() && e('return false'); //使用错误的host验证token权限 + +$host = 'http://10.0.7.242:9020'; +$result = $gitea->checkTokenAccess($host, $token); +if(empty($result)) $result = 'return null'; +r($result) && p() && e('return null'); //使用正确的host,错误的token验证token权限 + +$token = 'c6769e6761a7d719129b2421dcb3112d936e2b1f'; +$result = $gitea->checkTokenAccess($host, $token); +if(isset($result->id)) $result = 'success'; +r($result) && p() && e('success'); //通过host,token验证token权限 + +$token = 'wVFHE6NZA-cJy-3U2y2J'; +$result = $gitea->checkTokenAccess($host, $token); +if(!isset($result->id)) $result = 'no access'; +r($result) && p() && e('no access'); //通过host,权限不足的token验证token权限 diff --git a/test/model/gitea/create.php b/test/model/gitea/create.php index 28e194950c..a701c1bf54 100644 --- a/test/model/gitea/create.php +++ b/test/model/gitea/create.php @@ -13,7 +13,7 @@ pid=1 Gitea名称为空 >> name 服务器地址为空 >> url -正确Gitea数据 >> Gitea,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d +正确Gitea数据 >> Gitea,http://10.0.7.242:9020,1196c85ba525a268570df9da627e3a7b2d */ diff --git a/test/model/gitea/update.php b/test/model/gitea/update.php index 6381206528..c33e0ae2ab 100644 --- a/test/model/gitea/update.php +++ b/test/model/gitea/update.php @@ -32,7 +32,7 @@ $_POST['name'] = 'Changed Gitea'; $_POST['url'] = ''; r($gitea->update($giteaID)) && p() && e('url'); // 服务器地址为空 -$_POST['url'] = 'http://10.0.1.161:58080'; +$_POST['url'] = 'http://10.0.7.242:9020'; r($gitea->update($giteaID)) && p('name') && e('Changed Gitea'); // 正确Gitea数据 $db->restoreDB(); diff --git a/test/model/gogs/checktokenaccess.php b/test/model/gogs/checktokenaccess.php index 0a65a35396..2081e017b9 100644 --- a/test/model/gogs/checktokenaccess.php +++ b/test/model/gogs/checktokenaccess.php @@ -4,37 +4,37 @@ include dirname(dirname(dirname(__FILE__))) . '/lib/init.php'; /** -title=测试 gitlabModel::checkTokenAccess(); +title=测试 gogsModel::checkTokenAccess(); cid=1 pid=1 */ -$gitlab = $tester->loadModel('gitlab'); +$gogs = $tester->loadModel('gogs'); $host = ''; $token = ''; -$result = $gitlab->checkTokenAccess($host, $token); +$result = $gogs->checkTokenAccess($host, $token); if($result === false) $result = 'return false'; r($result) && p() && e('return false'); //使用空的数据验证token权限 -$host = 'http://10.0.1.161:5108'; -$result = $gitlab->checkTokenAccess($host, $token); +$host = 'http://10.0.7.242:9021'; +$result = $gogs->checkTokenAccess($host, $token); if(!$result) $result = 'return false'; r($result) && p() && e('return false'); //使用错误的host验证token权限 -$host = 'http://10.0.1.161:51080'; -$result = $gitlab->checkTokenAccess($host, $token); +$host = 'http://10.0.7.242:9021'; +$result = $gogs->checkTokenAccess($host, $token); if(empty($result)) $result = 'return null'; r($result) && p() && e('return null'); //使用正确的host,错误的token验证token权限 -$token = 'x88fZokrp5hShia2jyBN'; -$result = $gitlab->checkTokenAccess($host, $token); +$token = '9ff43f9d1a369465bcf0781a3785f46bcef782d1'; +$result = $gogs->checkTokenAccess($host, $token); if(isset($result->id)) $result = 'success'; r($result) && p() && e('success'); //通过host,token验证token权限 $token = 'wVFHE6NZA-cJy-3U2y2J'; -$result = $gitlab->checkTokenAccess($host, $token); +$result = $gogs->checkTokenAccess($host, $token); if(!isset($result->id)) $result = 'no access'; r($result) && p() && e('no access'); //通过host,权限不足的token验证token权限 diff --git a/test/model/gogs/create.php b/test/model/gogs/create.php new file mode 100644 index 0000000000..f1cb344a34 --- /dev/null +++ b/test/model/gogs/create.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +switchDB(); +su('admin'); + +/** + +title=测试gogsModel->create(); +cid=1 +pid=1 + +Gogs名称为空 >> name +服务器地址为空 >> url +正确Gogs数据 >> Gogs,http://10.0.7.242:9021,9ff43f9d1a369465bcf0781a3785f46bcef782d1 + +*/ + +$gogs = new gogsTest(); + +$_POST = array(); +$_POST['name'] = ''; +$_POST['url'] = 'http://10.0.7.242:9021'; +$_POST['token'] = '9ff43f9d1a369465bcf0781a3785f46bcef782d1'; + +r($gogs->create()) && p() && e('name'); // Gogs名称为空 + +$_POST['name'] = 'Gogs'; +$_POST['url'] = ''; +r($gogs->create()) && p() && e('url'); // 服务器地址为空 + +$_POST['url'] = 'http://10.0.7.242:9021'; +r($gogs->create()) && p('name,url,token') && e('Gogs,http://10.0.7.242:9021,9ff43f9d1a369465bcf0781a3785f46bcef782d1'); // 正确Gogs数据 + +$db->restoreDB(); diff --git a/test/model/gogs/getbyid.php b/test/model/gogs/getbyid.php new file mode 100755 index 0000000000..73d5ce9d67 --- /dev/null +++ b/test/model/gogs/getbyid.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +switchDB(); +su('admin'); + +/** + +title=测试gogsModel->gitById(); +cid=1 +pid=1 + +使用存在的ID >> 5 +使用空的ID >> 0 +使用不存在的ID >> 0 + +*/ + +$gogs = new gogsTest(); + +$gogsID = 5; +r($gogs->getById($gogsID)) && p('id') && e('5'); // 使用存在的ID + +$gogsID = 0; +r($gogs->getById($gogsID)) && p() && e(0); // 使用空的ID + +$gogsID = 111; +r($gogs->getById($gogsID)) && p() && e(0); // 使用不存在的ID + +$db->restoreDB(); diff --git a/test/model/gogs/getlist.php b/test/model/gogs/getlist.php new file mode 100755 index 0000000000..8cd6deec9b --- /dev/null +++ b/test/model/gogs/getlist.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +switchDB(); +su('admin'); + +/** + +title=测试gogsModel->gitList(); +cid=1 +pid=1 + +获取Gogs列表 >> 5 + +*/ + +$gogs = new gogsTest(); + +$orderBy = 'id_desc'; +r($gogs->getList($orderBy)) && p('id') && e('5'); // 获取Gogs列表 + +$db->restoreDB(); diff --git a/test/model/gogs/getpairs.php b/test/model/gogs/getpairs.php new file mode 100755 index 0000000000..ddd5ebe211 --- /dev/null +++ b/test/model/gogs/getpairs.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +switchDB(); +su('admin'); + +/** + +title=测试gogsModel->gitPairs(); +cid=1 +pid=1 + +获取Gogs >> 5 + +*/ + +$gogs = new gogsTest(); + +r($gogs->getPairs()) && p() && e('5'); // 获取Gogs + +$db->restoreDB(); diff --git a/test/model/gogs/update.php b/test/model/gogs/update.php new file mode 100644 index 0000000000..5ba27752ce --- /dev/null +++ b/test/model/gogs/update.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +switchDB(); +su('admin'); + +/** + +title=测试gogsModel->update(); +cid=1 +pid=1 + +Gogs名称为空 >> name +服务器地址为空 >> url +正确Gogs数据 >> Changed Gogs + +*/ + +$gogs = new gogsTest(); + +$gogsID = 3; + +$_POST = array(); +$_POST['name'] = ''; +$_POST['url'] = 'http://10.0.7.242:9021'; +$_POST['token'] = '9ff43f9d1a369465bcf0781a3785f46bcef782d1'; + +r($gogs->update($gogsID)) && p() && e('name'); // Gogs名称为空 + +$_POST['name'] = 'Changed Gogs'; +$_POST['url'] = ''; +r($gogs->update($gogsID)) && p() && e('url'); // 服务器地址为空 + +$_POST['url'] = 'http://10.0.7.242:9021'; +r($gogs->update($gogsID)) && p('name') && e('Changed Gogs'); // 正确Gogs数据 + +$db->restoreDB(); diff --git a/test/ztest b/test/ztest index 8454508f16..923d9116dd 100755 --- a/test/ztest +++ b/test/ztest @@ -187,6 +187,9 @@ switch($argv[1]) case 'gitea': ztfRun('model/gitea'); break; + case 'gogs': + ztfRun('model/gogs'); + break; default: ztfExtract($argv[1]); From 041204feb80980891b98a1b38278beadd12cde12 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 2 Sep 2022 13:09:44 +0800 Subject: [PATCH 3/5] * Modify gogs test case. --- test/data/oauth.yaml | 4 ++-- test/data/pipeline.yaml | 6 +++--- test/data/zentao/config.php | 4 ++-- test/lib/db.class.php | 2 +- test/lib/utils.php | 2 +- test/model/gogs/checktokenaccess.php | 2 +- test/model/gogs/create.php | 2 +- test/model/gogs/getgogslistbyaccount.php | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/data/oauth.yaml b/test/data/oauth.yaml index 700ff499a0..cadcdfd2ac 100644 --- a/test/data/oauth.yaml +++ b/test/data/oauth.yaml @@ -10,8 +10,8 @@ fields: - field: account2 range: 3-100 - field: openID - range: 1-100 + range: 1-98,root{2} - field: providerType - range: gitlab + range: gitlab{98},gitea,gogs - field: providerID range: 1 diff --git a/test/data/pipeline.yaml b/test/data/pipeline.yaml index 3d70e5b100..1e69ac16b3 100644 --- a/test/data/pipeline.yaml +++ b/test/data/pipeline.yaml @@ -9,13 +9,13 @@ fields: - field: name range: GitLab服务器,SonarQube服务器,Jenkins服务器,Gitea服务器,Gogs服务器 - field: url - range: [http://10.0.1.161:51080],[http://10.0.1.161:59001],[http://10.0.1.161:58080],[http://10.0.7.242:9020],[http://10.0.7.242:9021] + range: [http://10.0.7.242:9980],[http://10.0.7.242:9990],[http://10.0.7.242:9580],[http://10.0.7.242:9020],[http://10.0.7.242:9021] - field: account range: [],[admin]{2},[]{2} - field: password - range: [],[UDJzc3cwcmQ=],[RWFzeXNvZnRAcWQyMDEwIQ==],[]{2} + range: [],[U2h3N0NldHlsc1ozYkVTVjBreXM=],[TThFbEJqcVZsNmJXcTdNSmJZN3U=],[]{2} - field: token - range: x88fZokrp5hShia2jyBN,YWRtaW46UDJzc3cwcmQ=,1196c85ba525a268570df9da627e3a7b2d,c6769e6761a7d719129b2421dcb3112d936e2b1f,9ff43f9d1a369465bcf0781a3785f46bcef782d1 + range: x88fZokrp5hShia2jyBN,YWRtaW46U2h3N0NldHlsc1ozYkVTVjBreXM=,1196c85ba525a268570df9da627e3a7b2d,c6769e6761a7d719129b2421dcb3112d936e2b1f,9ff43f9d1a369465bcf0781a3785f46bcef782d1 - field: private range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41,a56af13f4c4a6a4ed77f24e59794cf39,4fabcbd31314365506ebc56c0c83c1ec - field: createdBy diff --git a/test/data/zentao/config.php b/test/data/zentao/config.php index d67e57308f..1dd6d8f647 100644 --- a/test/data/zentao/config.php +++ b/test/data/zentao/config.php @@ -109,12 +109,12 @@ $builder->weeklyreport = array('rows' => 10, 'extends' => array('weeklyreport')) $builder->metting = array('rows' => 10, 'extends' => array('meeting')); $builder->usertpl = array('rows' => 10, 'extends' => array('usertpl')); -$builder->pipeline = array('rows' => 4, 'extends' => array('pipeline')); +$builder->pipeline = array('rows' => 5, 'extends' => array('pipeline')); $builder->holiday = array('rows' => 100, 'extends' => array('holiday')); $builder->repo = array('rows' => 1, 'extends' => array('repo')); $builder->job = array('rows' => 2, 'extends' => array('job')); $builder->mr = array('rows' => 1, 'extends' => array('mr')); -$builder->oauth = array('rows' => 90, 'extends' => array('oauth')); +$builder->oauth = array('rows' => 100, 'extends' => array('oauth')); $builder->notify = array('rows' => 10, 'extends' => array('notify')); $builder->vm = array('rows' => 1, 'extends' => array('vm')); diff --git a/test/lib/db.class.php b/test/lib/db.class.php index c319649560..e0cc0cf622 100644 --- a/test/lib/db.class.php +++ b/test/lib/db.class.php @@ -143,7 +143,7 @@ class db { for($i = 1; $i <= $this->config->test->dbNum; $i++) { - $this->dao->query('DROP DATABASE ' . $this->config->test->dbPrefix . $i); + $this->dao->query('DROP DATABASE IF EXISTS ' . $this->config->test->dbPrefix . $i); $this->dao->query('CREATE DATABASE ' . $this->config->test->dbPrefix . $i); shell_exec("mysql -h{$this->config->db->host} -u {$this->config->db->user} -p{$this->config->db->password} -P {$this->config->db->port} {$this->config->test->dbPrefix}{$i} < {$this->sqlFile}"); diff --git a/test/lib/utils.php b/test/lib/utils.php index 2182360829..60e0f6a9d5 100755 --- a/test/lib/utils.php +++ b/test/lib/utils.php @@ -236,7 +236,7 @@ function copyDB() foreach($dbUsed as $db) { - if ($currentDBNum->num > 0) $dao->query('drop database ' . $db); + if($currentDBNum->num > 0) $dao->query('DROP DATABASE IF EXISTS ' . $db); $dao->query('CREATE DATABASE ' . $db); shell_exec("mysql -h{$config->db->host} -P {$config->db->port} -u{$config->db->user} -p{$config->db->password} $db < $sqlFile"); echo '数据库<' . $db . '>复制成功!' . PHP_EOL; diff --git a/test/model/gogs/checktokenaccess.php b/test/model/gogs/checktokenaccess.php index 2081e017b9..54b4d0dd4e 100644 --- a/test/model/gogs/checktokenaccess.php +++ b/test/model/gogs/checktokenaccess.php @@ -32,7 +32,7 @@ r($result) && p() && e('return null'); //使用正确的host,错误的token验 $token = '9ff43f9d1a369465bcf0781a3785f46bcef782d1'; $result = $gogs->checkTokenAccess($host, $token); if(isset($result->id)) $result = 'success'; -r($result) && p() && e('success'); //通过host,token验证token权限 +r($result) && p() && e('1'); //通过host,token验证token权限 $token = 'wVFHE6NZA-cJy-3U2y2J'; $result = $gogs->checkTokenAccess($host, $token); diff --git a/test/model/gogs/create.php b/test/model/gogs/create.php index f1cb344a34..457192d2f3 100644 --- a/test/model/gogs/create.php +++ b/test/model/gogs/create.php @@ -12,7 +12,7 @@ cid=1 pid=1 Gogs名称为空 >> name -服务器地址为空 >> url +服务器地址为空 >> url 正确Gogs数据 >> Gogs,http://10.0.7.242:9021,9ff43f9d1a369465bcf0781a3785f46bcef782d1 */ diff --git a/test/model/gogs/getgogslistbyaccount.php b/test/model/gogs/getgogslistbyaccount.php index d7d8b14f8d..05727e94e0 100644 --- a/test/model/gogs/getgogslistbyaccount.php +++ b/test/model/gogs/getgogslistbyaccount.php @@ -13,5 +13,5 @@ pid=1 $gogs = $tester->loadModel('gogs'); r(count($gogs->getGogsListByAccount())) && p() && e('0'); //默认admin用户查询绑定的gogs服务器 -r(count($gogs->getGogsListByAccount('user3'))) && p() && e('1'); //使用已绑定一个gogs服务器的用户查询 +r(count($gogs->getGogsListByAccount('user4'))) && p() && e('1'); //使用已绑定一个gogs服务器的用户查询 r(count($gogs->getGogsListByAccount('test1'))) && p() && e('0'); //使用未绑定gogs服务器的用户查询 From c050d868931f772d2db0c43b89cadb6172edd0ab Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 2 Sep 2022 13:18:45 +0800 Subject: [PATCH 4/5] * Modify gitea test case. --- test/model/gitea/checktokenaccess.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/model/gitea/checktokenaccess.php b/test/model/gitea/checktokenaccess.php index bbdabbf680..eca669c656 100644 --- a/test/model/gitea/checktokenaccess.php +++ b/test/model/gitea/checktokenaccess.php @@ -31,8 +31,7 @@ r($result) && p() && e('return null'); //使用正确的host,错误的token验 $token = 'c6769e6761a7d719129b2421dcb3112d936e2b1f'; $result = $gitea->checkTokenAccess($host, $token); -if(isset($result->id)) $result = 'success'; -r($result) && p() && e('success'); //通过host,token验证token权限 +r($result) && p() && e('1'); //通过host,token验证token权限 $token = 'wVFHE6NZA-cJy-3U2y2J'; $result = $gitea->checkTokenAccess($host, $token); From 86e536203ba5f0dfbd29a9e596b78a91780ba363 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 2 Sep 2022 13:35:16 +0800 Subject: [PATCH 5/5] * Modify server url. --- test/model/gitlab/apigetcurrentuser.php | 6 +++--- test/model/gitlab/checktokenaccess.php | 4 ++-- test/model/gitlab/create.php | 8 ++++---- test/model/gitlab/update.php | 4 ++-- test/model/jenkins/create.php | 12 ++++-------- test/model/jenkins/update.php | 6 +++--- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/test/model/gitlab/apigetcurrentuser.php b/test/model/gitlab/apigetcurrentuser.php index acf6f247ad..e4c465f3a3 100755 --- a/test/model/gitlab/apigetcurrentuser.php +++ b/test/model/gitlab/apigetcurrentuser.php @@ -30,14 +30,14 @@ $result = $gitlab->apiGetCurrentUser($host, $token); if(!$result) $result = 'return null'; r($result) && p() && e('return null'); //使用错误的host获取用户信息 -$host = 'http://10.0.1.161:51080'; +$host = 'http://10.0.7.242:9980'; $result = $gitlab->apiGetCurrentUser($host, $token); r($gitlab->apiGetCurrentUser($host, $token)) && p('message') && e('401 Unauthorized'); //使用正确的host,错误的token获取用户信息 -$token = 'x88fZokrp5hShia2jyBN'; +$token = 'y2UBqwPPzaLxsniy8R6A'; $result = $gitlab->apiGetCurrentUser($host, $token); r($result) && p('id') && e('1'); //通过host,token获取用户信息 $token = 'wVFHE6NZA-cJy-3U2y2J'; $result = $gitlab->apiGetCurrentUser($host, $token); -r($result) && p('error') && e('insufficient_scope'); //通过host,权限不足的token获取用户信息 \ No newline at end of file +r($result) && p('error') && e('insufficient_scope'); //通过host,权限不足的token获取用户信息 diff --git a/test/model/gitlab/checktokenaccess.php b/test/model/gitlab/checktokenaccess.php index 2382aa49c4..641d8db5a2 100755 --- a/test/model/gitlab/checktokenaccess.php +++ b/test/model/gitlab/checktokenaccess.php @@ -30,7 +30,7 @@ $result = $gitlab->checkTokenAccess($host, $token); if(!$result) $result = 'return false'; r($result) && p() && e('return false'); //使用错误的host验证token权限 -$host = 'http://10.0.1.161:51080'; +$host = 'http://10.0.7.242:9980'; $result = $gitlab->checkTokenAccess($host, $token); if(empty($result)) $result = 'return null'; r($result) && p() && e('return null'); //使用正确的host,错误的token验证token权限 @@ -43,4 +43,4 @@ r($result) && p() && e('success'); //通过host,token验证token权限 $token = 'wVFHE6NZA-cJy-3U2y2J'; $result = $gitlab->checkTokenAccess($host, $token); if(!isset($result->id)) $result = 'no access'; -r($result) && p() && e('no access'); //通过host,权限不足的token验证token权限 \ No newline at end of file +r($result) && p() && e('no access'); //通过host,权限不足的token验证token权限 diff --git a/test/model/gitlab/create.php b/test/model/gitlab/create.php index 98b43ccdfb..f698367593 100644 --- a/test/model/gitlab/create.php +++ b/test/model/gitlab/create.php @@ -12,7 +12,7 @@ pid=1 GitLab名称为空 >> name 服务器地址为空 >> url -正确GitLab数据 >> GitLab,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d +正确GitLab数据 >> GitLab,http://10.0.7.242:9980,1196c85ba525a268570df9da627e3a7b2d */ @@ -20,7 +20,7 @@ $gitlab = new gitlabTest(); $_POST = array(); $_POST['name'] = ''; -$_POST['url'] = 'http://10.0.1.161:51080'; +$_POST['url'] = 'http://10.0.7.242:9980'; $_POST['token'] = 'y2UBqwPPzaLxsniy8R6A'; $_POST['password'] = ''; @@ -30,7 +30,7 @@ $_POST['name'] = 'GitLab'; $_POST['url'] = ''; r($gitlab->create()) && p() && e('url'); // 服务器地址为空 -$_POST['url'] = 'http://10.0.1.161:51080'; -r($gitlab->create()) && p('name,url,token') && e('GitLab,http://10.0.1.161:51080,y2UBqwPPzaLxsniy8R6A'); // 正确GitLab数据 +$_POST['url'] = 'http://10.0.7.242:9980'; +r($gitlab->create()) && p('name,url,token') && e('GitLab,http://10.0.7.242:9980,y2UBqwPPzaLxsniy8R6A'); // 正确GitLab数据 system("./ztest init"); diff --git a/test/model/gitlab/update.php b/test/model/gitlab/update.php index 4006e3466d..7d3517c934 100644 --- a/test/model/gitlab/update.php +++ b/test/model/gitlab/update.php @@ -22,7 +22,7 @@ $gitlabID = 3; $_POST = array(); $_POST['name'] = ''; -$_POST['url'] = 'http://10.0.1.161:51080'; +$_POST['url'] = 'http://10.0.7.242:9980'; $_POST['account'] = 'admin'; $_POST['token'] = 'y2UBqwPPzaLxsniy8R6A'; $_POST['password'] = ''; @@ -33,7 +33,7 @@ $_POST['name'] = 'Changed GitLab'; $_POST['url'] = ''; r($gitlab->update($gitlabID)) && p() && e('url'); // 服务器地址为空 -$_POST['url'] = 'http://10.0.1.161:51080'; +$_POST['url'] = 'http://10.0.7.242:9980'; r($gitlab->update($gitlabID)) && p('name') && e('Changed GitLab'); // 正确GitLab数据 system("./ztest init"); diff --git a/test/model/jenkins/create.php b/test/model/jenkins/create.php index cebc2d7076..853895bfe7 100755 --- a/test/model/jenkins/create.php +++ b/test/model/jenkins/create.php @@ -11,17 +11,13 @@ title=测试jenkinsModel->create(); cid=1 pid=1 -Jenkins名称为空 >> name -服务器地址为空 >> url -正确Jenkins数据 >> Jenkins,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d - */ $jenkins = new jenkinsTest(); $_POST = array(); $_POST['name'] = ''; -$_POST['url'] = 'http://10.0.1.161:58080'; +$_POST['url'] = 'http://10.0.7.242:9580'; $_POST['account'] = 'admin'; $_POST['token'] = '1196c85ba525a268570df9da627e3a7b2d'; $_POST['password'] = ''; @@ -32,7 +28,7 @@ $_POST['name'] = 'Jenkins'; $_POST['url'] = ''; r($jenkins->create()) && p() && e('url'); // 服务器地址为空 -$_POST['url'] = 'http://10.0.1.161:58080'; -r($jenkins->create()) && p('name,url,token') && e('Jenkins,http://10.0.1.161:58080,1196c85ba525a268570df9da627e3a7b2d'); // 正确Jenkins数据 +$_POST['url'] = 'http://10.0.7.242:9580'; +r($jenkins->create()) && p('name,url,token') && e('Jenkins,http://10.0.7.242:9580,1196c85ba525a268570df9da627e3a7b2d'); // 正确Jenkins数据 -$db->restoreDB(); \ No newline at end of file +$db->restoreDB(); diff --git a/test/model/jenkins/update.php b/test/model/jenkins/update.php index f8d0445b29..a51185f738 100755 --- a/test/model/jenkins/update.php +++ b/test/model/jenkins/update.php @@ -23,7 +23,7 @@ $jenkinsID = 3; $_POST = array(); $_POST['name'] = ''; -$_POST['url'] = 'http://10.0.1.161:58080'; +$_POST['url'] = 'http://10.0.7.242:9580'; $_POST['account'] = 'admin'; $_POST['token'] = '1196c85ba525a268570df9da627e3a7b2d'; $_POST['password'] = ''; @@ -34,7 +34,7 @@ $_POST['name'] = 'Changed Jenkins'; $_POST['url'] = ''; r($jenkins->update($jenkinsID)) && p() && e('url'); // 服务器地址为空 -$_POST['url'] = 'http://10.0.1.161:58080'; +$_POST['url'] = 'http://10.0.7.242:9580'; r($jenkins->update($jenkinsID)) && p('name') && e('Changed Jenkins'); // 正确Jenkins数据 -$db->restoreDB(); \ No newline at end of file +$db->restoreDB();