2015-09-20 00:27:54 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2019-03-15 21:06:59 +01:00
|
|
|
import urllib.request
|
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
|
2016-04-06 13:45:31 +02:00
|
|
|
import shutil
|
2016-11-07 22:43:26 +01:00
|
|
|
import gc
|
2017-10-04 13:30:17 +02:00
|
|
|
import datetime
|
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
|
|
|
|
2019-01-20 03:10:39 +01:00
|
|
|
import gevent
|
|
|
|
from gevent import monkey
|
|
|
|
monkey.patch_all(thread=False, subprocess=False)
|
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
|
|
|
|
2019-03-15 21:06:59 +01: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")
|
|
|
|
|
2019-03-15 21:06:59 +01:00
|
|
|
|
2019-01-20 20:02:31 +01:00
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
|
|
if config.getoption("--slow"):
|
|
|
|
# --runslow given in cli: do not skip slow tests
|
|
|
|
return
|
|
|
|
skip_slow = pytest.mark.skip(reason="need --slow option to run")
|
|
|
|
for item in items:
|
|
|
|
if "slow" in item.keywords:
|
|
|
|
item.add_marker(skip_slow)
|
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
# Config
|
|
|
|
if sys.platform == "win32":
|
2018-11-26 00:10:43 +01:00
|
|
|
CHROMEDRIVER_PATH = "tools/chrome/chromedriver.exe"
|
2015-09-20 00:27:54 +02:00
|
|
|
else:
|
2018-11-26 00:10:43 +01:00
|
|
|
CHROMEDRIVER_PATH = "chromedriver"
|
2015-09-20 00:27:54 +02:00
|
|
|
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
|
2016-11-07 22:42:27 +01:00
|
|
|
config.parse(silent=True) # Plugins need to access the configuration
|
2017-10-04 13:30:17 +02:00
|
|
|
config.action = "test"
|
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
2015-09-20 00:27:54 +02:00
|
|
|
|
2019-03-15 21:06:59 +01:00
|
|
|
|
2017-10-04 13:30:17 +02:00
|
|
|
# Set custom formatter with realative time format (via: https://stackoverflow.com/questions/31521859/python-logging-module-time-since-last-log)
|
|
|
|
class TimeFilter(logging.Filter):
|
|
|
|
|
|
|
|
def filter(self, record):
|
|
|
|
try:
|
2019-03-15 21:06:59 +01:00
|
|
|
last = self.last
|
2017-10-04 13:30:17 +02:00
|
|
|
except AttributeError:
|
2019-03-15 21:06:59 +01:00
|
|
|
last = record.relativeCreated
|
2017-10-04 13:30:17 +02:00
|
|
|
|
|
|
|
|
2019-03-15 21:06:59 +01:00
|
|
|
record.relative = '{0:.3f}'.format(delta.seconds + delta.microseconds / 1000000.0)
|
2017-10-04 13:30:17 +02:00
|
|
|
|
|
|
|
self.last = record.relativeCreated
|
|
|
|
return True
|
|
|
|
|
|
|
|
log = logging.getLogger()
|
|
|
|
fmt = logging.Formatter(fmt='+%(relative)ss %(levelname)-8s %(name)s %(message)s')
|
|
|
|
[hndl.addFilter(TimeFilter()) for hndl in log.handlers]
|
|
|
|
[hndl.setFormatter(fmt) for hndl in log.handlers]
|
|
|
|
|
|
|
|
# Load plugins
|
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
|
2016-03-23 13:30:18 +01:00
|
|
|
|
|
|
|
config.data_dir = "src/Test/testdata" # Use test data for unittests
|
|
|
|
|
2016-09-05 13:58:10 +02:00
|
|
|
os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir
|
|
|
|
# Cleanup content.db caches
|
|
|
|
if os.path.isfile("%s/content.db" % config.data_dir):
|
|
|
|
os.unlink("%s/content.db" % config.data_dir)
|
|
|
|
if os.path.isfile("%s-temp/content.db" % config.data_dir):
|
|
|
|
os.unlink("%s-temp/content.db" % config.data_dir)
|
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
|
|
|
|
2019-01-20 03:10:39 +01:00
|
|
|
PluginManager.plugin_manager.loadPlugins()
|
|
|
|
config.loadPlugins()
|
|
|
|
config.parse() # Parse again to add plugin configuration options
|
|
|
|
|
|
|
|
config.debug_socket = True # Use test data for unittests
|
|
|
|
config.verbose = True # Use test data for unittests
|
|
|
|
config.tor = "disable" # Don't start Tor client
|
|
|
|
config.trackers = []
|
|
|
|
config.data_dir = "src/Test/testdata" # 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
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
from Site import Site
|
2016-09-05 13:58:10 +02:00
|
|
|
from Site import SiteManager
|
2015-09-20 00:27:54 +02:00
|
|
|
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
|
2016-09-05 13:58:10 +02:00
|
|
|
from Content import ContentDb
|
|
|
|
from util import RateLimit
|
2016-11-07 22:42:27 +01:00
|
|
|
from Db import Db
|
2016-09-05 13:58:10 +02:00
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def resetSettings(request):
|
|
|
|
open("%s/sites.json" % config.data_dir, "w").write("{}")
|
2018-06-25 14:25:19 +02:00
|
|
|
open("%s/filters.json" % config.data_dir, "w").write("{}")
|
2015-09-20 00:27:54 +02:00
|
|
|
open("%s/users.json" % config.data_dir, "w").write("""
|
|
|
|
{
|
|
|
|
"15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc": {
|
|
|
|
"certs": {},
|
|
|
|
"master_seed": "024bceac1105483d66585d8a60eaf20aa8c3254b0f266e0d626ddb6114e2949a",
|
|
|
|
"sites": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|
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("{}")
|
2018-06-25 14:25:19 +02:00
|
|
|
open("%s/filters.json" % data_dir_temp, "w").write("{}")
|
2015-09-24 22:08:08 +02:00
|
|
|
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)
|
2018-06-25 14:25:19 +02:00
|
|
|
os.unlink("%s/filters.json" % data_dir_temp)
|
2015-09-24 22:08:08 +02:00
|
|
|
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()
|
2016-04-06 13:45:31 +02:00
|
|
|
def site(request):
|
2016-11-07 22:43:26 +01:00
|
|
|
threads_before = [obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet)]
|
2016-09-05 13:58:10 +02:00
|
|
|
# Reset ratelimit
|
|
|
|
RateLimit.queue_db = {}
|
|
|
|
RateLimit.called_db = {}
|
|
|
|
|
2015-09-20 00:27:54 +02:00
|
|
|
site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
|
2016-04-06 13:45:31 +02:00
|
|
|
|
|
|
|
# Always use original data
|
|
|
|
assert "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT" in site.storage.getPath("") # Make sure we dont delete everything
|
|
|
|
shutil.rmtree(site.storage.getPath(""), True)
|
2016-09-05 13:58:10 +02:00
|
|
|
shutil.copytree(site.storage.getPath("") + "-original", site.storage.getPath(""))
|
2018-04-03 14:50:09 +02:00
|
|
|
|
|
|
|
# Add to site manager
|
|
|
|
SiteManager.site_manager.get("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
|
|
|
|
site.announce = mock.MagicMock(return_value=True) # Don't try to find peers from the net
|
|
|
|
|
2016-04-06 13:45:31 +02:00
|
|
|
def cleanup():
|
|
|
|
site.storage.deleteFiles()
|
2016-11-07 23:20:52 +01:00
|
|
|
site.content_manager.contents.db.deleteSite(site)
|
2016-09-05 13:58:10 +02:00
|
|
|
del SiteManager.site_manager.sites["1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"]
|
|
|
|
site.content_manager.contents.db.close()
|
2018-04-03 14:50:09 +02:00
|
|
|
SiteManager.site_manager.sites.clear()
|
2016-09-05 13:58:10 +02:00
|
|
|
db_path = "%s/content.db" % config.data_dir
|
|
|
|
os.unlink(db_path)
|
|
|
|
del ContentDb.content_dbs[db_path]
|
2016-11-07 22:43:26 +01:00
|
|
|
gevent.killall([obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet) and obj not in threads_before])
|
2016-04-06 13:45:31 +02:00
|
|
|
request.addfinalizer(cleanup)
|
|
|
|
|
|
|
|
site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT") # Create new Site object to load content.json files
|
2016-09-05 13:58:10 +02:00
|
|
|
if not SiteManager.site_manager.sites:
|
|
|
|
SiteManager.site_manager.sites = {}
|
|
|
|
SiteManager.site_manager.sites["1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"] = site
|
2015-09-20 00:27:54 +02:00
|
|
|
return site
|
|
|
|
|
|
|
|
|
2015-09-24 22:08:08 +02:00
|
|
|
@pytest.fixture()
|
|
|
|
def site_temp(request):
|
2016-11-07 22:43:26 +01:00
|
|
|
threads_before = [obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet)]
|
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")
|
2016-10-02 14:23:30 +02:00
|
|
|
site_temp.announce = mock.MagicMock(return_value=True) # Don't try to find peers from the net
|
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()
|
2016-11-07 23:20:52 +01:00
|
|
|
site_temp.content_manager.contents.db.deleteSite(site_temp)
|
2016-09-05 13:58:10 +02:00
|
|
|
site_temp.content_manager.contents.db.close()
|
|
|
|
db_path = "%s-temp/content.db" % config.data_dir
|
|
|
|
os.unlink(db_path)
|
|
|
|
del ContentDb.content_dbs[db_path]
|
2016-11-07 22:43:26 +01:00
|
|
|
gevent.killall([obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet) and obj not in threads_before])
|
2015-09-24 22:08:08 +02:00
|
|
|
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")
|
2018-11-26 00:10:43 +01:00
|
|
|
def browser(request):
|
2015-09-20 00:27:54 +02:00
|
|
|
try:
|
|
|
|
from selenium import webdriver
|
2019-03-15 21:06:59 +01:00
|
|
|
print("Starting chromedriver...")
|
2018-11-26 00:10:43 +01:00
|
|
|
options = webdriver.chrome.options.Options()
|
|
|
|
options.add_argument("--headless")
|
|
|
|
options.add_argument("--window-size=1920x1080")
|
|
|
|
options.add_argument("--log-level=1")
|
2019-01-20 20:02:31 +01:00
|
|
|
browser = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, service_log_path=os.path.devnull, options=options)
|
2018-11-26 00:10:43 +01:00
|
|
|
|
|
|
|
def quit():
|
|
|
|
browser.quit()
|
|
|
|
request.addfinalizer(quit)
|
2019-03-15 21:06:59 +01:00
|
|
|
except Exception as err:
|
2018-11-26 00:10:43 +01:00
|
|
|
raise pytest.skip("Test requires selenium + chromedriver: %s" % err)
|
2015-09-20 00:27:54 +02:00
|
|
|
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:
|
2019-03-15 21:06:59 +01:00
|
|
|
urllib.request.urlopen(SITE_URL).read()
|
|
|
|
except Exception as err:
|
2015-09-20 00:27:54 +02:00
|
|
|
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
|
|
|
|
2019-01-20 03:11:33 +01:00
|
|
|
@pytest.fixture(params=['ipv4', 'ipv6'])
|
2015-09-24 22:08:08 +02:00
|
|
|
def file_server(request):
|
2019-01-20 03:11:33 +01:00
|
|
|
if request.param == "ipv4":
|
2019-01-20 20:02:31 +01:00
|
|
|
return request.getfixturevalue("file_server4")
|
2019-01-20 03:11:33 +01:00
|
|
|
else:
|
2019-01-20 20:02:31 +01:00
|
|
|
return request.getfixturevalue("file_server6")
|
2019-01-20 03:11:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def file_server4(request):
|
2015-09-24 22:08:08 +02:00
|
|
|
file_server = FileServer("127.0.0.1", 1544)
|
2019-01-20 03:11:33 +01:00
|
|
|
file_server.ip_external = "1.2.3.4" # Fake external ip
|
2018-04-29 03:05:36 +02:00
|
|
|
|
|
|
|
def listen():
|
|
|
|
ConnectionServer.start(file_server)
|
|
|
|
ConnectionServer.listen(file_server)
|
|
|
|
|
|
|
|
gevent.spawn(listen)
|
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
|
2019-03-15 21:06:59 +01:00
|
|
|
except Exception as err:
|
|
|
|
print(err)
|
2015-09-24 22:08:08 +02:00
|
|
|
assert file_server.running
|
2019-01-20 03:11:33 +01:00
|
|
|
file_server.ip_incoming = {} # Reset flood protection
|
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
|
|
|
|
|
2019-03-15 21:06:59 +01:00
|
|
|
|
2019-01-20 03:11:33 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def file_server6(request):
|
|
|
|
file_server6 = FileServer("::1", 1544)
|
2019-01-26 20:39:31 +01:00
|
|
|
file_server6.ip_external = 'fca5:95d6:bfde:d902:8951:276e:1111:a22c' # Fake external ip
|
2019-01-20 03:11:33 +01:00
|
|
|
|
|
|
|
def listen():
|
|
|
|
ConnectionServer.start(file_server6)
|
|
|
|
ConnectionServer.listen(file_server6)
|
|
|
|
|
|
|
|
gevent.spawn(listen)
|
|
|
|
# Wait for port opening
|
|
|
|
for retry in range(10):
|
|
|
|
time.sleep(0.1) # Port opening
|
|
|
|
try:
|
|
|
|
conn = file_server6.getConnection("::1", 1544)
|
|
|
|
conn.close()
|
|
|
|
break
|
2019-03-15 21:06:59 +01:00
|
|
|
except Exception as err:
|
|
|
|
print(err)
|
2019-01-20 03:11:33 +01:00
|
|
|
assert file_server6.running
|
|
|
|
file_server6.ip_incoming = {} # Reset flood protection
|
|
|
|
|
|
|
|
def stop():
|
|
|
|
file_server6.stop()
|
|
|
|
request.addfinalizer(stop)
|
|
|
|
return file_server6
|
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()
|
2019-01-20 03:11:33 +01:00
|
|
|
tor_manager.start()
|
|
|
|
assert tor_manager.conn
|
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()
|
2019-03-15 21:06:59 +01:00
|
|
|
except Exception as err:
|
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
|
|
|
raise pytest.skip("Test requires Tor with ControlPort: %s, %s" % (config.tor_controller, err))
|
|
|
|
return tor_manager
|
2016-11-07 22:42:27 +01:00
|
|
|
|
2019-03-15 21:06:59 +01:00
|
|
|
|
2016-11-07 22:42:27 +01:00
|
|
|
@pytest.fixture()
|
|
|
|
def db(request):
|
|
|
|
db_path = "%s/zeronet.db" % config.data_dir
|
|
|
|
schema = {
|
|
|
|
"db_name": "TestDb",
|
|
|
|
"db_file": "%s/zeronet.db" % config.data_dir,
|
|
|
|
"maps": {
|
|
|
|
"data.json": {
|
|
|
|
"to_table": [
|
|
|
|
"test",
|
|
|
|
{"node": "test", "table": "test_importfilter", "import_cols": ["test_id", "title"]}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"tables": {
|
|
|
|
"test": {
|
|
|
|
"cols": [
|
|
|
|
["test_id", "INTEGER"],
|
|
|
|
["title", "TEXT"],
|
|
|
|
["json_id", "INTEGER REFERENCES json (json_id)"]
|
|
|
|
],
|
|
|
|
"indexes": ["CREATE UNIQUE INDEX test_id ON test(test_id)"],
|
|
|
|
"schema_changed": 1426195822
|
|
|
|
},
|
|
|
|
"test_importfilter": {
|
|
|
|
"cols": [
|
|
|
|
["test_id", "INTEGER"],
|
|
|
|
["title", "TEXT"],
|
|
|
|
["json_id", "INTEGER REFERENCES json (json_id)"]
|
|
|
|
],
|
|
|
|
"indexes": ["CREATE UNIQUE INDEX test_importfilter_id ON test_importfilter(test_id)"],
|
|
|
|
"schema_changed": 1426195822
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.path.isfile(db_path):
|
|
|
|
os.unlink(db_path)
|
|
|
|
db = Db(schema, db_path)
|
|
|
|
db.checkTables()
|
|
|
|
|
|
|
|
def stop():
|
|
|
|
db.close()
|
|
|
|
os.unlink(db_path)
|
|
|
|
|
|
|
|
request.addfinalizer(stop)
|
|
|
|
return db
|