Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ssl testcase and option for -t #202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def update_ip(ip_type, cache, dns, proxy_list):
# 如果更新失败删除缓存
cache[ipname] = update_fail and address

def runtest():
import test,sys
test.main()
sys.exit()

def main():
"""
Expand All @@ -162,7 +166,11 @@ def main():
action='version', version=__version__)
parser.add_argument('-c', '--config',
default="config.json", help="run with config file [配置文件路径]")
config_file = parser.parse_args().config
parser.add_argument('-t', '--test', action="store_true", help="run unittest and exit")
args = parser.parse_args()
if args.test:
runtest()
config_file = args.config
get_config(path=config_file)
# Dynamicly import the dns module as configuration
dns_provider = str(get_config('dns', 'dnspod').lower())
Expand Down
80 changes: 80 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import unittest

class TestSSL(unittest.TestCase):
"""Test ssl connect"""
def connect(self,domain):
try:
# python 2
from httplib import HTTPSConnection
except ImportError:
# python 3
from http.client import HTTPSConnection
conn = HTTPSConnection(domain)
try:
conn.request("POST", "/")
except:
self.assertTrue(False)
response = conn.getresponse()
res = response.read().decode('utf8')
conn.close()

def test_dnspod(self):
from dns import dnspod
self.connect(dnspod.API.SITE)

def test_dnspod_com(self):
from dns import dnspod_com as dnspod
self.connect(dnspod.API.SITE)

def test_alidns(self):
from dns import alidns
self.connect(alidns.API.SITE)

def test_cloudflare(self):
from dns import cloudflare
self.connect(cloudflare.API.SITE)

def test_dnscom(self):
from dns import dnscom
self.connect(dnscom.API.SITE)

def test_he(self):
from dns import he
self.connect(he.API.SITE)

def test_huaweidns(self):
from dns import huaweidns
self.connect(huaweidns.API.SITE)

def test_public_v4(self):
"""test public_v4"""
from util import ip
result=ip.public_v4()
self.assertIsNotNone(result)
self.assertIsInstance(result, str)
self.assertTrue(len(result)>7)
#def test_dnspod(self):
# """test dnspod"""
# from dns import dnspod
# dnspod.Config.ID='13490'
# dnspod.Config.TOKEN='6b5976c68aba5b14a0558b77c17c3932'
# result=dnspod.request('Info.Version')
# self.assertTrue(result["status"]["code"]=="1")
#def test_dnspod_com(self):
# """test dnspod.com. notoken always fail"""
# from dns import dnspod_com as dnspod
# try:
# dnspod.request('Info.Version')
# except Exception as e:
# self.assertTrue(eval(str(e))["code"]=="-1")

def main():
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSSL))
runner = unittest.TextTestRunner()
runner.run(suite)
if __name__ == '__main__':
main()