def test_invalid_introducer_furl(self): """ An introducer.furl of 'None' is invalid and causes create_introducer_clients to fail. """ cfg = ("[client]\n" "introducer.furl = None\n") config = config_from_string("basedir", "client.port", cfg) with self.assertRaises(ValueError) as ctx: client.create_introducer_clients(config, main_tub=None) self.assertIn("invalid 'introducer.furl = None'", str(ctx.exception))
def test_introducer_clients_unloadable(self): """ ``create_introducer_clients`` raises ``EnvironmentError`` if ``introducers.yaml`` exists but we can't read it. """ basedir = u"introducer.IntroducerNode.test_introducer_clients_unloadable" os.mkdir(basedir) os.mkdir(os.path.join(basedir, u"private")) yaml_fname = os.path.join(basedir, u"private", u"introducers.yaml") with open(yaml_fname, 'w') as f: f.write(u'---\n') os.chmod(yaml_fname, 0o000) self.addCleanup(lambda: os.chmod(yaml_fname, 0o700)) config = read_config(basedir, "portnum") with self.assertRaises(EnvironmentError): create_introducer_clients(config, Tub())
def test_invalid_introducer_furl(self): """ An introducer.furl of 'None' is invalid and causes create_introducer_clients to fail. """ cfg = ( "[client]\n" "introducer.furl = None\n" ) config = config_from_string("basedir", "client.port", cfg) with self.assertRaises(ValueError) as ctx: client.create_introducer_clients(config, main_tub=None) self.assertIn( "invalid 'introducer.furl = None'", str(ctx.exception) )
def test_introducer_clients_unloadable(self): """ Error if introducers.yaml exists but we can't read it """ basedir = u"introducer.IntroducerNode.test_introducer_clients_unloadable" os.mkdir(basedir) os.mkdir(os.path.join(basedir, u"private")) yaml_fname = os.path.join(basedir, u"private", u"introducers.yaml") with open(yaml_fname, 'w') as f: f.write(u'---\n') os.chmod(yaml_fname, 0o000) self.addCleanup(lambda: os.chmod(yaml_fname, 0o700)) # just mocking the yaml failure, as "yamlutil.safe_load" only # returns None on some platforms for unreadable files with patch("allmydata.client.yamlutil") as p: p.safe_load = Mock(return_value=None) fake_tub = Mock() config = read_config(basedir, "portnum") with self.assertRaises(EnvironmentError): create_introducer_clients(config, fake_tub)