diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py index 170ab2b2..591e9bff 100644 --- a/plugins/Zeroname/updater/zeroname_updater.py +++ b/plugins/Zeroname/updater/zeroname_updater.py @@ -29,7 +29,7 @@ def processNameOp(domain, value): if not isinstance(data["zeronet"], dict): print "Not dict: ", data["zeronet"] return False - if not re.match("^[a-z]([a-z0-9-]{0,62}[a-z0-9])?$", domain): + if not re.match("^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$", domain): print "Invalid domain: ", domain return False @@ -45,7 +45,10 @@ def processNameOp(domain, value): address = re.sub("[^A-Za-z0-9]", "", address) print subdomain, domain, "->", address if subdomain: - names["%s.%s.bit" % (subdomain, domain)] = address + if re.match("^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$", subdomain): + names["%s.%s.bit" % (subdomain, domain)] = address + else: + print "Invalid subdomain:", domain, subdomain else: names["%s.bit" % domain] = address @@ -153,4 +156,4 @@ while 1: processBlock(block_id) config["lastprocessed"] = last_block - open(config_path, "w").write(json.dumps(config, indent=2)) + open(config_path, "w").write(json.dumps(config, indent=1)) diff --git a/src/Test/TestConnection.py b/src/Test/TestConnection.py new file mode 100644 index 00000000..bdce6d09 --- /dev/null +++ b/src/Test/TestConnection.py @@ -0,0 +1,31 @@ +import time + +from Crypt import CryptConnection + +class TestConnection: + def testSslConnection(self, connection_server): + server = connection_server + assert server.running + + # Connect to myself + connection = server.getConnection("127.0.0.1", 1544) + assert connection.handshake + assert connection.crypt + + # Close connection + connection.close() + time.sleep(0.01) + assert len(server.connections) == 0 + + def testRawConnection(self, connection_server): + server = connection_server + crypt_supported_bk = CryptConnection.manager.crypt_supported + CryptConnection.manager.crypt_supported = [] + + connection = server.getConnection("127.0.0.1", 1544) + assert not connection.crypt + + # Close connection + connection.close() + time.sleep(0.01) + assert len(server.connections) == 0 diff --git a/src/Test/TestSite.py b/src/Test/TestSite.py index ffa951e9..5aa14069 100644 --- a/src/Test/TestSite.py +++ b/src/Test/TestSite.py @@ -2,6 +2,7 @@ import shutil import os import pytest +from Site import SiteManager @pytest.mark.usefixtures("resetSettings") @@ -56,3 +57,8 @@ class TestSite: # Delete created files new_site.storage.deleteFiles() assert not os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL") + + # Delete from site registry + assert new_site.address in SiteManager.site_manager.sites + SiteManager.site_manager.delete(new_site.address) + assert new_site.address not in SiteManager.site_manager.sites diff --git a/src/Test/conftest.py b/src/Test/conftest.py index 3e7f5b4a..5d80f9a7 100644 --- a/src/Test/conftest.py +++ b/src/Test/conftest.py @@ -1,6 +1,7 @@ import os import sys import urllib +import time import pytest @@ -22,6 +23,11 @@ config.data_dir = "src/Test/testdata" # Use test data for unittests from Site import Site from User import UserManager +from Connection import ConnectionServer +from Crypt import CryptConnection +import gevent +from gevent import monkey +monkey.patch_all(thread=False) @pytest.fixture(scope="session") def resetSettings(request): @@ -70,3 +76,10 @@ def site_url(): except Exception, err: raise pytest.skip("Test requires zeronet client running: %s" % err) return SITE_URL + +@pytest.fixture(scope="session") +def connection_server(): + connection_server = ConnectionServer("127.0.0.1", 1544) + gevent.spawn(connection_server.start) + time.sleep(0) # Port opening + return connection_server diff --git a/src/Test/pytest.ini b/src/Test/pytest.ini index 081cf778..d09210d1 100644 --- a/src/Test/pytest.ini +++ b/src/Test/pytest.ini @@ -1,5 +1,5 @@ [pytest] python_files = Test*.py -addopts = -rsxX -v +addopts = -rsxX -v --durations=6 markers = webtest: mark a test as a webtest. \ No newline at end of file