Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
This commit is contained in:
parent
c9578e9037
commit
e9d2cdfd37
99 changed files with 9476 additions and 267 deletions
|
@ -79,6 +79,8 @@ class TestConnection:
|
|||
|
||||
def testFloodProtection(self, file_server):
|
||||
file_server.ip_incoming = {} # Reset flood protection
|
||||
whitelist = file_server.whitelist # Save for reset
|
||||
file_server.whitelist = [] # Disable 127.0.0.1 whitelist
|
||||
client = ConnectionServer("127.0.0.1", 1545)
|
||||
|
||||
# Only allow 3 connection in 1 minute
|
||||
|
@ -98,3 +100,6 @@ class TestConnection:
|
|||
with pytest.raises(gevent.Timeout):
|
||||
with gevent.Timeout(0.1):
|
||||
connection = client.getConnection("127.0.0.1", 1544)
|
||||
|
||||
# Reset whitelist
|
||||
file_server.whitelist = whitelist
|
||||
|
|
|
@ -112,6 +112,9 @@ class TestDb:
|
|||
assert db.execute("SELECT COUNT(*) AS num FROM test WHERE ?", {"test_id": [1,2,3], "title": "Test #2"}).fetchone()["num"] == 1
|
||||
assert db.execute("SELECT COUNT(*) AS num FROM test WHERE ?", {"test_id": [1,2,3], "title": ["Test #2", "Test #3", "Test #4"]}).fetchone()["num"] == 2
|
||||
|
||||
# Test named parameter escaping
|
||||
assert db.execute("SELECT COUNT(*) AS num FROM test WHERE test_id = :test_id AND title LIKE :titlelike", {"test_id": 1, "titlelike": "Test%"}).fetchone()["num"] == 1
|
||||
|
||||
db.close()
|
||||
|
||||
# Cleanup
|
||||
|
|
|
@ -18,7 +18,7 @@ class TestHelper:
|
|||
with pytest.raises(socket.error):
|
||||
helper.packAddress("999.1.1.1", 1)
|
||||
|
||||
with pytest.raises(socket.error):
|
||||
with pytest.raises(AssertionError):
|
||||
helper.unpackAddress("X")
|
||||
|
||||
def testGetDirname(self):
|
||||
|
|
107
src/Test/TestTor.py
Normal file
107
src/Test/TestTor.py
Normal file
|
@ -0,0 +1,107 @@
|
|||
import pytest
|
||||
import time
|
||||
|
||||
from File import FileServer
|
||||
from Crypt import CryptRsa
|
||||
|
||||
@pytest.mark.usefixtures("resetSettings")
|
||||
@pytest.mark.usefixtures("resetTempSettings")
|
||||
class TestTor:
|
||||
def testDownload(self, tor_manager):
|
||||
for retry in range(15):
|
||||
time.sleep(1)
|
||||
if tor_manager.enabled and tor_manager.conn:
|
||||
break
|
||||
assert tor_manager.enabled
|
||||
|
||||
def testManagerConnection(self, tor_manager):
|
||||
assert "250-version" in tor_manager.request("GETINFO version")
|
||||
|
||||
def testAddOnion(self, tor_manager):
|
||||
# Add
|
||||
address = tor_manager.addOnion()
|
||||
assert address
|
||||
assert address in tor_manager.privatekeys
|
||||
|
||||
# Delete
|
||||
assert tor_manager.delOnion(address)
|
||||
assert address not in tor_manager.privatekeys
|
||||
|
||||
def testSignOnion(self, tor_manager):
|
||||
address = tor_manager.addOnion()
|
||||
|
||||
# Sign
|
||||
sign = CryptRsa.sign("hello", tor_manager.getPrivatekey(address))
|
||||
assert len(sign) == 128
|
||||
|
||||
# Verify
|
||||
publickey = CryptRsa.privatekeyToPublickey(tor_manager.getPrivatekey(address))
|
||||
assert len(publickey) == 140
|
||||
assert CryptRsa.verify("hello", publickey, sign)
|
||||
assert not CryptRsa.verify("not hello", publickey, sign)
|
||||
|
||||
# Pub to address
|
||||
assert CryptRsa.publickeyToOnion(publickey) == address
|
||||
|
||||
# Delete
|
||||
tor_manager.delOnion(address)
|
||||
|
||||
@pytest.mark.skipif(not pytest.config.getvalue("slow"), reason="--slow not requested (takes around ~ 1min)")
|
||||
def testConnection(self, tor_manager, file_server, site, site_temp):
|
||||
file_server.tor_manager.start_onions = True
|
||||
address = file_server.tor_manager.getOnion(site.address)
|
||||
assert address
|
||||
print "Connecting to", address
|
||||
for retry in range(5): # Wait for hidden service creation
|
||||
time.sleep(10)
|
||||
try:
|
||||
connection = file_server.getConnection(address+".onion", 1544)
|
||||
if connection:
|
||||
break
|
||||
except Exception, err:
|
||||
continue
|
||||
assert connection.handshake
|
||||
assert not connection.handshake["peer_id"] # No peer_id for Tor connections
|
||||
|
||||
# Return the same connection without site specified
|
||||
assert file_server.getConnection(address+".onion", 1544) == connection
|
||||
# No reuse for different site
|
||||
assert file_server.getConnection(address+".onion", 1544, site=site) != connection
|
||||
assert file_server.getConnection(address+".onion", 1544, site=site) == file_server.getConnection(address+".onion", 1544, site=site)
|
||||
site_temp.address = "1OTHERSITE"
|
||||
assert file_server.getConnection(address+".onion", 1544, site=site) != file_server.getConnection(address+".onion", 1544, site=site_temp)
|
||||
|
||||
# Only allow to query from the locked site
|
||||
file_server.sites[site.address] = site
|
||||
connection_locked = file_server.getConnection(address+".onion", 1544, site=site)
|
||||
assert "body" in connection_locked.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 0})
|
||||
assert connection_locked.request("getFile", {"site": "1OTHERSITE", "inner_path": "content.json", "location": 0})["error"] == "Invalid site"
|
||||
|
||||
def testPex(self, file_server, site, site_temp):
|
||||
# Register site to currently running fileserver
|
||||
site.connection_server = file_server
|
||||
file_server.sites[site.address] = site
|
||||
# Create a new file server to emulate new peer connecting to our peer
|
||||
file_server_temp = FileServer("127.0.0.1", 1545)
|
||||
site_temp.connection_server = file_server_temp
|
||||
file_server_temp.sites[site_temp.address] = site_temp
|
||||
# We will request peers from this
|
||||
peer_source = site_temp.addPeer("127.0.0.1", 1544)
|
||||
|
||||
# Get ip4 peers from source site
|
||||
assert peer_source.pex(need_num=10) == 1 # Need >5 to return also return non-connected peers
|
||||
assert len(site_temp.peers) == 2 # Me, and the other peer
|
||||
site.addPeer("1.2.3.4", 1555) # Add peer to source site
|
||||
assert peer_source.pex(need_num=10) == 1
|
||||
assert len(site_temp.peers) == 3
|
||||
assert "1.2.3.4:1555" in site_temp.peers
|
||||
|
||||
# Get onion peers from source site
|
||||
site.addPeer("bka4ht2bzxchy44r.onion", 1555)
|
||||
assert "bka4ht2bzxchy44r.onion:1555" not in site_temp.peers
|
||||
assert peer_source.pex(need_num=10) == 1 # Need >5 to return also return non-connected peers
|
||||
assert "bka4ht2bzxchy44r.onion:1555" in site_temp.peers
|
||||
|
||||
def testSiteOnion(self, tor_manager):
|
||||
assert tor_manager.getOnion("address1") != tor_manager.getOnion("address2")
|
||||
assert tor_manager.getOnion("address1") == tor_manager.getOnion("address1")
|
|
@ -8,6 +8,10 @@ import json
|
|||
import pytest
|
||||
import mock
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--slow", action='store_true', default=False, help="Also run slow tests")
|
||||
|
||||
# Config
|
||||
if sys.platform == "win32":
|
||||
PHANTOMJS_PATH = "tools/phantomjs/bin/phantomjs.exe"
|
||||
|
@ -15,29 +19,31 @@ else:
|
|||
PHANTOMJS_PATH = "phantomjs"
|
||||
SITE_URL = "http://127.0.0.1:43110"
|
||||
|
||||
# Imports relative to src dir
|
||||
sys.path.append(
|
||||
os.path.abspath(os.path.dirname(__file__) + "/..")
|
||||
)
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/../lib")) # External modules directory
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/..")) # Imports relative to src dir
|
||||
|
||||
from Config import config
|
||||
config.argv = ["none"] # Dont pass any argv to config parser
|
||||
config.parse()
|
||||
config.data_dir = "src/Test/testdata" # Use test data for unittests
|
||||
config.debug_socket = True # Use test data for unittests
|
||||
config.tor = "disabled" # Don't start Tor client
|
||||
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
||||
|
||||
from Plugin import PluginManager
|
||||
PluginManager.plugin_manager.loadPlugins()
|
||||
|
||||
import gevent
|
||||
from gevent import monkey
|
||||
monkey.patch_all(thread=False)
|
||||
|
||||
from Site import Site
|
||||
from User import UserManager
|
||||
from File import FileServer
|
||||
from Connection import ConnectionServer
|
||||
from Crypt import CryptConnection
|
||||
from Ui import UiWebsocket
|
||||
import gevent
|
||||
from gevent import monkey
|
||||
monkey.patch_all(thread=False)
|
||||
from Tor import TorManager
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
@ -128,7 +134,6 @@ def site_url():
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def file_server(request):
|
||||
CryptConnection.manager.loadCerts() # Load and create certs
|
||||
request.addfinalizer(CryptConnection.manager.removeCerts) # Remove cert files after end
|
||||
file_server = FileServer("127.0.0.1", 1544)
|
||||
gevent.spawn(lambda: ConnectionServer.start(file_server))
|
||||
|
@ -160,3 +165,14 @@ def ui_websocket(site, file_server, user):
|
|||
|
||||
ui_websocket.testAction = testAction
|
||||
return ui_websocket
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def tor_manager():
|
||||
try:
|
||||
tor_manager = TorManager()
|
||||
tor_manager.connect()
|
||||
tor_manager.startOnions()
|
||||
except Exception, err:
|
||||
raise pytest.skip("Test requires Tor with ControlPort: %s, %s" % (config.tor_controller, err))
|
||||
return tor_manager
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue