Skip to content

Commit

Permalink
Added test for comment failing
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Miller <amiller@dappervision.com>

Added a simple validation of introducer furl

Signed-off-by: Andrew Miller <amiller@dappervision.com>

Improved regular expression

Signed-off-by: Andrew Miller <amiller@dappervision.com>

better parse

Signed-off-by: Andrew Miller <amiller@dappervision.com>
  • Loading branch information
amiller committed Jan 14, 2014
1 parent 419df9b commit c88d4ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/allmydata/client.py
Expand Up @@ -176,6 +176,19 @@ def _sequencer(self):

def init_introducer_client(self):
self.introducer_furl = self.get_config("client", "introducer.furl")

# Make a simple attempt to validate the introducer furl
def contains_unescaped_hash(description):
description = iter(description)
for n in description:
if n == '\\': description.next()
elif n == '#': return True
else: continue
return False

if contains_unescaped_hash(self.introducer_furl):
raise Exception("introducer.furl contains an unescaped '#' character")

ic = IntroducerClient(self.tub, self.introducer_furl,
self.nickname,
str(allmydata.__full_version__),
Expand Down
22 changes: 22 additions & 0 deletions src/allmydata/test/test_client.py
Expand Up @@ -30,6 +30,28 @@ def test_loadable(self):
BASECONFIG)
client.Client(basedir)

def test_comment(self):
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"

shouldfail = [r"test#test", "#testtest", r"test\\#test"]
shouldnotfail = [r"test\#test", r"test\\\#test", r"testtest"]

basedir = "test_client.Basic.test_comment"
os.mkdir(basedir)

def test(shouldfail, s):
config = ("[client]\n"
"introducer.furl = %s\n" % s)
fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
config)
if shouldfail:
self.failUnlessRaises(Exception, client.Client, basedir)
else:
client.Client(basedir)

for s in shouldfail: test(True, s)
for s in shouldnotfail: test(False, s)

@mock.patch('twisted.python.log.msg')
def test_error_on_old_config_files(self, mock_log_msg):
basedir = "test_client.Basic.test_error_on_old_config_files"
Expand Down

0 comments on commit c88d4ea

Please sign in to comment.