Simple tests for Connections, SiteManager delete test, ZeroName updater allow domain names starting with numbers, check subdomains validity
This commit is contained in:
parent
54c367cac8
commit
891c5cc34a
5 changed files with 57 additions and 4 deletions
|
@ -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))
|
||||
|
|
31
src/Test/TestConnection.py
Normal file
31
src/Test/TestConnection.py
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
Loading…
Reference in a new issue