Initial YakPanel commit
This commit is contained in:
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