mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-27 06:20:25 +00:00
Improve test coverage.
This commit is contained in:
parent
fa0dbcfd0e
commit
0cf6ca86fb
@ -17,6 +17,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import mock
|
import mock
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
import configparser
|
||||||
|
|
||||||
from unittest import skipIf
|
from unittest import skipIf
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ from allmydata.node import (
|
|||||||
MissingConfigEntry,
|
MissingConfigEntry,
|
||||||
_tub_portlocation,
|
_tub_portlocation,
|
||||||
formatTimeTahoeStyle,
|
formatTimeTahoeStyle,
|
||||||
|
UnescapedHashError,
|
||||||
|
PrivacyError,
|
||||||
)
|
)
|
||||||
from allmydata.introducer.server import create_introducer
|
from allmydata.introducer.server import create_introducer
|
||||||
from allmydata import client
|
from allmydata import client
|
||||||
@ -178,6 +181,43 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
|
|||||||
config = read_config(basedir, "")
|
config = read_config(basedir, "")
|
||||||
self.failUnless(config.nickname == nickname)
|
self.failUnless(config.nickname == nickname)
|
||||||
|
|
||||||
|
def test_hash_in_furl(self):
|
||||||
|
"""
|
||||||
|
Hashes in furl options are not allowed, resulting in exception.
|
||||||
|
"""
|
||||||
|
escaped = "lalal\\#onohash"
|
||||||
|
basedir = self.mktemp()
|
||||||
|
fileutil.make_dirs(basedir)
|
||||||
|
with open(os.path.join(basedir, 'tahoe.cfg'), 'wt') as f:
|
||||||
|
f.write("[node]\n")
|
||||||
|
f.write("log_gatherer.furl = lalal#onohash\n")
|
||||||
|
|
||||||
|
config = read_config(basedir, "")
|
||||||
|
with self.assertRaises(UnescapedHashError):
|
||||||
|
config.get_config("node", "log_gatherer.furl")
|
||||||
|
|
||||||
|
with open(os.path.join(basedir, 'tahoe.cfg'), 'wt') as f:
|
||||||
|
f.write("[node]\n")
|
||||||
|
f.write("log_gatherer.furl = %s\n" % (escaped,))
|
||||||
|
self.assertEquals(config.get_config("node", "log_gatherer.furl"), escaped)
|
||||||
|
|
||||||
|
def test_missing_config_item(self):
|
||||||
|
"""
|
||||||
|
If a config item is missing:
|
||||||
|
|
||||||
|
1. Given a default, return default.
|
||||||
|
2. Otherwise, raise MissingConfigEntry.
|
||||||
|
"""
|
||||||
|
basedir = self.mktemp()
|
||||||
|
fileutil.make_dirs(basedir)
|
||||||
|
with open(os.path.join(basedir, 'tahoe.cfg'), 'wt') as f:
|
||||||
|
f.write("[node]\n")
|
||||||
|
config = read_config(basedir, "")
|
||||||
|
|
||||||
|
self.assertEquals(config.get_config("node", "log_gatherer.furl", "def"), "def")
|
||||||
|
with self.assertRaises(MissingConfigEntry):
|
||||||
|
config.get_config("node", "log_gatherer.furl")
|
||||||
|
|
||||||
def test_config_required(self):
|
def test_config_required(self):
|
||||||
"""
|
"""
|
||||||
Asking for missing (but required) configuration is an error
|
Asking for missing (but required) configuration is an error
|
||||||
@ -210,6 +250,31 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
|
|||||||
("timeout.disconnect", "12"),
|
("timeout.disconnect", "12"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
config.items("node", [("unnecessary", "default")]),
|
||||||
|
[("nickname", "foo"),
|
||||||
|
("timeout.disconnect", "12"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_items_missing_section(self):
|
||||||
|
"""
|
||||||
|
If a default is given for a missing section, the default is used.
|
||||||
|
|
||||||
|
Lacking both default and section, an error is raised.
|
||||||
|
"""
|
||||||
|
basedir = self.mktemp()
|
||||||
|
create_node_dir(basedir, "testing")
|
||||||
|
|
||||||
|
with open(os.path.join(basedir, 'tahoe.cfg'), 'wt') as f:
|
||||||
|
f.write("")
|
||||||
|
|
||||||
|
config = read_config(basedir, "portnum")
|
||||||
|
with self.assertRaises(configparser.NoSectionError):
|
||||||
|
config.items("nosuch")
|
||||||
|
default = [("hello", "world")]
|
||||||
|
self.assertEqual(config.items("nosuch", default), default)
|
||||||
|
|
||||||
@skipIf(
|
@skipIf(
|
||||||
"win32" in sys.platform.lower() or "cygwin" in sys.platform.lower(),
|
"win32" in sys.platform.lower() or "cygwin" in sys.platform.lower(),
|
||||||
@ -756,3 +821,52 @@ class Configuration(unittest.TestCase):
|
|||||||
"invalid section",
|
"invalid section",
|
||||||
str(ctx.exception),
|
str(ctx.exception),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class FakeProvider(object):
|
||||||
|
"""Emulate Tor and I2P providers."""
|
||||||
|
|
||||||
|
def get_tor_handler(self):
|
||||||
|
return "TORHANDLER!"
|
||||||
|
|
||||||
|
def get_i2p_handler(self):
|
||||||
|
return "I2PHANDLER!"
|
||||||
|
|
||||||
|
|
||||||
|
class CreateConnectionHandlers(unittest.TestCase):
|
||||||
|
"""
|
||||||
|
Tests for create_connection_handlers().
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_tcp_disabled(self):
|
||||||
|
"""
|
||||||
|
If tcp is set to disabled, no TCP handler is set.
|
||||||
|
"""
|
||||||
|
config = config_from_string("", "", dedent("""
|
||||||
|
[connections]
|
||||||
|
tcp = disabled
|
||||||
|
"""))
|
||||||
|
reactor = object() # it's not actually used?!
|
||||||
|
provider = FakeProvider()
|
||||||
|
default_handlers, _ = create_connection_handlers(
|
||||||
|
reactor, config, provider, provider
|
||||||
|
)
|
||||||
|
self.assertIs(default_handlers["tcp"], None)
|
||||||
|
|
||||||
|
def test_reveal_ip_tcp(self):
|
||||||
|
"""
|
||||||
|
If reveal IP setting is false, TCP handler is not allowed.
|
||||||
|
"""
|
||||||
|
config = config_from_string("", "", dedent("""
|
||||||
|
[node]
|
||||||
|
reveal-IP-address = False
|
||||||
|
|
||||||
|
[connections]
|
||||||
|
tcp = tcp
|
||||||
|
"""))
|
||||||
|
reactor = object() # it's not actually used?!
|
||||||
|
provider = FakeProvider()
|
||||||
|
with self.assertRaises(PrivacyError):
|
||||||
|
create_connection_handlers(reactor, config, provider, provider)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user