mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-31 16:36:20 +00:00
Make corrections from Daira's code review
This commit is contained in:
parent
31dfee2dcd
commit
e9c1075ac5
@ -34,18 +34,14 @@ def validate_where_options(options):
|
||||
raise usage.UsageError("The --port option must be used with the --location option.")
|
||||
if (options['listen'] != "tcp") and options['hostname']:
|
||||
raise usage.UsageError("The listener type must be TCP to use --hostname option.")
|
||||
if options['listen'] not in ["tcp", "tor", "i2p"]:
|
||||
raise usage.UsageError("The listener type must set to one of: tcp, tor, i2p.")
|
||||
|
||||
class _CreateBaseOptions(BasedirOptions):
|
||||
optFlags = [
|
||||
("hide-ip", None, "prohibit any configuration that would reveal the node's IP address"),
|
||||
]
|
||||
|
||||
# This is overridden in order to ensure we get a "Wrong number of
|
||||
# arguments." error when more than one argument is given.
|
||||
def parseArgs(self, basedir=None):
|
||||
BasedirOptions.parseArgs(self, basedir)
|
||||
|
||||
|
||||
class CreateClientOptions(_CreateBaseOptions):
|
||||
synopsis = "[options] [NODEDIR]"
|
||||
description = "Create a client-only Tahoe-LAFS node (no storage server)."
|
||||
@ -62,6 +58,8 @@ class CreateClientOptions(_CreateBaseOptions):
|
||||
% quote_local_unicode_path(_default_nodedir)),
|
||||
]
|
||||
|
||||
# This is overridden in order to ensure we get a "Wrong number of
|
||||
# arguments." error when more than one argument is given.
|
||||
def parseArgs(self, basedir=None):
|
||||
BasedirOptions.parseArgs(self, basedir)
|
||||
|
||||
@ -147,7 +145,7 @@ def write_node_config(c, config):
|
||||
c.write("tub.port = disabled\n")
|
||||
c.write("tub.location = disabled\n")
|
||||
|
||||
if ('hostname' in config and config['hostname']) or ('listen' in config and config['listen']):
|
||||
if config.get('hostname', None) or config.get('listen', None):
|
||||
c.write("# to prevent the Tub from listening at all, use this:\n")
|
||||
c.write("# tub.port = disabled\n")
|
||||
c.write("# tub.location = disabled\n")
|
||||
|
@ -11,6 +11,33 @@ class Config(unittest.TestCase):
|
||||
config = configutil.get_config(tahoe_cfg)
|
||||
return config
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _test_option_not_recognized(self, option, *args):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
params = args[0] + (basedir,)
|
||||
rc, out, err = yield run_cli(*params)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option %s not recognized" % (option,))
|
||||
else:
|
||||
self.fail("UsageError expected to be raised")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_unrecognized_options(self):
|
||||
basedir = self.mktemp()
|
||||
tests = [
|
||||
("--listen", ("create-client", "--listen=tcp")),
|
||||
("--hostname", ("create-client", "--hostname=computer")),
|
||||
("--port", ("create-client", "--port=unix:/var/tahoe/socket",
|
||||
"--location=tor:myservice.onion:12345")),
|
||||
("--port", ("create-client", "--port=unix:/var/tahoe/socket")),
|
||||
("--location", ("create-client", "--location=tor:myservice.onion:12345")),
|
||||
("--listen", ("create-client", "--listen=tor")),
|
||||
("--listen", ("create-client", "--listen=i2p")),
|
||||
]
|
||||
for test in tests:
|
||||
yield self._test_option_not_recognized(test[0], test[1])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client(self):
|
||||
basedir = self.mktemp()
|
||||
@ -20,79 +47,6 @@ class Config(unittest.TestCase):
|
||||
self.assertEqual(cfg.get("node", "tub.port"), "disabled")
|
||||
self.assertEqual(cfg.get("node", "tub.location"), "disabled")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_hostname(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client", "--hostname=computer", basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --hostname not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_port_location(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client",
|
||||
"--port=unix:/var/tahoe/socket",
|
||||
"--location=tor:myservice.onion:12345",
|
||||
basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --port not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_port_only(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client", "--port=unix:/var/tahoe/socket", basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --port not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_location_only(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client", "--location=tor:myservice.onion:12345", basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --location not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_listen_tcp(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client", "--listen=tcp", basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --listen not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised)")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_listen_tor(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client", "--listen=tor", basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --listen not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised)")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_listen_i2p(self):
|
||||
basedir = self.mktemp()
|
||||
try:
|
||||
rc, out, err = yield run_cli("create-client", "--listen=i2p", basedir)
|
||||
except usage.UsageError, e:
|
||||
self.failUnlessEqual(str(e), "option --listen not recognized")
|
||||
else:
|
||||
self.fail("UsageError expected to be raised")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_client_hide_ip(self):
|
||||
basedir = self.mktemp()
|
||||
|
Loading…
x
Reference in New Issue
Block a user