2015-09-20 00:27:54 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import urllib
|
2015-09-22 12:16:29 +02:00
|
|
|
import time
|
2015-09-24 22:08:08 +02:00
|
|
|
import logging
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
import json
|
2015-09-20 00:27:54 +02:00
|
|
|
|
|
|
|
import pytest
|
2015-09-24 22:08:08 +02:00
|
|
|
import mock
|
2015-09-20 00:27:54 +02:00
|
|
|
|
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
2016-01-05 00:20:52 +01:00
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption("--slow", action='store_true', default=False, help="Also run slow tests")
|
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
# Config
|
|
|
|
if sys.platform == "win32":
|
|
|
|
PHANTOMJS_PATH = "tools/phantomjs/bin/phantomjs.exe"
|
|
|
|
else:
|
|
|
|
PHANTOMJS_PATH = "phantomjs"
|
|
|
|
SITE_URL = "http://127.0.0.1:43110"
|
|
|
|
|
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
2016-01-05 00:20:52 +01:00
|
|
|
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
|
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
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
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
config.debug_socket = True # Use test data for unittests
|
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
2016-01-05 00:20:52 +01:00
|
|
|
config.tor = "disabled" # Don't start Tor client
|
2015-09-24 22:08:08 +02:00
|
|
|
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
2015-09-20 00:27:54 +02:00
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
from Plugin import PluginManager
|
|
|
|
PluginManager.plugin_manager.loadPlugins()
|
|
|
|
|
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
2016-01-05 00:20:52 +01:00
|
|
|
import gevent
|
|
|
|
from gevent import monkey
|
|
|
|
monkey.patch_all(thread=False)
|
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
from Site import Site
|
|
|
|
from User import UserManager
|
2015-09-24 22:08:08 +02:00
|
|
|
from File import FileServer
|
2015-09-22 12:16:29 +02:00
|
|
|
from Connection import ConnectionServer
|
|
|
|
from Crypt import CryptConnection
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
from Ui import UiWebsocket
|
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
2016-01-05 00:20:52 +01:00
|
|
|
from Tor import TorManager
|
2015-09-20 00:27:54 +02:00
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def resetSettings(request):
|
2015-09-24 22:08:08 +02:00
|
|
|
os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir
|
2015-09-20 00:27:54 +02:00
|
|
|
open("%s/sites.json" % config.data_dir, "w").write("{}")
|
|
|
|
open("%s/users.json" % config.data_dir, "w").write("""
|
|
|
|
{
|
|
|
|
"15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc": {
|
|
|
|
"certs": {},
|
|
|
|
"master_seed": "024bceac1105483d66585d8a60eaf20aa8c3254b0f266e0d626ddb6114e2949a",
|
|
|
|
"sites": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|
2015-09-24 22:08:08 +02:00
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
def cleanup():
|
|
|
|
os.unlink("%s/sites.json" % config.data_dir)
|
|
|
|
os.unlink("%s/users.json" % config.data_dir)
|
|
|
|
request.addfinalizer(cleanup)
|
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def resetTempSettings(request):
|
|
|
|
data_dir_temp = config.data_dir + "-temp"
|
|
|
|
if not os.path.isdir(data_dir_temp):
|
|
|
|
os.mkdir(data_dir_temp)
|
|
|
|
open("%s/sites.json" % data_dir_temp, "w").write("{}")
|
|
|
|
open("%s/users.json" % data_dir_temp, "w").write("""
|
|
|
|
{
|
|
|
|
"15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc": {
|
|
|
|
"certs": {},
|
|
|
|
"master_seed": "024bceac1105483d66585d8a60eaf20aa8c3254b0f266e0d626ddb6114e2949a",
|
|
|
|
"sites": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
|
|
|
|
def cleanup():
|
|
|
|
os.unlink("%s/sites.json" % data_dir_temp)
|
|
|
|
os.unlink("%s/users.json" % data_dir_temp)
|
|
|
|
request.addfinalizer(cleanup)
|
|
|
|
|
|
|
|
|
Rev467, requirements.txt accept newer dependecies, Boost dbschema.json, Move getDirname getFilename to helper, Verify optional files, Includes not allowed in user files, Optional files rules, Peer hashfield functions, Test optional files signing, Test file info, Test verify file, Test helpers
2015-10-01 01:35:13 +02:00
|
|
|
@pytest.fixture()
|
2015-09-20 00:27:54 +02:00
|
|
|
def site():
|
|
|
|
site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
|
|
|
|
return site
|
|
|
|
|
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
@pytest.fixture()
|
|
|
|
def site_temp(request):
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
with mock.patch("Config.config.data_dir", config.data_dir + "-temp"):
|
2015-09-24 22:08:08 +02:00
|
|
|
site_temp = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
def cleanup():
|
|
|
|
site_temp.storage.deleteFiles()
|
|
|
|
request.addfinalizer(cleanup)
|
|
|
|
return site_temp
|
|
|
|
|
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def user():
|
|
|
|
user = UserManager.user_manager.get()
|
Rev426, Fix for nonce error on bigsites asking, Dont display error details on 404 error, Dont log Websocket close errors, Add travis pip caching and osx test, Add build status to readme, Test for site files after cloning, Test for json to db mapping, Test site deleteFiles command, Test user certificate and auth address generation, Exclude debug lines from coverage, Dont run webtests every time
2015-09-20 22:35:45 +02:00
|
|
|
user.sites = {} # Reset user data
|
2015-09-20 00:27:54 +02:00
|
|
|
return user
|
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def browser():
|
|
|
|
try:
|
|
|
|
from selenium import webdriver
|
|
|
|
browser = webdriver.PhantomJS(executable_path=PHANTOMJS_PATH, service_log_path=os.path.devnull)
|
|
|
|
browser.set_window_size(1400, 1000)
|
|
|
|
except Exception, err:
|
|
|
|
raise pytest.skip("Test requires selenium + phantomjs: %s" % err)
|
|
|
|
return browser
|
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def site_url():
|
|
|
|
try:
|
|
|
|
urllib.urlopen(SITE_URL).read()
|
|
|
|
except Exception, err:
|
|
|
|
raise pytest.skip("Test requires zeronet client running: %s" % err)
|
|
|
|
return SITE_URL
|
2015-09-22 12:16:29 +02:00
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
|
2015-09-22 12:16:29 +02:00
|
|
|
@pytest.fixture(scope="session")
|
2015-09-24 22:08:08 +02:00
|
|
|
def file_server(request):
|
|
|
|
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))
|
2016-03-16 21:09:07 +01:00
|
|
|
# Wait for port opening
|
|
|
|
for retry in range(10):
|
|
|
|
time.sleep(0.1) # Port opening
|
|
|
|
try:
|
|
|
|
conn = file_server.getConnection("127.0.0.1", 1544)
|
|
|
|
conn.close()
|
|
|
|
break
|
|
|
|
except Exception, err:
|
|
|
|
print err
|
2015-09-24 22:08:08 +02:00
|
|
|
assert file_server.running
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
2015-09-28 00:22:27 +02:00
|
|
|
def stop():
|
|
|
|
file_server.stop()
|
|
|
|
request.addfinalizer(stop)
|
2015-09-24 22:08:08 +02:00
|
|
|
return file_server
|
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def ui_websocket(site, file_server, user):
|
|
|
|
class WsMock:
|
|
|
|
def __init__(self):
|
|
|
|
self.result = None
|
|
|
|
|
|
|
|
def send(self, data):
|
|
|
|
self.result = json.loads(data)["result"]
|
|
|
|
|
|
|
|
ws_mock = WsMock()
|
|
|
|
ui_websocket = UiWebsocket(ws_mock, site, file_server, user, None)
|
|
|
|
|
|
|
|
def testAction(action, *args, **kwargs):
|
|
|
|
func = getattr(ui_websocket, "action%s" % action)
|
|
|
|
func(0, *args, **kwargs)
|
|
|
|
return ui_websocket.ws.result
|
|
|
|
|
|
|
|
ui_websocket.testAction = testAction
|
|
|
|
return ui_websocket
|
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
2016-01-05 00:20:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def tor_manager():
|
|
|
|
try:
|
|
|
|
tor_manager = TorManager()
|
2016-01-05 01:19:53 +01:00
|
|
|
assert tor_manager.connect()
|
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
2016-01-05 00:20:52 +01:00
|
|
|
tor_manager.startOnions()
|
|
|
|
except Exception, err:
|
|
|
|
raise pytest.skip("Test requires Tor with ControlPort: %s, %s" % (config.tor_controller, err))
|
|
|
|
return tor_manager
|