diff --git a/domain_admin/api/cert_api.py b/domain_admin/api/cert_api.py index 3b5691b15b..911d6150ab 100644 --- a/domain_admin/api/cert_api.py +++ b/domain_admin/api/cert_api.py @@ -15,7 +15,7 @@ def get_cert_information(): domain = request.json['domain'] try: - data = cert_util_v2.get_cert_info(domain) + data = cert_util.get_cert_info(domain) except Exception as e: data = None diff --git a/domain_admin/main.py b/domain_admin/main.py index d4d6cbb739..282a1a5521 100644 --- a/domain_admin/main.py +++ b/domain_admin/main.py @@ -42,6 +42,10 @@ def teardown_request(exc): @app.get('/') def index(): + """ + 静态首页 + :return: + """ return send_file('public/index.html') diff --git a/domain_admin/service/domain_service.py b/domain_admin/service/domain_service.py index bfc5b6b964..fbd6c9d260 100644 --- a/domain_admin/service/domain_service.py +++ b/domain_admin/service/domain_service.py @@ -58,7 +58,7 @@ def update_domain_cert_info(row): info = {} try: - info = cert_util_v2.get_cert_info(row.domain) + info = cert_util.get_cert_info(row.domain) connect_status = True except Exception: pass diff --git a/domain_admin/utils/cert_util.py b/domain_admin/utils/cert_util.py index f89024ad04..69aee28ca3 100644 --- a/domain_admin/utils/cert_util.py +++ b/domain_admin/utils/cert_util.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -@File : cert_util_v2.py +@File : cert_util.py @Date : 2022-10-22 @Author : Peng Shiyu diff --git a/domain_admin/utils/domain_util.py b/domain_admin/utils/domain_util.py index 57f83dab05..94875e128b 100644 --- a/domain_admin/utils/domain_util.py +++ b/domain_admin/utils/domain_util.py @@ -8,7 +8,7 @@ def parse_domain(domain): :param domain: :return: """ - ret = re.match('.*?//([a-zA-Z\.0-9]+)/?.*?', domain) + ret = re.match('.*?//([a-zA-Z\\.0-9]+)/?.*?', domain) if ret: return ret.groups()[0] else: diff --git a/domain_admin/utils/flask_ext/flask_app.py b/domain_admin/utils/flask_ext/flask_app.py index 1c146762ee..df21d8769e 100644 --- a/domain_admin/utils/flask_ext/flask_app.py +++ b/domain_admin/utils/flask_ext/flask_app.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from collections import Iterator +from typing import Iterator from flask import Flask from peewee import ModelSelect, Model diff --git a/domain_admin/version.py b/domain_admin/version.py index 5e43de56ff..80c645aff1 100755 --- a/domain_admin/version.py +++ b/domain_admin/version.py @@ -2,4 +2,4 @@ """ 版本号 """ -VERSION = '0.0.15' +VERSION = '0.0.16' diff --git a/requirements/production.txt b/requirements/production.txt index 3a0b663b1f..1bf4f35d8f 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -1,13 +1,13 @@ -requests>=2.27.0 -Flask==2.0.0 -werkzeug>=2.2.2 +requests==2.28.1 +Flask==2.2.2 +werkzeug==2.2.2 Jinja2==3.0.0 Flask-Cors==3.0.10 peewee==3.15.3 python-dateutil==2.8.2 gunicorn==20.1.0 gevent==21.12.0 -apscheduler>=3.9.1 +apscheduler==3.9.1 PyJWT>=2.5.0 bcrypt>=4.0.0 python-dotenv>=0.21.0 diff --git a/tests/api/__init__.py b/tests/api/__init__.py new file mode 100644 index 0000000000..897472a7ae --- /dev/null +++ b/tests/api/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +""" +@File : __init__.py.py +@Date : 2022-11-05 +@Author : Peng Shiyu +""" diff --git a/tests/api/auth_api.py b/tests/api/auth_api.py new file mode 100644 index 0000000000..a333ce3255 --- /dev/null +++ b/tests/api/auth_api.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +""" +@File : auth_api.py +@Date : 2022-11-05 +@Author : Peng Shiyu +""" + + +def test_login(client): + response = client.post('/api/login', json={ + 'username': 'admin', + 'password': '123456' + }) + + assert response.json['code'] == 0 diff --git a/tests/api/test_cert.py b/tests/api/test_cert.py new file mode 100644 index 0000000000..adafaadd4f --- /dev/null +++ b/tests/api/test_cert.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +@File : test_cert.py +@Date : 2022-11-05 +@Author : Peng Shiyu +""" + + +def test_get_cert_information_not_login(client): + response = client.post('/api/getCertInformation') + assert response.json['code'] == 401 + + +def test_get_cert_information_not_params(client, token): + response = client.post( + path='/api/getCertInformation', + headers={'x-token': token} + ) + + assert response.json['code'] == -1 + + +def test_get_cert_information(client, token): + response = client.post('/api/getCertInformation', json={ + 'domain': 'www.baidu.com' + }, headers={'x-token': token}) + + assert response.json['code'] == 0 diff --git a/tests/api/test_index.py b/tests/api/test_index.py new file mode 100644 index 0000000000..0781282cae --- /dev/null +++ b/tests/api/test_index.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +""" +@File : test_demo.py +@Date : 2022-11-05 +@Author : Peng Shiyu +""" + + +def test_index(client): + response = client.get('/') + assert 'id="app"' in response.text diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000000..b9e97f94f9 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +""" +@File : conftest.py +@Date : 2022-11-05 +@Author : Peng Shiyu +""" +import pytest +from flask.testing import FlaskClient + +from domain_admin.main import app + + +@pytest.fixture() +def client() -> FlaskClient: + app.config.update({ + "TESTING": True, + }) + + with app.app_context(): + client = app.test_client() + + return client + + +@pytest.fixture() +def token(client) -> str: + response = client.post('/api/login', json={ + 'username': 'admin', + 'password': '123456' + }) + + return response.json['data']['token']