WIP: remove unused server tests, minor syntax fixes. still fails.

This commit is contained in:
Brian Warner 2018-02-20 23:54:28 -08:00
parent 9957044a99
commit 37a7ed7adc
4 changed files with 4 additions and 1584 deletions

View File

@ -7,6 +7,7 @@ import mock
from ..cli import cli
from ..transit import allocate_tcp_port
from wormhole_mailbox_server.server import make_server
from wormhole_mailbox_server.web import make_web_server
from wormhole_mailbox_server.database import create_channel_db
from wormhole_transit_relay.transit_server import Transit
@ -23,9 +24,9 @@ class ServerBase:
self._rendezvous = make_server(db,
advertise_version=advertise_version,
signal_error=error)
ep = endpoints.TCP4ServerEndpoint(reactor 0, interface="127.0.01")
site = make_web_server(self._rendezvous)
s = StreamServerEndpointService(ep, site)
ep = endpoints.TCP4ServerEndpoint(reactor, 0, interface="127.0.01")
site = make_web_server(self._rendezvous, log_requests=False)
s = internet.StreamServerEndpointService(ep, site)
s.setServiceParent(self.sp)
self.rdv_ws_port = s.__lp.getHost().port
self._relay_server = s

View File

@ -17,8 +17,6 @@ from ..cli import cmd_send, cmd_receive, welcome, cli
from ..errors import (TransferError, WrongPasswordError, WelcomeError,
UnsendableFileError, ServerConnectionError)
from .._interfaces import ITorManager
from wormhole.server.cmd_server import MyPlugin
from wormhole.server.cli import server
def build_offer(args):
@ -1260,97 +1258,3 @@ class Help(unittest.TestCase):
result = CliRunner().invoke(cli.wormhole, ["--help"])
self._check_top_level_help(result.output)
self.assertEqual(result.exit_code, 0)
class FakeConfig(object):
no_daemon = True
blur_usage = True
advertise_version = u"fake.version.1"
transit = str('tcp:4321')
rendezvous = str('tcp:1234')
signal_error = True
allow_list = False
relay_database_path = "relay.sqlite"
stats_json_path = "stats.json"
class Server(unittest.TestCase):
def setUp(self):
self.runner = CliRunner()
@mock.patch('wormhole.server.cmd_server.twistd')
def test_server_disallow_list(self, fake_twistd):
result = self.runner.invoke(server, ['start', '--no-daemon', '--disallow-list'])
self.assertEqual(0, result.exit_code)
def test_server_plugin(self):
cfg = FakeConfig()
plugin = MyPlugin(cfg)
relay = plugin.makeService(None)
self.assertEqual(False, relay._allow_list)
@mock.patch("wormhole.server.cmd_server.start_server")
def test_start_no_args(self, fake_start_server):
result = self.runner.invoke(server, ['start'])
self.assertEqual(0, result.exit_code)
cfg = fake_start_server.mock_calls[0][1][0]
MyPlugin(cfg).makeService(None)
@mock.patch("wormhole.server.cmd_server.restart_server")
def test_restart_no_args(self, fake_start_reserver):
result = self.runner.invoke(server, ['restart'])
self.assertEqual(0, result.exit_code)
cfg = fake_start_reserver.mock_calls[0][1][0]
MyPlugin(cfg).makeService(None)
def test_state_locations(self):
cfg = FakeConfig()
plugin = MyPlugin(cfg)
relay = plugin.makeService(None)
self.assertEqual('relay.sqlite', relay._db_url)
self.assertEqual('stats.json', relay._stats_file)
@mock.patch("wormhole.server.cmd_server.start_server")
def test_websocket_protocol_options(self, fake_start_server):
result = self.runner.invoke(
server, [
'start',
'--websocket-protocol-option=a=3',
'--websocket-protocol-option=b=true',
'--websocket-protocol-option=c=3.5',
'--websocket-protocol-option=d=["foo","bar"]',
'--websocket-protocol-option', 'e=["foof","barf"]',
])
self.assertEqual(0, result.exit_code)
cfg = fake_start_server.mock_calls[0][1][0]
self.assertEqual(
cfg.websocket_protocol_option,
[("a", 3), ("b", True), ("c", 3.5), ("d", ['foo', 'bar']),
("e", ['foof', 'barf']),
],
)
def test_broken_websocket_protocol_options(self):
result = self.runner.invoke(
server, [
'start',
'--websocket-protocol-option=a',
])
self.assertNotEqual(0, result.exit_code)
self.assertIn(
'Error: Invalid value for "--websocket-protocol-option": '
'format options as OPTION=VALUE',
result.output,
)
result = self.runner.invoke(
server, [
'start',
'--websocket-protocol-option=a=foo',
])
self.assertNotEqual(0, result.exit_code)
self.assertIn(
'Error: Invalid value for "--websocket-protocol-option": '
'could not parse JSON value for a',
result.output,
)

View File

@ -1,61 +0,0 @@
from __future__ import print_function, unicode_literals
import os
from twisted.python import filepath
from twisted.trial import unittest
from ..server import database
from ..server.database import get_db, TARGET_VERSION, dump_db
class DB(unittest.TestCase):
def test_create_default(self):
db_url = ":memory:"
db = get_db(db_url)
rows = db.execute("SELECT * FROM version").fetchall()
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["version"], TARGET_VERSION)
def test_failed_create_allows_subsequent_create(self):
patch = self.patch(database, "get_schema", lambda version: b"this is a broken schema")
dbfile = filepath.FilePath(self.mktemp())
self.assertRaises(Exception, lambda: get_db(dbfile.path))
patch.restore()
get_db(dbfile.path)
def test_upgrade(self):
basedir = self.mktemp()
os.mkdir(basedir)
fn = os.path.join(basedir, "upgrade.db")
self.assertNotEqual(TARGET_VERSION, 2)
# create an old-version DB in a file
db = get_db(fn, 2)
rows = db.execute("SELECT * FROM version").fetchall()
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["version"], 2)
del db
# then upgrade the file to the latest version
dbA = get_db(fn, TARGET_VERSION)
rows = dbA.execute("SELECT * FROM version").fetchall()
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["version"], TARGET_VERSION)
dbA_text = dump_db(dbA)
del dbA
# make sure the upgrades got committed to disk
dbB = get_db(fn, TARGET_VERSION)
dbB_text = dump_db(dbB)
del dbB
self.assertEqual(dbA_text, dbB_text)
# The upgraded schema should be equivalent to that of a new DB.
# However a text dump will differ because ALTER TABLE always appends
# the new column to the end of a table, whereas our schema puts it
# somewhere in the middle (wherever it fits naturally). Also ALTER
# TABLE doesn't include comments.
if False:
latest_db = get_db(":memory:", TARGET_VERSION)
latest_text = dump_db(latest_db)
with open("up.sql","w") as f: f.write(dbA_text)
with open("new.sql","w") as f: f.write(latest_text)
# check with "diff -u _trial_temp/up.sql _trial_temp/new.sql"
self.assertEqual(dbA_text, latest_text)

File diff suppressed because it is too large Load Diff