Initial YakPanel commit
This commit is contained in:
0
mod/test/__init__.py
Normal file
0
mod/test/__init__.py
Normal file
92
mod/test/docker/routetestModTest.py
Normal file
92
mod/test/docker/routetestModTest.py
Normal file
@@ -0,0 +1,92 @@
|
||||
# coding: utf-8
|
||||
# -------------------------------------------------------------------
|
||||
# yakpanel
|
||||
# -------------------------------------------------------------------
|
||||
# Copyright (c) 2015-2099 yakpanel(http://www.yakpanel.com) All rights reserved.
|
||||
# -------------------------------------------------------------------
|
||||
# Author: wzz <wzz@yakpanel.com>
|
||||
# -------------------------------------------------------------------
|
||||
# ------------------------------
|
||||
# Docker模型测试模块 - 容器模型
|
||||
# ------------------------------
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, '/www/server/panel')
|
||||
|
||||
from mod.project.docker.routetestMod import main as routetest_main
|
||||
|
||||
routetest = routetest_main()
|
||||
|
||||
|
||||
#
|
||||
class TestContainerModel(unittest.TestCase):
|
||||
"""
|
||||
创建测试用例
|
||||
"""
|
||||
|
||||
def test_returnResult(self):
|
||||
"""
|
||||
测试模型测试方法,检测返回结果是否为json格式数据
|
||||
@return:
|
||||
"""
|
||||
result = routetest.returnResult({'data': {}})
|
||||
self.assertIsInstance(result, dict)
|
||||
self.assertIn('status', result)
|
||||
self.assertIn('msg', result)
|
||||
self.assertIn('data', result)
|
||||
self.assertIn('code', result)
|
||||
self.assertIn('timestamp', result)
|
||||
|
||||
def test_wsRequest(self):
|
||||
"""
|
||||
使用ws长链请求ws://127.0.0.1:8888/ws_mod
|
||||
并发送{"mod_name":"docker","sub_mod_name":"routetest","def_name":"wsRequest","ws_callback":"111"},检测返回结果是否为True
|
||||
|
||||
备注:请将__init__.py中ws模型路由的comReturn和csrf检查注释掉再测试
|
||||
@param get:
|
||||
{"mod_name":"docker","sub_mod_name":"routetest","def_name":"wsRequest","ws_callback":"111"}
|
||||
{"mod_name":"模型名称","sub_mod_name":"子模块名称","def_name":"函数名称","ws_callback":"ws必传参数,传111",其他参数接后面}
|
||||
@return:
|
||||
"""
|
||||
import json
|
||||
import time
|
||||
from websocket import create_connection
|
||||
ws = create_connection("ws://127.0.0.1:8888/ws_mod")
|
||||
print("连接状态:", ws.connected)
|
||||
|
||||
params = {"mod_name": "docker", "sub_mod_name": "routetest", "def_name": "wsRequest", "ws_callback": "111"}
|
||||
ws.send(json.dumps(params))
|
||||
|
||||
while True:
|
||||
result = ws.recv()
|
||||
print("接收到结果:", result.strip())
|
||||
|
||||
try:
|
||||
result_data = json.loads(result)
|
||||
if "result" in result_data and "callback" in result_data:
|
||||
if result_data["result"] == True and result_data["callback"] == "111":
|
||||
print("websocket测试成功!")
|
||||
break
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
# 等待一段时间再继续接收消息
|
||||
time.sleep(0.1)
|
||||
|
||||
ws.close()
|
||||
self.assertIn('result', result)
|
||||
self.assertIn('callback', result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# unittest.main()
|
||||
# 创建测试套件
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(TestContainerModel('test_returnResult'))
|
||||
suite.addTest(TestContainerModel('test_wsRequest'))
|
||||
|
||||
# 创建测试运行器
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(suite)
|
||||
0
mod/test/java/__init__.py
Normal file
0
mod/test/java/__init__.py
Normal file
46
mod/test/java/test_spring_config.py
Normal file
46
mod/test/java/test_spring_config.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
|
||||
from mod.project.java.springboot_parser import SpringConfigParser, SpringLogConfigParser
|
||||
|
||||
|
||||
class TestSpringConfigParser(unittest.TestCase):
|
||||
|
||||
# def test_parser_config(self):
|
||||
# file = "/www/java_mall/yami-shop-admin-0.0.1-SNAPSHOT.jar"
|
||||
# # file = "/www/lilishop/lili-shop-error_jar.jar"
|
||||
# # file = "/www/wwwroot/111_java/demo.jar"
|
||||
# # file = "/www/wwwroot/33_java/tduck-api.jar"
|
||||
# # file = "/www/java_mall/yami-shop-api-0.0.1-SNAPSHOT.jar"
|
||||
#
|
||||
# scp = SpringConfigParser(file)
|
||||
# print(scp.get_tip())
|
||||
#
|
||||
# def test_shell_env(self):
|
||||
# SpringConfigParser.get_env_file_data("/www/wwwroot/33_java/test.sh")
|
||||
|
||||
def test_parser_log_config(self):
|
||||
# file = "/www/java_mall/yami-shop-admin-0.0.1-SNAPSHOT.jar"
|
||||
# file = "/www/lilishop/run_api/buyer-api-4.3.jar"
|
||||
# file = "/www/wwwroot/111_java/demo.jar"
|
||||
# file = "/www/wwwroot/33_java/tduck-api.jar"
|
||||
file = "/www/wwwroot/55_MCMS_java/ms-mcms.jar"
|
||||
# file = "/www/java_mall/yami-shop-api-0.0.1-SNAPSHOT.jar"
|
||||
|
||||
if not os.path.exists(file):
|
||||
print("file does not exist")
|
||||
scp = SpringLogConfigParser(file)
|
||||
print(scp.get_all_log_ptah())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
46
mod/test/java/test_sprintboot_mod.py
Normal file
46
mod/test/java/test_sprintboot_mod.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.project.java.projectMod import main as springboot_main
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
from mod.project.java import utils
|
||||
|
||||
|
||||
class TestSpringBootConfig(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.springboot = springboot_main()
|
||||
|
||||
# def test_process_for_create(self):
|
||||
# get = GET_CLASS()
|
||||
# get.is_java_process = ''
|
||||
# get.search = 'ja'
|
||||
# data = self.springboot.process_for_create(get)
|
||||
# print(data)
|
||||
#
|
||||
# def test_process_info_for_create(self):
|
||||
# get = GET_CLASS()
|
||||
# get.pid = "15701"
|
||||
# data = self.springboot.process_info_for_create(get)
|
||||
# print(data)
|
||||
|
||||
# def test_create_port(self):
|
||||
# t = time.time()
|
||||
# print(t)
|
||||
# print(utils.create_a_not_used_port())
|
||||
# print(time.time() - t)
|
||||
|
||||
def test_get_jar_war_config(self):
|
||||
file = "/www/wwwroot/33_java/tduck-api.jar"
|
||||
data = utils.get_jar_war_config(file)
|
||||
if data:
|
||||
data = utils.to_utf8(data)
|
||||
print(data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
126
mod/test/java/test_util.py
Normal file
126
mod/test/java/test_util.py
Normal file
@@ -0,0 +1,126 @@
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
import zipfile
|
||||
import sys
|
||||
from unittest.mock import patch, MagicMock
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.append("/www/server/panel")
|
||||
|
||||
from mod.project.java.utils import get_jar_war_config, to_utf8, parse_application_yaml, TomCat
|
||||
|
||||
|
||||
class TestJarWarConfig(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# 创建测试用的zip文件
|
||||
self.test_jar = tempfile.NamedTemporaryFile(delete=False)
|
||||
self.test_jar_name = self.test_jar.name
|
||||
self.test_jar.close()
|
||||
|
||||
# 创建一个包含application.yaml的zip文件
|
||||
with zipfile.ZipFile(self.test_jar_name, 'w') as jar:
|
||||
jar.writestr('application.yaml', 'spring:\n datasource:\n url: jdbc:mysql://localhost:3306/testdb')
|
||||
|
||||
# 创建一个不包含application.yaml的zip文件
|
||||
self.test_jar_no_config = tempfile.NamedTemporaryFile(delete=False)
|
||||
self.test_jar_no_config_name = self.test_jar_no_config.name
|
||||
self.test_jar_no_config.close()
|
||||
|
||||
with zipfile.ZipFile(self.test_jar_no_config_name, 'w') as jar:
|
||||
jar.writestr('README.txt', 'This is a test JAR without configuration')
|
||||
|
||||
# 创建一个非zip文件
|
||||
self.test_non_zip = tempfile.NamedTemporaryFile(delete=False)
|
||||
self.test_non_zip_name = self.test_non_zip.name
|
||||
self.test_non_zip.close()
|
||||
|
||||
# 创建一个不存在的文件路径
|
||||
self.test_non_existent = 'non_existent.jar'
|
||||
|
||||
def tearDown(self):
|
||||
# 删除测试文件
|
||||
os.unlink(self.test_jar_name)
|
||||
os.unlink(self.test_jar_no_config_name)
|
||||
os.unlink(self.test_non_zip_name)
|
||||
|
||||
def test_get_jar_war_config_with_valid_jar(self):
|
||||
# 测试有效的JAR文件
|
||||
result = get_jar_war_config(self.test_jar_name)
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assertIn('application.yaml', result[0][0])
|
||||
|
||||
def test_get_jar_war_config_with_no_config(self):
|
||||
# 测试没有配置文件的JAR
|
||||
result = get_jar_war_config(self.test_jar_no_config_name)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_get_jar_war_config_with_non_zip(self):
|
||||
# 测试非ZIP文件
|
||||
result = get_jar_war_config(self.test_non_zip_name)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_get_jar_war_config_with_non_existent(self):
|
||||
# 测试不存在的文件
|
||||
result = get_jar_war_config(self.test_non_existent)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_to_utf8(self):
|
||||
# 测试转换为UTF-8
|
||||
byte_data = 'test'.encode('utf-8')
|
||||
file_data_list = [('test.txt', byte_data)]
|
||||
result = to_utf8(file_data_list)
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(result, [('test.txt', 'test')])
|
||||
|
||||
def test_parse_application_yaml_valid(self):
|
||||
# 测试有效的YAML配置
|
||||
byte_data = 'spring:\n datasource:\n url: jdbc:mysql://localhost:3306/testdb'
|
||||
file_data_list = [('application.yaml', byte_data.encode('utf-8'))]
|
||||
result = parse_application_yaml(file_data_list)
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(len(result), 1)
|
||||
self.assertIn('application.yaml', result[0][0])
|
||||
self.assertIsInstance(result[0][1], dict)
|
||||
self.assertEqual(result[0][1]['spring']['datasource']['url'], 'jdbc:mysql://localhost:3306/testdb')
|
||||
|
||||
def test_parse_application_yaml_invalid(self):
|
||||
# 测试无效的YAML配置
|
||||
invalid_byte_data = 'not --- a valid yaml'
|
||||
file_data_list = [('application.yaml', invalid_byte_data.encode('utf-8'))]
|
||||
result = parse_application_yaml(file_data_list)
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(len(result), 0)
|
||||
|
||||
|
||||
class TestTomCat(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tomcat_path = "/usr/local/bttomcat/tomcat10"
|
||||
self.tomcat = TomCat(self.tomcat_path)
|
||||
|
||||
def test_jdk_path(self):
|
||||
self.assertEqual(self.tomcat.jdk_path, "/usr/local/btjdk/jdk8")
|
||||
|
||||
def test_config_xml(self):
|
||||
self.assertIsNotNone(self.tomcat.config_xml)
|
||||
print(self.tomcat.config_xml)
|
||||
|
||||
def test_save_config_xml(self):
|
||||
self.tomcat.add_host("taaaaa", "/tmp/aaaa")
|
||||
self.tomcat.add_host("taaaaa", "/tmp/aaaa")
|
||||
self.tomcat.add_host("tbbb", "/tmp/tbbb")
|
||||
self.assertEqual(self.tomcat.save_config_xml(), True)
|
||||
with open(self.tomcat_path + "/conf/server.xml", "r") as f:
|
||||
print(f.read())
|
||||
|
||||
self.tomcat.remove_host("tbbb")
|
||||
self.assertEqual(self.tomcat.save_config_xml(), True)
|
||||
with open(self.tomcat_path + "/conf/server.xml", "r") as f:
|
||||
print(f.read())
|
||||
|
||||
def test_status(self):
|
||||
print(self.tomcat.status())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
0
mod/test/php/__init__.py
Normal file
0
mod/test/php/__init__.py
Normal file
273
mod/test/php/test_php_asyncMod.py
Normal file
273
mod/test/php/test_php_asyncMod.py
Normal file
@@ -0,0 +1,273 @@
|
||||
import unittest
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
from mod.base import RealProcess
|
||||
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
import public
|
||||
|
||||
from mod.project.php.php_asyncMod import main as php_async
|
||||
phpasync = php_async()
|
||||
|
||||
class Testmain(unittest.TestCase):
|
||||
def test_create_project(self):
|
||||
args = {
|
||||
'webname':{"domain":"test.c","domainlist":[]},
|
||||
'php_version':'74',
|
||||
'site_path':'/xiaopacai/swoole-webim-demo-master',
|
||||
'project_cmd':'php server/hsw_server.php start',
|
||||
'install_dependence':'1',
|
||||
'sql':'',
|
||||
'sql_name':'',
|
||||
'sql_user': '',
|
||||
'sql_pwd': '',
|
||||
'sql_codeing': '',
|
||||
'project_ps': '',
|
||||
'open_proxy': '',
|
||||
'project_proxy_path': '',
|
||||
'project_port': '',
|
||||
}
|
||||
# phpasync.create_project(public.to_dict_obj(args))
|
||||
|
||||
|
||||
def test_delete_site(self):
|
||||
args = {
|
||||
'webname':"test.c",
|
||||
'id':'1',
|
||||
}
|
||||
# phpasync.delete_site(public.to_dict_obj(args))
|
||||
|
||||
def test_get_project_list(self):
|
||||
res = phpasync.get_project_list(public.to_dict_obj({}))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_project_get_domain(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c'
|
||||
}
|
||||
res = phpasync.project_get_domain(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
|
||||
def test_project_remove_domain(self):
|
||||
self.fail()
|
||||
|
||||
def test_project_add_domain(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'domain':["daw.daw","ssff.cxs"]
|
||||
}
|
||||
res = phpasync.project_add_domain(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
def test_get_project_run_state(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
}
|
||||
res = phpasync.get_project_run_state(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_modify_project_run_state(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'status':'stop'
|
||||
}
|
||||
res = phpasync.modify_project_run_state(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_async_dependence_config(self):
|
||||
self.fail()
|
||||
|
||||
def test_modify_project(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'php_version':'74',
|
||||
'project_path':'/xiaopacai/swoole-webim-demo-master',
|
||||
'project_cmd':'php server/hsw_server.php start',
|
||||
'site_run_path':'/xiaopacai/swoole-webim-demo-master',
|
||||
'project_port': '',
|
||||
}
|
||||
res = phpasync.modify_project(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_get_project_log(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
}
|
||||
res = phpasync.get_project_log(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_get_config_file(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
}
|
||||
res = phpasync.get_config_file(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_upload_version(self):
|
||||
self.fail()
|
||||
|
||||
def test_get_version_list(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
}
|
||||
res = phpasync.get_version_list(public.to_dict_obj(args))
|
||||
|
||||
def test_remove_version(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'version':'1'
|
||||
}
|
||||
res = phpasync.remove_version(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_recover_version(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'version':'1'
|
||||
}
|
||||
res = phpasync.recover_version(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_now_file_backup(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'version':'2'
|
||||
}
|
||||
res = phpasync.now_file_backup(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_set_version_ps(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'version':'2',
|
||||
'ps':'test'
|
||||
}
|
||||
res = phpasync.set_version_ps(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_setup_log(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
}
|
||||
res = phpasync.get_setup_log(public.to_dict_obj(args))
|
||||
self.assertEqual(type(res), dict)
|
||||
|
||||
def test_add_crontab(self):
|
||||
pass
|
||||
|
||||
def test_get_crontab_list(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
}
|
||||
res = phpasync.get_crontab_list(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_start_task(self):
|
||||
args = {
|
||||
'id':'19',
|
||||
}
|
||||
res = phpasync.start_task(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_modify_crontab_status(self):
|
||||
args = {
|
||||
'id':'19',
|
||||
}
|
||||
res = phpasync.modify_crontab_status(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_remove_crontab(self):
|
||||
args = {
|
||||
'id':'19',
|
||||
}
|
||||
res = phpasync.remove_crontab(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_modify_crontab(self):
|
||||
pass
|
||||
|
||||
def test_get_crontab_log(self):
|
||||
args = {
|
||||
'id':'19',
|
||||
}
|
||||
res = phpasync.get_crontab_log(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_clearn_logs(self):
|
||||
args = {
|
||||
'id':'19',
|
||||
}
|
||||
res = phpasync.clearn_logs(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_group_list(self):
|
||||
res = phpasync.get_group_list(public.to_dict_obj('{}'))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_create_group(self):
|
||||
args = {
|
||||
'group_name':'test',
|
||||
}
|
||||
res = phpasync.create_group(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_remove_group(self):
|
||||
args = {
|
||||
'group_name':'test',
|
||||
}
|
||||
res = phpasync.remove_group(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_group_add_project(self):
|
||||
args = {
|
||||
'group_name':'test',
|
||||
'project_name':'sdadaw.c'
|
||||
}
|
||||
res = phpasync.group_add_project(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_group_remove_project(self):
|
||||
args = {
|
||||
'group_name':'test',
|
||||
'project_name':'sdadaw.c'
|
||||
}
|
||||
res = phpasync.group_remove_project(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_set_group_interval(self):
|
||||
args = {
|
||||
'group_name':'test',
|
||||
'interval':'15'
|
||||
}
|
||||
res = phpasync.set_group_interval(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_set_group_status(self):
|
||||
args = {
|
||||
'group_name':'test',
|
||||
'status':'1'
|
||||
}
|
||||
res = phpasync.set_group_status(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_proxy_file(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'proxyname':'test'
|
||||
}
|
||||
res = phpasync.get_proxy_file(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_save_proxy_file(self):
|
||||
args = {
|
||||
'sitename':'sdadaw.c',
|
||||
'proxyname':'test',
|
||||
'file':'test'
|
||||
}
|
||||
res = phpasync.save_proxy_file(public.to_dict_obj(args))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
0
mod/test/process/__init__.py
Normal file
0
mod/test/process/__init__.py
Normal file
4
mod/test/process/test.py
Normal file
4
mod/test/process/test.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import time
|
||||
while True:
|
||||
print("Hello, World!")
|
||||
time.sleep(1)
|
||||
105
mod/test/process/test_process.py
Normal file
105
mod/test/process/test_process.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
from mod.base import RealProcess
|
||||
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
import public
|
||||
|
||||
real_process = RealProcess()
|
||||
|
||||
|
||||
class TestRealProcess(unittest.TestCase):
|
||||
|
||||
def test_get_process_list(self):
|
||||
res = real_process.get_process_list()
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_info_by_pid(self):
|
||||
res = real_process.get_process_info_by_pid(1)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_info_by_name(self):
|
||||
res = real_process.get_process_info_by_name('system')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_info_by_exec(self):
|
||||
res = real_process.get_process_info_by_exec('/usr/sbin/sshd')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_info_by_port(self):
|
||||
res = real_process.get_process_info_by_port(22)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_info_by_ip(self):
|
||||
res = real_process.get_process_info_by_ip('192.168.168.66')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_info_by_openfile(self):
|
||||
res = real_process.get_process_info_by_openfile('/etc/passwd')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_ps(self):
|
||||
res = real_process.get_process_ps('grep')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_process_tree(self):
|
||||
res = real_process.get_process_tree(1)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
# def test_kill_pid(self):
|
||||
# try:
|
||||
# pid = real_process.get_process_info_by_exec('/www/server/panel/mod/test/process/test.py')['data'][0]['pid']
|
||||
# res = real_process.kill_pid(pid)
|
||||
# self.assertEqual(res['code'], 1)
|
||||
# except:
|
||||
# pass
|
||||
|
||||
# def test_kill_name(self):
|
||||
# try:
|
||||
# name = real_process.get_process_info_by_exec('/www/server/panel/mod/test/process/test.py')['data'][0]['name']
|
||||
# res = real_process.kill_name(name)
|
||||
# self.assertEqual(res['code'], 1)
|
||||
# except:
|
||||
# pass
|
||||
#
|
||||
# def test_kill_tree(self):
|
||||
# try:
|
||||
# pid = real_process.get_process_info_by_exec('/www/server/panel/mod/test/process/test.py')['data'][0]['pid']
|
||||
# res = real_process.kill_tree(pid)
|
||||
# self.assertEqual(res['code'], 1)
|
||||
# except:
|
||||
# pass
|
||||
#
|
||||
# def test_kill_proc_all(self):
|
||||
# pid = real_process.get_process_info_by_exec('/www/server/panel/mod/test/process/test.py')['data'][0]['pid']
|
||||
# res = real_process.kill_proc_all(pid)
|
||||
# self.assertEqual(res['code'], 1)
|
||||
#
|
||||
# def test_kill_port(self):
|
||||
# res = real_process.kill_port(22)
|
||||
# self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_add_black_ip(self):
|
||||
res = real_process.add_black_ip(['1.2.3.4'])
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_del_black_ip(self):
|
||||
res = real_process.del_black_ip(['1.2.3.4'])
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_firewall_reload(self):
|
||||
res = real_process.firewall_reload()
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_run_list(self):
|
||||
res = real_process.get_run_list()
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
69
mod/test/process/test_server.py
Normal file
69
mod/test/process/test_server.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import unittest
|
||||
import sys
|
||||
import time
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
from mod.base import RealServer
|
||||
|
||||
realserver = RealServer()
|
||||
|
||||
|
||||
class TestRealServer(unittest.TestCase):
|
||||
def test_server_admin(self):
|
||||
res = realserver.server_admin('httpd', 'stop')
|
||||
self.assertEqual(res['code'], 1)
|
||||
res = realserver.server_admin('httpd', 'start')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_server_status(self):
|
||||
res = realserver.server_status('httpd')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_add_boot(self):
|
||||
server_name = 'swwnb'
|
||||
pidfile = '/tmp/test.pl'
|
||||
start_exec = 'btpython /root/1.py'
|
||||
stop_exec = 'kill <cat /tmp/test.pl'
|
||||
res = realserver.add_boot(server_name, pidfile, start_exec, stop_exec)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_universal_server_admin(self):
|
||||
res = realserver.universal_server_admin('swwnb', 'stop')
|
||||
self.assertEqual(res['code'], 1)
|
||||
res = realserver.universal_server_admin('swwnb', 'start')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_universal_server_status(self):
|
||||
res = realserver.universal_server_status('swwnb')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_create_daemon(self):
|
||||
server_name = 'swwnb'
|
||||
pidfile = '/tmp/test.pl'
|
||||
start_exec = 'btpython /root/1.py'
|
||||
workingdirectory = '/tmp'
|
||||
res = realserver.create_daemon(server_name, pidfile, start_exec, workingdirectory)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_daemon_status(self):
|
||||
res = realserver.daemon_status('swwnb')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_del_daemon(self):
|
||||
res = realserver.del_daemon('swwnb')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
# def test_del_boot(self):
|
||||
# res = realserver.del_boot('swwnb')
|
||||
# self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_add_task(self):
|
||||
res = realserver.add_task('echo 1 > /time/111.log', int(time.time()) + 3000)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
149
mod/test/process/test_user.py
Normal file
149
mod/test/process/test_user.py
Normal file
@@ -0,0 +1,149 @@
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
from mod.base import RealUser
|
||||
|
||||
realuser = RealUser()
|
||||
|
||||
|
||||
class TestRealUser(unittest.TestCase):
|
||||
def setUp(self):
|
||||
realuser.add_user('test1', 'test1', 'test1')
|
||||
realuser.add_group('test')
|
||||
|
||||
def tearDown(self):
|
||||
realuser.remove_user('test1')
|
||||
realuser.remove_user('test')
|
||||
realuser.remove_group('test1')
|
||||
realuser.remove_group('test')
|
||||
|
||||
def test_get_user_list(self):
|
||||
print('get_user_list:')
|
||||
res = realuser.get_user_list()
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_group_list(self):
|
||||
print('get_group_list:')
|
||||
res = realuser.get_group_list()
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_add_user(self):
|
||||
print('add_user:')
|
||||
res = realuser.add_user('test', 'test', 'test')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_remove_user(self):
|
||||
print('remove_user:')
|
||||
res = realuser.remove_user('test1')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_pwd(self):
|
||||
print('edit_user_pwd:')
|
||||
res = realuser.edit_user_pwd('test1', 'test111')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_group(self):
|
||||
print('edit_user_group:')
|
||||
res = realuser.edit_user_group('test1', 'test')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_ps(self):
|
||||
print('edit_user_ps:')
|
||||
res = realuser.edit_user_ps('test1', 'test')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_status(self):
|
||||
print('edit_user_status:')
|
||||
res = realuser.edit_user_status('test1', '0')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_login_shell(self):
|
||||
print('edit_user_login_shell:')
|
||||
res = realuser.edit_user_login_shell('test1', '/bin/bash')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_home(self):
|
||||
print('edit_user_home:')
|
||||
res = realuser.edit_user_home('test1', '/home/test1')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_user_info(self):
|
||||
print('get_user_info:')
|
||||
res = realuser.get_user_info('test1')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_add_group(self):
|
||||
print('add_group:')
|
||||
res = realuser.add_group('test2')
|
||||
print(res)
|
||||
realuser.remove_group('test2')
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_remove_group(self):
|
||||
realuser.add_group('test')
|
||||
print('remove_group:')
|
||||
res = realuser.remove_group('test')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_group_name(self):
|
||||
print('edit_group_name:')
|
||||
res = realuser.edit_group_name('test', 'test5')
|
||||
print(res)
|
||||
print(realuser.remove_group('test5'))
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_group_info(self):
|
||||
print('get_group_info:')
|
||||
res = realuser.get_group_info('test1')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_group_user(self):
|
||||
print('get_group_user:')
|
||||
res = realuser.get_group_user('test1')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_get_user_group(self):
|
||||
print('get_user_group:')
|
||||
res = realuser.get_user_group('test1')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_permission(self):
|
||||
print('edit_user_permission:')
|
||||
res = realuser.edit_user_permission('test1', '777')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_group_permission(self):
|
||||
print('edit_group_permission:')
|
||||
res = realuser.edit_group_permission('test1', '777')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
def test_edit_user_name(self):
|
||||
print('edit_user_name:')
|
||||
res = realuser.edit_user_name('test1', 'test')
|
||||
print(res)
|
||||
self.assertEqual(res['code'], 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
35
mod/test/test_backup_tool.py
Normal file
35
mod/test/test_backup_tool.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from unittest import TestCase
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
|
||||
from mod.base.backup_tool import BackupTool, DB
|
||||
|
||||
|
||||
class TestBackupTool(TestCase):
|
||||
|
||||
def test_backup(self):
|
||||
src = "/www/wwwroot/aaa.test.com"
|
||||
sub_dir = "site/aaa.test.com"
|
||||
|
||||
site_info = DB("sites").where("name= ?", ("aaa.test.com", )).find()
|
||||
print(site_info)
|
||||
print(BackupTool().backup(src, sub_dir=sub_dir, sync=False, site_info=site_info))
|
||||
time.sleep(2) # 等待执行完成
|
||||
# print(BackupTool().backup(src, sub_dir=sub_dir, sync=True, site_info=site_info))
|
||||
|
||||
print(os.listdir(BackupTool().backup_path + "/" + sub_dir))
|
||||
|
||||
def runTest(self):
|
||||
self.test_backup()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestBackupTool())
|
||||
unittest.TextTestRunner().run(s)
|
||||
54
mod/test/test_database_tool.py
Normal file
54
mod/test/test_database_tool.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
import sys
|
||||
from unittest import TestCase
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
|
||||
from mod.base.database_tool import add_database
|
||||
|
||||
|
||||
class TestDataBaseTool(TestCase):
|
||||
|
||||
def test_create_data_base(self):
|
||||
mysql_data = {
|
||||
"server_id": 0,
|
||||
"database_name": "aaa",
|
||||
"db_user": "eee",
|
||||
"password": "ffff",
|
||||
"dataAccess": "ip",
|
||||
"address": "127.0.0.1",
|
||||
"codeing": "utf8mb4",
|
||||
"ps": "",
|
||||
"listen_ip": "0.0.0.0/0",
|
||||
"host": "",
|
||||
}
|
||||
print(add_database(db_type="mysql", data=mysql_data))
|
||||
|
||||
pgsql_data = {
|
||||
"server_id": 0,
|
||||
"database_name": "aaa",
|
||||
"db_user": "eee",
|
||||
"password": "ffff",
|
||||
"ps": "",
|
||||
"listen_ip": "0.0.0.0/0",
|
||||
}
|
||||
print(add_database(db_type="pgsql", data=pgsql_data))
|
||||
|
||||
mgo_data = {
|
||||
"server_id": 0,
|
||||
"database_name": "aaa",
|
||||
"ps": "",
|
||||
}
|
||||
print(add_database(db_type="mongodb", data=mgo_data))
|
||||
|
||||
def runTest(self):
|
||||
self.test_create_data_base()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestDataBaseTool())
|
||||
unittest.TextTestRunner().run(s)
|
||||
59
mod/test/test_git/test_git_tool.py
Normal file
59
mod/test/test_git/test_git_tool.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from unittest import TestCase
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.base.git_tool import GitTool, GitMager
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
|
||||
class TestGitTool(TestCase):
|
||||
def runTest(self):
|
||||
# g = GitTool(
|
||||
# project_path="/www/test/git_test",
|
||||
# git_url="https://example.com/git/demo.git",
|
||||
# user_config={
|
||||
# "name": "baozi",
|
||||
# "password": "swt258452.",
|
||||
# "email": "1191604998@qq.com",
|
||||
# }
|
||||
# )
|
||||
# g.pull("master")
|
||||
os.remove("/www/server/panel/data/site_git_config.json")
|
||||
|
||||
get = GET_CLASS()
|
||||
get.git_path = "/www/test/git_test"
|
||||
get.site_name = "git_test"
|
||||
get.url = "https://example.com/git/demo.git"
|
||||
get.config = json.dumps({
|
||||
"name": "baozi",
|
||||
"password": "swt258452.",
|
||||
"email": "1191604998@qq.com",
|
||||
})
|
||||
|
||||
gm = GitMager()
|
||||
print(gm.add_git(get))
|
||||
|
||||
get = GET_CLASS()
|
||||
get.site_name = "git_test"
|
||||
get.refresh = "1"
|
||||
print(gm.site_git_configure(get))
|
||||
|
||||
# get = GET_CLASS()
|
||||
# get.git_path = "/www/test/git_test1"
|
||||
# get.site_name = "git_test"
|
||||
# get.git_id = "git_test"
|
||||
# print(gm.modify_git(get))
|
||||
#
|
||||
# gm.git_pull("master")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestGitTool())
|
||||
unittest.TextTestRunner().run(s)
|
||||
33
mod/test/test_version_tool.py
Normal file
33
mod/test/test_version_tool.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from unittest import TestCase
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
|
||||
from mod.base.backup_tool import VersionTool
|
||||
|
||||
|
||||
class TestVersionTool(TestCase):
|
||||
|
||||
def test_backup(self):
|
||||
src = "/www/wwwroot/aaa.test.com"
|
||||
v = VersionTool()
|
||||
print(v.publish("aaa", src, "1.0.0", sync=False))
|
||||
print(v.version_list("aaa"))
|
||||
time.sleep(2) # 等待执行完成
|
||||
# print(BackupTool().backup(src, sub_dir=sub_dir, sync=True, site_info=site_info))
|
||||
v.recover('aaa', '1.0.0', src)
|
||||
|
||||
def runTest(self):
|
||||
self.test_backup()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestVersionTool())
|
||||
unittest.TextTestRunner().run(s)
|
||||
190
mod/test/test_web_conf/__init__.py
Normal file
190
mod/test/test_web_conf/__init__.py
Normal file
@@ -0,0 +1,190 @@
|
||||
import os
|
||||
import sys
|
||||
from unittest import TestCase
|
||||
|
||||
SITE_NAME_CASE = "aaa.test.com"
|
||||
SITE_PATH = "/www/wwwroot/aaa.test.com"
|
||||
SUB_SITE_PATH = SITE_PATH + "/test_run"
|
||||
if not os.path.exists(SUB_SITE_PATH):
|
||||
os.makedirs(SUB_SITE_PATH)
|
||||
VHOST_PATH = "/www/server/panel/vhost"
|
||||
PREFIX = ""
|
||||
NGINX_CONFIG_FILE = "{}/nginx/{}{}.conf".format(VHOST_PATH, PREFIX, SITE_NAME_CASE)
|
||||
APACHE_CONFIG_FILE = "{}/apache/{}{}.conf".format(VHOST_PATH, PREFIX, SITE_NAME_CASE)
|
||||
NGINX_CONFIG_CASE = r"""server
|
||||
{
|
||||
listen 80;
|
||||
server_name aaa.test.com;
|
||||
index index.php index.html index.htm default.php default.html default.htm;
|
||||
root /www/wwwroot/aaa.test.com;
|
||||
#CERT-APPLY-CHECK--START
|
||||
# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除
|
||||
include /www/server/panel/vhost/nginx/well-known/aaa.test.com.conf;
|
||||
#CERT-APPLY-CHECK--END
|
||||
|
||||
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
|
||||
#error_page 404/404.html;
|
||||
#SSL-END
|
||||
|
||||
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
|
||||
#error_page 404 /404.html;
|
||||
#error_page 502 /502.html;
|
||||
#ERROR-PAGE-END
|
||||
|
||||
#PHP-INFO-START PHP引用配置,可以注释或修改
|
||||
include enable-php-00.conf;
|
||||
#PHP-INFO-END
|
||||
|
||||
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
|
||||
include /www/server/panel/vhost/rewrite/aaa.test.com.conf;
|
||||
#REWRITE-END
|
||||
|
||||
#禁止访问的文件或目录
|
||||
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
|
||||
{
|
||||
return 404;
|
||||
}
|
||||
|
||||
#一键申请SSL证书验证目录相关设置
|
||||
location ~ \.well-known{
|
||||
allow all;
|
||||
}
|
||||
|
||||
#禁止在证书验证目录放入敏感文件
|
||||
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
|
||||
return 403;
|
||||
}
|
||||
|
||||
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
|
||||
{
|
||||
expires 30d;
|
||||
error_log /dev/null;
|
||||
access_log /dev/null;
|
||||
}
|
||||
|
||||
location ~ .*\.(js|css)?$
|
||||
{
|
||||
expires 12h;
|
||||
error_log /dev/null;
|
||||
access_log /dev/null;
|
||||
}
|
||||
access_log /www/wwwlogs/aaa.test.com.log;
|
||||
error_log /www/wwwlogs/aaa.test.com.error.log;
|
||||
}"""
|
||||
|
||||
# access_log /www/wwwlogs/aaa.test.com.log;
|
||||
|
||||
APACHE_CONFIG_CASE = r"""<VirtualHost *:80>
|
||||
ServerAdmin webmaster@example.com
|
||||
DocumentRoot "/www/wwwroot/aaa.test.com"
|
||||
ServerName 630e5c70.aaa.test.com
|
||||
ServerAlias aaa.test.com
|
||||
#errorDocument 404 /404.html
|
||||
ErrorLog "/www/wwwlogs/aaa.test.com-error_log"
|
||||
CustomLog "/www/wwwlogs/aaa.test.com-access_log" combined
|
||||
|
||||
#DENY FILES
|
||||
<Files ~ (\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)$>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</Files>
|
||||
|
||||
#PHP
|
||||
<FilesMatch \.php$>
|
||||
SetHandler "proxy:unix:/tmp/php-cgi-00.sock|fcgi://localhost"
|
||||
</FilesMatch>
|
||||
|
||||
#PATH
|
||||
<Directory "/www/wwwroot/aaa.test.com">
|
||||
SetOutputFilter DEFLATE
|
||||
Options FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
DirectoryIndex index.php index.html index.htm default.php default.html default.htm
|
||||
</Directory>
|
||||
</VirtualHost>"""
|
||||
|
||||
APACHE_PATH = "/www/server/apache"
|
||||
NGINX_PATH = "/www/server/nginx"
|
||||
|
||||
|
||||
class WebBaseTestcase(TestCase):
|
||||
|
||||
def __init__(self):
|
||||
super(WebBaseTestcase, self).__init__()
|
||||
if not os.path.isfile(NGINX_CONFIG_FILE):
|
||||
with open(NGINX_CONFIG_FILE, "w+") as f:
|
||||
f.write(NGINX_CONFIG_CASE)
|
||||
|
||||
if not os.path.isfile(APACHE_CONFIG_FILE):
|
||||
with open(APACHE_CONFIG_FILE, "w+") as f:
|
||||
f.write(APACHE_CONFIG_CASE)
|
||||
|
||||
self.site_name = SITE_NAME_CASE
|
||||
|
||||
@staticmethod
|
||||
def reset_site_config():
|
||||
with open(NGINX_CONFIG_FILE, "w+") as f:
|
||||
f.write(NGINX_CONFIG_CASE)
|
||||
|
||||
with open(APACHE_CONFIG_FILE, "w+") as f:
|
||||
f.write(APACHE_CONFIG_CASE)
|
||||
|
||||
@staticmethod
|
||||
def change_env_to_apache():
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
|
||||
import public
|
||||
|
||||
if os.path.exists(NGINX_PATH):
|
||||
public.ExecShell("/etc/init.d/nginx stop")
|
||||
os.rename(NGINX_PATH, NGINX_PATH+"_back")
|
||||
|
||||
if os.path.exists(APACHE_PATH + "_back"):
|
||||
os.rename(APACHE_PATH + "_back", APACHE_PATH)
|
||||
|
||||
@staticmethod
|
||||
def change_env_to_nginx():
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
|
||||
import public
|
||||
|
||||
if os.path.exists(APACHE_PATH):
|
||||
public.ExecShell("/etc/init.d/httpd stop")
|
||||
os.rename(APACHE_PATH, APACHE_PATH + "_back")
|
||||
|
||||
if os.path.exists(NGINX_PATH + "_back"):
|
||||
os.rename(NGINX_PATH + "_back", NGINX_PATH)
|
||||
|
||||
def check_web_server_config(self):
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
|
||||
import public
|
||||
|
||||
# nginx
|
||||
ng_error = ""
|
||||
if os.path.exists(NGINX_PATH):
|
||||
shell_str = "ulimit -n 8192; {np}/sbin/nginx -t -c {np}/conf/nginx.conf".format(np=NGINX_PATH)
|
||||
ng_result = public.ExecShell(shell_str)
|
||||
if ng_result[1].find("successful") == -1:
|
||||
ng_error = ng_result[1]
|
||||
|
||||
# apache
|
||||
ap_error = ""
|
||||
if os.path.exists(APACHE_PATH):
|
||||
shell_str = "ulimit -n 8192; {ap}/bin/apachectl -t".format(ap=APACHE_PATH)
|
||||
ap_result = public.ExecShell(shell_str)
|
||||
if ap_result[1].find("Syntax OK") == -1:
|
||||
ap_error = ap_result[1]
|
||||
|
||||
if ng_error:
|
||||
print(ng_error)
|
||||
|
||||
if ap_error:
|
||||
print(ap_error)
|
||||
|
||||
if ng_error or ap_error:
|
||||
self.fail("Failed to execute")
|
||||
119
mod/test/test_web_conf/test_access_restriction.py
Normal file
119
mod/test/test_web_conf/test_access_restriction.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import os.path
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX
|
||||
from mod.base.web_conf import AccessRestriction
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
|
||||
class TestAccessRestriction(WebBaseTestcase):
|
||||
as_obj = AccessRestriction(PREFIX)
|
||||
|
||||
def test_create_auth_dir(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.name = "fshfd"
|
||||
get.dir_path = "/"
|
||||
get.password = "ssss"
|
||||
get.username = "aaaa"
|
||||
res = self.as_obj.create_auth_dir(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
|
||||
def test_modify_auth_dir(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.name = "fshfd"
|
||||
get.dir_path = "/"
|
||||
get.password = "ssss"
|
||||
get.username = "aarrr"
|
||||
res = self.as_obj.modify_auth_dir(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
|
||||
def test_remove_auth_dir(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.name = "fshfd"
|
||||
res = self.as_obj.remove_auth_dir(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
|
||||
def test_create_file_deny(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.name = "fshfd"
|
||||
get.dir_path = "/"
|
||||
get.suffix = "[\"txt\"]"
|
||||
res = self.as_obj.create_file_deny(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
|
||||
def test_modify_file_deny(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.name = "fshfd"
|
||||
get.dir_path = "/"
|
||||
get.suffix = "[\"ffff\"]"
|
||||
res = self.as_obj.modify_file_deny(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
|
||||
def test_remove_file_deny(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.name = "fshfd"
|
||||
res = self.as_obj.remove_file_deny(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
|
||||
def test_site_access_restriction_info(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
res = self.as_obj.site_access_restriction_info(get)
|
||||
self.assertTrue(res["status"], res["msg"])
|
||||
print(res["data"])
|
||||
|
||||
def setUp(self) -> None:
|
||||
if os.path.exists("/www/server/panel/data/site_access.json"):
|
||||
os.remove("/www/server/panel/data/site_access.json")
|
||||
self.reset_site_config()
|
||||
|
||||
def runTest(self):
|
||||
# self.change_env_to_apache()
|
||||
|
||||
self.change_env_to_nginx()
|
||||
self.test_create_auth_dir()
|
||||
self.check_web_server_config()
|
||||
self.test_create_file_deny()
|
||||
self.check_web_server_config()
|
||||
self.test_modify_file_deny()
|
||||
self.check_web_server_config()
|
||||
self.test_modify_auth_dir()
|
||||
self.check_web_server_config()
|
||||
self.test_site_access_restriction_info()
|
||||
self.test_remove_auth_dir()
|
||||
self.test_remove_file_deny()
|
||||
self.check_web_server_config()
|
||||
|
||||
self.change_env_to_apache()
|
||||
self.test_create_auth_dir()
|
||||
self.check_web_server_config()
|
||||
self.test_create_file_deny()
|
||||
self.check_web_server_config()
|
||||
self.test_modify_file_deny()
|
||||
self.check_web_server_config()
|
||||
self.test_modify_auth_dir()
|
||||
self.check_web_server_config()
|
||||
self.test_site_access_restriction_info()
|
||||
self.test_remove_auth_dir()
|
||||
self.test_remove_file_deny()
|
||||
self.check_web_server_config()
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists("/www/server/panel/data/site_access.json"):
|
||||
os.remove("/www/server/panel/data/site_access.json")
|
||||
self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestAccessRestriction())
|
||||
unittest.TextTestRunner().run(s)
|
||||
68
mod/test/test_web_conf/test_config_mgr.py
Normal file
68
mod/test/test_web_conf/test_config_mgr.py
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf import ConfigMgr
|
||||
|
||||
|
||||
class TestConfigMgr(WebBaseTestcase):
|
||||
|
||||
def test_nginx_config(self):
|
||||
self.assertEqual(self.config_mgr.nginx_config(), NGINX_CONFIG_CASE, "nginx 配置文件读取错误")
|
||||
|
||||
def test_apache_config(self):
|
||||
self.assertEqual(self.config_mgr.apache_config(), APACHE_CONFIG_CASE, "apache 配置文件读取错误")
|
||||
|
||||
def test_save_nginx_config(self):
|
||||
self.config_mgr.save_nginx_config(NGINX_CONFIG_CASE + "\n\n")
|
||||
self.assertEqual(self.config_mgr.nginx_config(), NGINX_CONFIG_CASE + "\n\n", "nginx 配置文件保存错误")
|
||||
|
||||
self.assertIsInstance(self.config_mgr.save_nginx_config("hshdgajdgg"), str, "nginx 配置文件保存错误")
|
||||
|
||||
def test_save_apache_config(self):
|
||||
self.config_mgr.save_apache_config(APACHE_CONFIG_CASE + "\n\n")
|
||||
self.assertEqual(self.config_mgr.apache_config(), APACHE_CONFIG_CASE + "\n\n", "apache 配置文件保存错误")
|
||||
|
||||
self.assertIsInstance(self.config_mgr.save_apache_config("hshdgajdgg"), str, "apache 配置文件保存错误")
|
||||
|
||||
def test_history_list(self):
|
||||
print(self.config_mgr.history_list())
|
||||
|
||||
def test_history_conf(self):
|
||||
res = self.config_mgr.history_list()
|
||||
if len(res["nginx"]) > 0:
|
||||
print(self.config_mgr.history_conf(res["nginx"][0]))
|
||||
|
||||
if len(res["apache"]) > 0:
|
||||
print(self.config_mgr.history_conf(res["apache"][0]))
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
self.config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
|
||||
def runTest(self):
|
||||
self.change_env_to_nginx()
|
||||
self.test_nginx_config()
|
||||
self.test_save_nginx_config()
|
||||
self.test_history_list()
|
||||
self.test_history_conf()
|
||||
self.check_web_server_config()
|
||||
|
||||
self.change_env_to_apache()
|
||||
self.test_apache_config()
|
||||
self.test_save_apache_config()
|
||||
self.test_history_list()
|
||||
self.test_history_conf()
|
||||
self.check_web_server_config()
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestConfigMgr())
|
||||
unittest.TextTestRunner().run(s)
|
||||
66
mod/test/test_web_conf/test_default_site.py
Normal file
66
mod/test/test_web_conf/test_default_site.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX
|
||||
from mod.base.web_conf import get_default_site, set_default_site, check_default
|
||||
|
||||
|
||||
class TestDefaultSite(WebBaseTestcase):
|
||||
def test_check_default(self):
|
||||
vhost_path = "/www/server/panel/vhost"
|
||||
nginx = vhost_path + '/nginx'
|
||||
httpd = vhost_path + '/apache'
|
||||
check_default()
|
||||
self.assertTrue(os.path.exists(httpd + '/0.default.conf'))
|
||||
self.assertTrue(os.path.exists(nginx + '/0.default.conf'))
|
||||
|
||||
def test_get_default_site(self):
|
||||
self.assertEqual(get_default_site(), (self.site_name, PREFIX), "设置默认站点错误")
|
||||
|
||||
def test_set_default_site(self):
|
||||
set_default_site(site_name=self.site_name, prefix=PREFIX, domain=self.site_name)
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
vhost_path = "/www/server/panel/vhost"
|
||||
nginx = vhost_path + '/nginx'
|
||||
httpd = vhost_path + '/apache'
|
||||
|
||||
if os.path.exists(httpd + '/0.default.conf'):
|
||||
os.remove(httpd + '/0.default.conf')
|
||||
if os.path.exists(httpd + '/default.conf'):
|
||||
os.remove(httpd + '/default.conf')
|
||||
|
||||
if os.path.exists(nginx + '/0.default.conf'):
|
||||
os.remove(nginx + '/0.default.conf')
|
||||
if os.path.exists(nginx + '/default.conf'):
|
||||
os.remove(nginx + '/default.conf')
|
||||
|
||||
panel_path = "/www/server/panel"
|
||||
new_ds_file = panel_path + "/data/mod_default_site.pl"
|
||||
if os.path.exists(new_ds_file):
|
||||
os.remove(new_ds_file)
|
||||
|
||||
def runTest(self):
|
||||
self.test_check_default()
|
||||
self.test_set_default_site()
|
||||
self.test_get_default_site()
|
||||
|
||||
self.change_env_to_nginx()
|
||||
self.check_web_server_config()
|
||||
|
||||
self.change_env_to_apache()
|
||||
self.check_web_server_config()
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_site_config()
|
||||
set_default_site(None)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestDefaultSite())
|
||||
unittest.TextTestRunner().run(s)
|
||||
95
mod/test/test_web_conf/test_dir_tool.py
Normal file
95
mod/test/test_web_conf/test_dir_tool.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, SITE_PATH, SUB_SITE_PATH
|
||||
from mod.base.web_conf import DirTool
|
||||
from mod.base.web_conf.util import DB, write_file
|
||||
|
||||
|
||||
class TestDirTool(WebBaseTestcase):
|
||||
dir_tool = DirTool(PREFIX)
|
||||
|
||||
def reset_site_config(self) -> None:
|
||||
super(TestDirTool, self).reset_site_config()
|
||||
|
||||
if "/www/server/panel/class" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel/class")
|
||||
import public
|
||||
|
||||
if os.path.exists(SUB_SITE_PATH + "/.user.ini"):
|
||||
public.ExecShell("chattr -i " + SUB_SITE_PATH + "/.user.ini")
|
||||
os.remove(SUB_SITE_PATH + "/.user.ini")
|
||||
|
||||
if not os.path.exists(SITE_PATH + "/.user.ini"):
|
||||
write_file(SITE_PATH + "/.user.ini", "open_basedir=/www/wwwroot/aaa.test.com/:/tmp/")
|
||||
|
||||
site_info = DB("sites").where("name=?", (self.site_name,)).find()
|
||||
DB("sites").where("id=?", (site_info["id"],)).setField('path', SITE_PATH)
|
||||
|
||||
def test_modify_site_path(self):
|
||||
res = self.dir_tool.modify_site_path(self.site_name, SITE_PATH, SUB_SITE_PATH)
|
||||
self.assertIsNone(res, "修改路径失败")
|
||||
self.assertTrue(os.path.exists(SUB_SITE_PATH + "/.user.ini"), ".user.ini错误")
|
||||
self.assertEqual(DB("sites").where("name=?", (self.site_name,)).find()["path"], SUB_SITE_PATH, "数据库错误")
|
||||
self.reset_site_config()
|
||||
|
||||
def test_modify_site_run_path(self):
|
||||
self.dir_tool.modify_site_run_path(self.site_name, SITE_PATH, "/test_run")
|
||||
self.assertEqual(self.dir_tool.get_site_run_path(self.site_name), SUB_SITE_PATH, "修改运行目录失败")
|
||||
self.assertTrue(os.path.exists(SUB_SITE_PATH + "/.user.ini"), ".user.ini错误")
|
||||
self.reset_site_config()
|
||||
|
||||
def test_index_conf(self):
|
||||
self.assertCountEqual(self.dir_tool.get_index_conf(self.site_name),
|
||||
["index.php", "index.html", "index.htm", "default.php", "default.html", "default.htm"],
|
||||
"获取index信息错误")
|
||||
self.dir_tool.set_index_conf(self.site_name, "index.php", "default.php", "default.html", "default.htm")
|
||||
self.assertCountEqual(self.dir_tool.get_index_conf(self.site_name),
|
||||
["index.php", "default.php", "default.html", "default.htm"],
|
||||
"设置index信息错误")
|
||||
|
||||
self.reset_site_config()
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
|
||||
def runTest(self):
|
||||
# 测试改变path
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_modify_site_path()
|
||||
# self.check_web_server_config()
|
||||
#
|
||||
# self.change_env_to_apache()
|
||||
# self.test_modify_site_path()
|
||||
# self.check_web_server_config()
|
||||
|
||||
# 测试改变run_path
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_modify_site_run_path()
|
||||
# self.check_web_server_config()
|
||||
#
|
||||
# self.change_env_to_apache()
|
||||
# self.test_modify_site_run_path()
|
||||
# self.check_web_server_config()
|
||||
|
||||
self.change_env_to_nginx()
|
||||
self.test_index_conf()
|
||||
self.check_web_server_config()
|
||||
|
||||
self.change_env_to_apache()
|
||||
self.test_index_conf()
|
||||
self.check_web_server_config()
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestDirTool())
|
||||
unittest.TextTestRunner().run(s)
|
||||
1
mod/test/test_web_conf/test_dns_api.py
Normal file
1
mod/test/test_web_conf/test_dns_api.py
Normal file
@@ -0,0 +1 @@
|
||||
# dns_api 部分来自dns集中管理插件, 未做单元测试
|
||||
68
mod/test/test_web_conf/test_domain_tool.py
Normal file
68
mod/test/test_web_conf/test_domain_tool.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, SITE_PATH, SUB_SITE_PATH
|
||||
from mod.base.web_conf import normalize_domain, NginxDomainTool, ApacheDomainTool, ConfigMgr, set_default_site
|
||||
from mod.base.web_conf.util import DB, write_file, read_file
|
||||
|
||||
|
||||
class DomainToolTest(WebBaseTestcase):
|
||||
|
||||
def test_normalize_domain(self):
|
||||
res, err = normalize_domain("www.example.com", "www.example.com:2546545", "www.example.com:4545")
|
||||
self.assertCountEqual(res, [("www.example.com", "80"), ("www.example.com", "4545")])
|
||||
print(err)
|
||||
|
||||
def test_nginx_domain_tool(self):
|
||||
ngd_tool = NginxDomainTool(PREFIX)
|
||||
# 检查default_site 与 域名设置
|
||||
set_default_site(self.site_name)
|
||||
res, _ = normalize_domain("www.example.com", "www.example.com:2546545", "www.example.com:4545")
|
||||
res = ngd_tool.nginx_set_domain(self.site_name, (self.site_name, "80"), *res)
|
||||
self.assertEqual(res, None, "设置域名出错")
|
||||
|
||||
conf_mager = ConfigMgr(self.site_name, PREFIX)
|
||||
conf = conf_mager.nginx_config()
|
||||
self.assertIn("www.example.com", conf)
|
||||
self.assertIn("4545", conf)
|
||||
print(conf)
|
||||
|
||||
def test_apache_domain_tool(self):
|
||||
ngd_tool = ApacheDomainTool(PREFIX)
|
||||
|
||||
res, _ = normalize_domain("www.example.com", "www.example.com:2546545", "www.example.com:4545")
|
||||
res = ngd_tool.apache_set_domain(self.site_name, (self.site_name, "80"), *res)
|
||||
self.assertEqual(res, None, "设置域名出错")
|
||||
|
||||
conf_mager = ConfigMgr(self.site_name, PREFIX)
|
||||
conf = conf_mager.apache_config()
|
||||
self.assertIn("www.example.com", conf)
|
||||
self.assertIn("4545", conf)
|
||||
print(conf)
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
|
||||
def runTest(self):
|
||||
self.test_normalize_domain()
|
||||
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_nginx_domain_tool()
|
||||
# self.check_web_server_config()
|
||||
|
||||
self.change_env_to_apache()
|
||||
self.test_apache_domain_tool()
|
||||
self.check_web_server_config()
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(DomainToolTest())
|
||||
unittest.TextTestRunner().run(s)
|
||||
123
mod/test/test_web_conf/test_ip_restrict.py
Normal file
123
mod/test/test_web_conf/test_ip_restrict.py
Normal file
@@ -0,0 +1,123 @@
|
||||
import os.path
|
||||
import sys
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf.util import GET_CLASS, service_reload
|
||||
from mod.base.web_conf import IpRestrict, ConfigMgr
|
||||
|
||||
|
||||
class TestIpRestrict(WebBaseTestcase):
|
||||
ip_restrict = IpRestrict(PREFIX)
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
setup_path = "/www/server/panel"
|
||||
ip_restrict_conf = "{}/data/ip_restrict_data/{}{}".format(setup_path, PREFIX, self.site_name)
|
||||
if os.path.exists(ip_restrict_conf):
|
||||
os.remove(ip_restrict_conf)
|
||||
nginx_ip_restrict_conf = "{}/vhost/ip-restrict/{}{}.conf".format(setup_path, PREFIX, self.site_name)
|
||||
if os.path.exists(nginx_ip_restrict_conf):
|
||||
os.remove(nginx_ip_restrict_conf)
|
||||
|
||||
def test_black_ip_restrict(self):
|
||||
# 设置为黑名单格式
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
# black white closed
|
||||
get.set_type = "black"
|
||||
self.ip_restrict.set_ip_restrict(get)
|
||||
|
||||
# 添加黑名单信息
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.value = "192.168.168.65"
|
||||
self.ip_restrict.add_black_ip_restrict(get)
|
||||
|
||||
config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
self.assertIn("ip-restrict", config_mgr.nginx_config())
|
||||
setup_path = "/www/server/panel"
|
||||
ip_restrict_conf = "{}/data/ip_restrict_data/{}{}".format(setup_path, PREFIX, self.site_name)
|
||||
nginx_ip_restrict_conf = "{}/vhost/ip-restrict/{}{}.conf".format(setup_path, PREFIX, self.site_name)
|
||||
|
||||
self.assertTrue(os.path.exists(ip_restrict_conf))
|
||||
self.assertTrue(os.path.exists(nginx_ip_restrict_conf))
|
||||
|
||||
# 移除黑名单信息
|
||||
# get = GET_CLASS()
|
||||
# get.site_name = self.site_name
|
||||
# get.value = "192.168.168.65"
|
||||
# self.ip_restrict.remove_black_ip_restrict(get)
|
||||
|
||||
def test_white_ip_restrict(self):
|
||||
# 设置为白名单格式
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
# black white closed
|
||||
get.set_type = "white"
|
||||
self.ip_restrict.set_ip_restrict(get)
|
||||
|
||||
# 添加白名单信息
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.value = "192.168.168.65" # "192.168.168.66"
|
||||
self.ip_restrict.add_white_ip_restrict(get)
|
||||
|
||||
config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
self.assertIn("ip-restrict", config_mgr.nginx_config())
|
||||
setup_path = "/www/server/panel"
|
||||
ip_restrict_conf = "{}/data/ip_restrict_data/{}{}".format(setup_path, PREFIX, self.site_name)
|
||||
nginx_ip_restrict_conf = "{}/vhost/ip-restrict/{}{}.conf".format(setup_path, PREFIX, self.site_name)
|
||||
|
||||
self.assertTrue(os.path.exists(ip_restrict_conf))
|
||||
self.assertTrue(os.path.exists(nginx_ip_restrict_conf))
|
||||
|
||||
# 移除白名单信息
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.value = "192.168.168.65"
|
||||
self.ip_restrict.remove_white_ip_restrict(get)
|
||||
|
||||
def test_ip_restrict_conf(self):
|
||||
# 添加黑名单信息
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.value = "192.168.168.65"
|
||||
self.ip_restrict.add_black_ip_restrict(get)
|
||||
|
||||
# 设置为白单格式
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
# black white closed
|
||||
get.set_type = "white"
|
||||
self.ip_restrict.set_ip_restrict(get)
|
||||
# 添加白名单信息
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.value = "192.168.168.65" # "192.168.168.66"
|
||||
self.ip_restrict.add_white_ip_restrict(get)
|
||||
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.ip_restrict.restrict_conf(get))
|
||||
|
||||
def runTest(self):
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_black_ip_restrict()
|
||||
# self.check_web_server_config()
|
||||
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_white_ip_restrict()
|
||||
# self.check_web_server_config()
|
||||
|
||||
self.change_env_to_nginx()
|
||||
self.test_ip_restrict_conf()
|
||||
self.check_web_server_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestIpRestrict())
|
||||
unittest.TextTestRunner().run(s)
|
||||
159
mod/test/test_web_conf/test_logmanager.py
Normal file
159
mod/test/test_web_conf/test_logmanager.py
Normal file
@@ -0,0 +1,159 @@
|
||||
import json
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf import ConfigMgr, LogMgr
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
LOG_FORMAT_1 = json.dumps([
|
||||
"server_addr", "server_port", "host", "remote_addr", "remote_port", "protocol", "method", "uri",
|
||||
"status", "sent_bytes", "referer", "user_agent", "take_time"
|
||||
])
|
||||
LOG_FORMAT_2 = json.dumps([
|
||||
"server_addr", "host", "remote_addr", "remote_port", "protocol", "method", "uri",
|
||||
"status", "user_agent", "take_time"
|
||||
])
|
||||
|
||||
|
||||
class TestRealLogMgr(WebBaseTestcase):
|
||||
log_mgr = LogMgr(PREFIX)
|
||||
|
||||
def test_log_format_mager(self):
|
||||
# 查看初始
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.log_mgr.log_format_data(get))
|
||||
|
||||
# 添加 一个格式
|
||||
get = GET_CLASS()
|
||||
get.format_name = "btlog1"
|
||||
get.keys = LOG_FORMAT_1
|
||||
get.space_character = "|"
|
||||
print(self.log_mgr.add_log_format(get))
|
||||
|
||||
# 添加 第二个格式
|
||||
get = GET_CLASS()
|
||||
get.format_name = "btlog2"
|
||||
get.keys = LOG_FORMAT_2
|
||||
get.space_character = " "
|
||||
print(self.log_mgr.add_log_format(get))
|
||||
|
||||
# 修改 第二个格式
|
||||
get = GET_CLASS()
|
||||
get.format_name = "btlog2"
|
||||
get.keys = LOG_FORMAT_2
|
||||
get.space_character = "|"
|
||||
print(self.log_mgr.modify_log_format(get))
|
||||
|
||||
# 删除 第一个格式
|
||||
# get = GET_CLASS()
|
||||
# get.format_name = "btlog1"
|
||||
# print(self.log_mgr.remove_log_format(get))
|
||||
|
||||
# 查看格式
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.log_mgr.log_format_data(get))
|
||||
|
||||
def test_set_site_log_format(self):
|
||||
# 设置使用 第二个
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.format_name = "btlog2"
|
||||
print(self.log_mgr.set_site_log_format(get))
|
||||
|
||||
# 修改 第二个格式
|
||||
get = GET_CLASS()
|
||||
get.format_name = "btlog2"
|
||||
get.keys = LOG_FORMAT_2
|
||||
get.space_character = "|"
|
||||
print(self.log_mgr.modify_log_format(get))
|
||||
|
||||
# 设置使用 第一个
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.format_name = "btlog1"
|
||||
print(self.log_mgr.set_site_log_format(get))
|
||||
|
||||
# 查看格式
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.log_mgr.log_format_data(get))
|
||||
|
||||
def test_site_log_path(self):
|
||||
# 查看初始
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.log_mgr.get_site_log_path(get))
|
||||
|
||||
# 修改日志路径
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.log_path = "/www/test/logs"
|
||||
print(self.log_mgr.set_site_log_path(get))
|
||||
|
||||
def test_site_crontab_log(self):
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
get.hour = "1"
|
||||
get.minute = "1"
|
||||
get.save = "180"
|
||||
print(self.log_mgr.site_crontab_log(get))
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
self.config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
panel_path = "/www/server/panel"
|
||||
if os.path.exists("{}/data/ng_log_format.json".format(panel_path)):
|
||||
os.remove("{}/data/ng_log_format.json".format(panel_path))
|
||||
|
||||
if os.path.exists("{}/vhost/nginx/log_format".format(panel_path)):
|
||||
shutil.rmtree("{}/vhost/nginx/log_format".format(panel_path))
|
||||
|
||||
if os.path.exists("{}/data/ap_log_format.json".format(panel_path)):
|
||||
os.remove("{}/data/ap_log_format.json".format(panel_path))
|
||||
|
||||
if os.path.exists("{}/vhost/apache/log_format".format(panel_path)):
|
||||
shutil.rmtree("{}/vhost/apache/log_format".format(panel_path))
|
||||
|
||||
def runTest(self):
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_log_format_mager()
|
||||
# print("==================================")
|
||||
# self.test_set_site_log_format()
|
||||
# self.check_web_server_config()
|
||||
|
||||
# self.change_env_to_apache()
|
||||
# self.test_log_format_mager()
|
||||
# print("==================================")
|
||||
# self.test_set_site_log_format()
|
||||
# self.check_web_server_config()
|
||||
|
||||
# self.change_env_to_nginx()
|
||||
# self.log_mgr = LogMgr(PREFIX)
|
||||
# self.test_site_log_path()
|
||||
# self.check_web_server_config()
|
||||
|
||||
# self.change_env_to_apache()
|
||||
# self.log_mgr = LogMgr(PREFIX)
|
||||
# self.test_site_log_path()
|
||||
# self.check_web_server_config()
|
||||
|
||||
self.test_site_crontab_log()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestRealLogMgr())
|
||||
unittest.TextTestRunner().run(s)
|
||||
107
mod/test/test_web_conf/test_proxy.py
Normal file
107
mod/test/test_web_conf/test_proxy.py
Normal file
@@ -0,0 +1,107 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf import ConfigMgr, Proxy
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
|
||||
class TestProxy(WebBaseTestcase):
|
||||
proxy_obj = Proxy(PREFIX)
|
||||
|
||||
def test_create_project_proxy(self):
|
||||
get = GET_CLASS()
|
||||
get.proxyname = "aaa"
|
||||
get.sitename = self.site_name
|
||||
get.proxydir = "/"
|
||||
get.proxysite = "https://www.baidu.com"
|
||||
get.todomain = "www.baidu.com"
|
||||
get.type = "1"
|
||||
get.cache = "1"
|
||||
get.subfilter = '[{"sub1":"","sub2":""},{"sub1":"","sub2":""},{"sub1":"","sub2":""}]'
|
||||
get.advanced = "1"
|
||||
get.cachetime = "1"
|
||||
print(self.proxy_obj.create_proxy(get))
|
||||
|
||||
# get = GET_CLASS()
|
||||
# get.proxyname = "ggfff"
|
||||
# get.sitename = self.site_name
|
||||
# get.proxydir = "/dad"
|
||||
# get.proxysite = "https://www.baidu.com"
|
||||
# get.todomain = "www.baidu.com"
|
||||
# get.type = "1"
|
||||
# get.cache = "1"
|
||||
# get.subfilter = '[{"sub1":"","sub2":""},{"sub1":"","sub2":""},{"sub1":"","sub2":""}]'
|
||||
# get.advanced = "1"
|
||||
# get.cachetime = "1"
|
||||
# print(self.proxy_obj.create_proxy(get))
|
||||
|
||||
def test_modify_project_proxy(self):
|
||||
get = GET_CLASS()
|
||||
get.proxyname = "ggfff"
|
||||
get.sitename = self.site_name
|
||||
get.proxydir = "/dygvccc"
|
||||
get.proxysite = "https://www.baidu.com"
|
||||
get.todomain = "www.baidu.com"
|
||||
get.type = "1"
|
||||
get.cache = "1"
|
||||
get.subfilter = '[{"sub1":"","sub2":""},{"sub1":"","sub2":""},{"sub1":"","sub2":""}]'
|
||||
get.advanced = "0"
|
||||
get.cachetime = "1"
|
||||
print(self.proxy_obj.modify_proxy(get))
|
||||
|
||||
def test_remove_project_proxy(self):
|
||||
get = GET_CLASS()
|
||||
get.proxyname = "aaa"
|
||||
get.sitename = self.site_name
|
||||
print(self.proxy_obj.remove_proxy(get))
|
||||
|
||||
def test_get_project_proxy_list(self):
|
||||
get = GET_CLASS()
|
||||
get.sitename = self.site_name
|
||||
print(self.proxy_obj.get_proxy_list(get))
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
self.config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
panel_path = "/www/server/panel"
|
||||
_proxy_conf_file = "{}/data/mod_proxy_file.conf".format(panel_path)
|
||||
if os.path.exists(_proxy_conf_file):
|
||||
os.remove(_proxy_conf_file)
|
||||
|
||||
ng_proxy_dir = "/www/server/panel/vhost/nginx/proxy/" + self.site_name
|
||||
ap_proxy_dir = "/www/server/panel/vhost/apache/proxy/" + self.site_name
|
||||
if os.path.exists(ng_proxy_dir):
|
||||
shutil.rmtree(ng_proxy_dir)
|
||||
|
||||
if os.path.exists(ap_proxy_dir):
|
||||
shutil.rmtree(ap_proxy_dir)
|
||||
|
||||
def runTest(self):
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_create_project_proxy()
|
||||
# self.test_remove_project_proxy()
|
||||
# self.check_web_server_config()
|
||||
|
||||
self.change_env_to_apache()
|
||||
self.test_create_project_proxy()
|
||||
self.test_remove_project_proxy()
|
||||
self.test_modify_project_proxy()
|
||||
self.test_get_project_proxy_list()
|
||||
self.check_web_server_config()
|
||||
|
||||
# def tearDown(self):
|
||||
# self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestProxy())
|
||||
unittest.TextTestRunner().run(s)
|
||||
87
mod/test/test_web_conf/test_redirect.py
Normal file
87
mod/test/test_web_conf/test_redirect.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf import ConfigMgr, Redirect
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
|
||||
class TestRedirect(WebBaseTestcase):
|
||||
redirect = Redirect()
|
||||
|
||||
def test_create_project_redirect(self):
|
||||
get = GET_CLASS()
|
||||
get.sitename = self.site_name
|
||||
get.redirectpath = "/"
|
||||
get.redirecttype = "301"
|
||||
get.domainorpath = "path"
|
||||
get.redirectname = "aaa"
|
||||
get.tourl = ""
|
||||
get.topath = "/ashdjadg"
|
||||
get.redirectdomain = "[]"
|
||||
get.type = "1"
|
||||
get.errorpage = "0"
|
||||
get.holdpath = "1"
|
||||
print(self.redirect.create_project_redirect(get))
|
||||
|
||||
def test_modify_project_redirect(self):
|
||||
get = GET_CLASS()
|
||||
get.sitename = self.site_name
|
||||
get.redirectpath = "/"
|
||||
get.redirecttype = "301"
|
||||
get.domainorpath = "domain"
|
||||
get.redirectname = "aaa"
|
||||
get.tourl = "https://www.baidu.com"
|
||||
get.topath = ""
|
||||
get.redirectdomain = json.dumps([self.site_name])
|
||||
get.type = "1"
|
||||
get.errorpage = "0"
|
||||
get.holdpath = "1"
|
||||
print(self.redirect.modify_project_redirect(get))
|
||||
|
||||
def test_remove_project_redirect(self):
|
||||
get = GET_CLASS()
|
||||
get.sitename = self.site_name
|
||||
get.redirectname = "aaa"
|
||||
print(self.redirect.remove_project_redirect(get))
|
||||
|
||||
def test_get_project_redirect_list(self):
|
||||
get = GET_CLASS()
|
||||
get.sitename = self.site_name
|
||||
print(self.redirect.get_project_redirect_list(get))
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
self.config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
|
||||
def runTest(self):
|
||||
# self.change_env_to_nginx()
|
||||
# self.test_create_project_redirect()
|
||||
# self.test_modify_project_redirect()
|
||||
# self.test_get_project_redirect_list()
|
||||
# self.test_remove_project_redirect()
|
||||
# self.check_web_server_config()
|
||||
#
|
||||
self.change_env_to_apache()
|
||||
self.test_create_project_redirect()
|
||||
self.test_modify_project_redirect()
|
||||
self.test_get_project_redirect_list()
|
||||
self.test_remove_project_redirect()
|
||||
self.check_web_server_config()
|
||||
|
||||
# def tearDown(self):
|
||||
# pass
|
||||
# self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestRedirect())
|
||||
unittest.TextTestRunner().run(s)
|
||||
70
mod/test/test_web_conf/test_referer.py
Normal file
70
mod/test/test_web_conf/test_referer.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf import ConfigMgr, Referer
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
|
||||
class TestReferer(WebBaseTestcase):
|
||||
referer = Referer(PREFIX)
|
||||
|
||||
def test_referer_security(self):
|
||||
# 开启
|
||||
get = GET_CLASS()
|
||||
get.status = "true"
|
||||
get.http_status = "false"
|
||||
get.name = self.site_name
|
||||
get.fix = "fsf,dhjdh,uooo"
|
||||
get.domains = self.site_name + ",www.asdad.com"
|
||||
get.return_rule = "403"
|
||||
print(self.referer.set_referer_security(get))
|
||||
|
||||
# 修改
|
||||
get = GET_CLASS()
|
||||
get.status = "true"
|
||||
get.http_status = "false"
|
||||
get.name = self.site_name
|
||||
get.fix = "fsf,dhjdh,hjhlh"
|
||||
get.domains = self.site_name + ",www.asdad.com"
|
||||
get.return_rule = "404"
|
||||
print(self.referer.set_referer_security(get))
|
||||
|
||||
# 删除
|
||||
get = GET_CLASS()
|
||||
get.status = "false"
|
||||
get.http_status = "false"
|
||||
get.name = self.site_name
|
||||
get.fix = "fsf,dhjdh,hjhlh"
|
||||
get.domains = self.site_name + ",www.asdad.com"
|
||||
get.return_rule = "404"
|
||||
print(self.referer.set_referer_security(get))
|
||||
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.referer.get_referer_security(get))
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
self.config_mgr = ConfigMgr(self.site_name, PREFIX)
|
||||
|
||||
def runTest(self):
|
||||
self.change_env_to_nginx()
|
||||
self.test_referer_security()
|
||||
self.check_web_server_config()
|
||||
|
||||
# def tearDown(self):
|
||||
# pass
|
||||
# self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestReferer())
|
||||
unittest.TextTestRunner().run(s)
|
||||
63
mod/test/test_web_conf/test_ssl.py
Normal file
63
mod/test/test_web_conf/test_ssl.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
if "/www/server/panel" not in sys.path:
|
||||
sys.path.insert(0, "/www/server/panel")
|
||||
|
||||
from mod.test.test_web_conf import WebBaseTestcase, PREFIX, NGINX_CONFIG_CASE, APACHE_CONFIG_CASE
|
||||
from mod.base.web_conf import SSLManager, set_default_site
|
||||
from mod.base.web_conf.util import GET_CLASS
|
||||
|
||||
|
||||
class TestSSLManager(WebBaseTestcase):
|
||||
ssl = SSLManager(PREFIX)
|
||||
|
||||
def test_set_site_ssl_conf(self):
|
||||
# 开启
|
||||
get = GET_CLASS()
|
||||
get.ssl_id = "2" # 保证这个ID存在
|
||||
get.site_name = self.site_name
|
||||
print(self.ssl.set_site_ssl_conf(get))
|
||||
|
||||
def test_mutil_set_site_ssl_conf(self):
|
||||
# 开启
|
||||
get = GET_CLASS()
|
||||
get.ssl_id = "9" # 保证这个ID存在
|
||||
get.site_names = json.dumps([self.site_name, "www.123test.com"])
|
||||
print(self.ssl.mutil_set_site_ssl_conf(get))
|
||||
|
||||
def test_close_site_ssl_conf(self):
|
||||
# 关闭
|
||||
get = GET_CLASS()
|
||||
get.site_name = self.site_name
|
||||
print(self.ssl.close_site_ssl_conf(get))
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.reset_site_config()
|
||||
|
||||
def runTest(self):
|
||||
set_default_site(site_name=self.site_name)
|
||||
self.change_env_to_nginx()
|
||||
self.test_set_site_ssl_conf()
|
||||
self.test_mutil_set_site_ssl_conf()
|
||||
self.test_close_site_ssl_conf()
|
||||
self.check_web_server_config()
|
||||
|
||||
# self.change_env_to_apache()
|
||||
# self.test_set_site_ssl_conf()
|
||||
# self.test_mutil_set_site_ssl_conf()
|
||||
# self.test_close_site_ssl_conf()
|
||||
# self.check_web_server_config()
|
||||
|
||||
# def tearDown(self):
|
||||
# pass
|
||||
# self.reset_site_config()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
s = unittest.TestSuite()
|
||||
s.addTest(TestSSLManager())
|
||||
unittest.TextTestRunner().run(s)
|
||||
Reference in New Issue
Block a user