本文整理汇总了Python中txtorcon.TorConfig类的典型用法代码示例。如果您正苦于以下问题:Python TorConfig类的具体用法?Python TorConfig怎么用?Python TorConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TorConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_launch
def test_basic_launch(self):
config = TorConfig()
config.OrPort = 1234
config.SocksPort = 9999
def connector(proto, trans):
proto._set_valid_events('STATUS_CLIENT')
proto.makeConnection(trans)
proto.post_bootstrap.callback(proto)
return proto.post_bootstrap
class OnProgress:
def __init__(self, test, expected):
self.test = test
self.expected = expected
def __call__(self, percent, tag, summary):
self.test.assertEqual(self.expected[0], (percent, tag, summary))
self.expected = self.expected[1:]
self.test.assertTrue('"' not in summary)
self.test.assertTrue(percent >= 0 and percent <= 100)
def on_protocol(proto):
proto.outReceived('Bootstrapped 100%\n')
proto.progress = OnProgress(self, [(90, 'circuit_create', 'Establishing a Tor circuit'),
(100, 'done', 'Done')])
trans = FakeProcessTransport()
trans.protocol = self.protocol
self.othertrans = trans
creator = functools.partial(connector, self.protocol, self.transport)
d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
d.addCallback(self.setup_complete_no_errors, config)
return d
示例2: test_hidden_service_parse_error
def test_hidden_service_parse_error(self):
conf = TorConfig(FakeControlProtocol(['config/names=']))
try:
conf._setup_hidden_services('''FakeHiddenServiceKey=foo''')
self.fail()
except RuntimeError, e:
self.assertTrue('parse' in str(e))
示例3: test_tor_connection_user_data_dir
def test_tor_connection_user_data_dir(self):
"""
Test that we don't delete a user-supplied data directory.
"""
config = TorConfig()
config.OrPort = 1234
class Connector:
def __call__(self, proto, trans):
proto._set_valid_events('STATUS_CLIENT')
proto.makeConnection(trans)
proto.post_bootstrap.callback(proto)
return proto.post_bootstrap
def on_protocol(proto):
proto.outReceived('Bootstrapped 90%\n')
proto.outReceived('Bootstrapped 100%\n')
my_dir = tempfile.mkdtemp(prefix='tortmp')
config.DataDirectory = my_dir
trans = FakeProcessTransport()
trans.protocol = self.protocol
self.othertrans = trans
creator = functools.partial(Connector(), self.protocol, self.transport)
d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
def still_have_data_dir(proto, tester):
proto.cleanup() # FIXME? not really unit-testy as this is sort of internal function
tester.assertTrue(os.path.exists(my_dir))
delete_file_or_tree(my_dir)
d.addCallback(still_have_data_dir, self)
d.addErrback(self.fail)
return d
示例4: test_add_hidden_service_to_empty_config
def test_add_hidden_service_to_empty_config(self):
conf = TorConfig()
h = HiddenService(conf, '/fake/path', ['80 127.0.0.1:1234'], '', 3)
conf.hiddenservices.append(h)
self.assertEqual(len(conf.hiddenservices), 1)
self.assertEqual(h, conf.hiddenservices[0])
self.assertTrue(conf.needs_save())
示例5: test_parse_user_path
def test_parse_user_path(self):
# this makes sure we expand users and symlinks in
# hiddenServiceDir args. see Issue #77
# make sure we have a valid thing from get_global_tor without
# actually launching tor
config = TorConfig()
config.post_bootstrap = defer.succeed(config)
from txtorcon import torconfig
torconfig._global_tor_config = None
get_global_tor(
self.reactor,
_tor_launcher=lambda react, config, prog: defer.succeed(config)
)
ep = serverFromString(
self.reactor,
'onion:88:localPort=1234:hiddenServiceDir=~/blam/blarg'
)
# would be nice to have a fixed path here, but then would have
# to run as a known user :/
# maybe using the docker stuff to run integration tests better here?
self.assertEqual(
os.path.expanduser('~/blam/blarg'),
ep.hidden_service_dir
)
示例6: test_tor_produces_stderr_output
def test_tor_produces_stderr_output(self):
config = TorConfig()
config.OrPort = 1234
config.SocksPort = 9999
def connector(proto, trans):
proto._set_valid_events('STATUS_CLIENT')
proto.makeConnection(trans)
proto.post_bootstrap.callback(proto)
return proto.post_bootstrap
def on_protocol(proto):
proto.errReceived('Something went horribly wrong!\n')
trans = FakeProcessTransport()
trans.protocol = self.protocol
self.othertrans = trans
fakeout = StringIO()
fakeerr = StringIO()
creator = functools.partial(connector, self.protocol, self.transport)
d = launch_tor(config, FakeReactor(self, trans, on_protocol),
connection_creator=creator, tor_binary='/bin/echo',
stdout=fakeout, stderr=fakeerr)
d.addCallback(self.fail) # should't get callback
d.addErrback(self.setup_fails_stderr, fakeout, fakeerr)
self.assertFalse(self.protocol.on_disconnect)
return d
示例7: test_options_hidden
def test_options_hidden(self):
self.protocol.answers.append(
'HiddenServiceDir=/fake/path\nHiddenServicePort=80 '
'127.0.0.1:1234\nHiddenServiceDirGroupReadable=1\n'
)
conf = TorConfig(self.protocol)
yield conf.post_bootstrap
self.assertTrue(conf.post_bootstrap.called)
self.assertTrue('HiddenServiceOptions' not in conf.config)
self.assertTrue('HiddenServices' in conf.config)
self.assertEqual(len(conf.HiddenServices), 1)
self.assertTrue(not conf.needs_save())
conf.hiddenservices.append(
HiddenService(conf, '/some/dir', '80 127.0.0.1:2345', 'auth', 2, True)
)
conf.hiddenservices[0].ports.append('443 127.0.0.1:443')
self.assertTrue(conf.needs_save())
conf.save()
self.assertEqual(len(self.protocol.sets), 9)
self.assertEqual(self.protocol.sets[0], ('HiddenServiceDir', '/fake/path'))
self.assertEqual(self.protocol.sets[1], ('HiddenServiceDirGroupReadable', '1'))
self.assertEqual(self.protocol.sets[2], ('HiddenServicePort', '80 127.0.0.1:1234'))
self.assertEqual(self.protocol.sets[3], ('HiddenServicePort', '443 127.0.0.1:443'))
self.assertEqual(self.protocol.sets[4], ('HiddenServiceDir', '/some/dir'))
self.assertEqual(self.protocol.sets[5], ('HiddenServiceDirGroupReadable', '1'))
self.assertEqual(self.protocol.sets[6], ('HiddenServicePort', '80 127.0.0.1:2345'))
self.assertEqual(self.protocol.sets[7], ('HiddenServiceVersion', '2'))
self.assertEqual(self.protocol.sets[8], ('HiddenServiceAuthorizeClient', 'auth'))
示例8: test_parse_relative_path
def test_parse_relative_path(self):
# this makes sure we convert a relative path to absolute
# hiddenServiceDir args. see Issue #77
# make sure we have a valid thing from get_global_tor without
# actually launching tor
config = TorConfig()
config.post_bootstrap = defer.succeed(config)
from txtorcon import torconfig
torconfig._global_tor_config = None
get_global_tor(
self.reactor,
_tor_launcher=lambda react, config, prog: defer.succeed(config)
)
orig = os.path.realpath('.')
try:
with util.TempDir() as t:
t = str(t)
os.chdir(t)
os.mkdir(os.path.join(t, 'foo'))
hsdir = os.path.join(t, 'foo', 'blam')
os.mkdir(hsdir)
ep = serverFromString(
self.reactor,
'onion:88:localPort=1234:hiddenServiceDir=foo/blam'
)
self.assertEqual(
os.path.realpath(hsdir),
ep.hidden_service_dir
)
finally:
os.chdir(orig)
示例9: test_tor_connection_fails
def test_tor_connection_fails(self):
"""
We fail to connect once, and then successfully connect --
testing whether we're retrying properly on each Bootstrapped
line from stdout.
"""
config = TorConfig()
config.OrPort = 1234
config.SocksPort = 9999
class Connector:
count = 0
def __call__(self, proto, trans):
self.count += 1
if self.count < 2:
return defer.fail(error.CannotListenError(None, None, None))
proto._set_valid_events('STATUS_CLIENT')
proto.makeConnection(trans)
proto.post_bootstrap.callback(proto)
return proto.post_bootstrap
def on_protocol(proto):
proto.outReceived('Bootstrapped 90%\n')
proto.outReceived('Bootstrapped 100%\n')
trans = FakeProcessTransport()
trans.protocol = self.protocol
self.othertrans = trans
creator = functools.partial(Connector(), self.protocol, self.transport)
d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator, tor_binary='/bin/echo')
d.addCallback(self.setup_complete_fails)
return self.assertFailure(d, Exception)
示例10: test_tor_connection_user_control_port
def test_tor_connection_user_control_port(self):
"""
Confirm we use a user-supplied control-port properly
"""
config = TorConfig()
config.OrPort = 1234
config.ControlPort = 4321
class Connector:
def __call__(self, proto, trans):
proto._set_valid_events('STATUS_CLIENT')
proto.makeConnection(trans)
proto.post_bootstrap.callback(proto)
return proto.post_bootstrap
def on_protocol(proto):
proto.outReceived('Bootstrapped 90%\n')
proto.outReceived('Bootstrapped 100%\n')
trans = FakeProcessTransport()
trans.protocol = self.protocol
self.othertrans = trans
creator = functools.partial(Connector(), self.protocol, self.transport)
d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
def check_control_port(proto, tester):
## we just want to ensure launch_tor() didn't mess with
## the controlport we set
tester.assertEquals(config.ControlPort, 4321)
d.addCallback(check_control_port, self)
d.addErrback(self.fail)
return d
示例11: test_set_wrong_object
def test_set_wrong_object(self):
conf = TorConfig(self.protocol)
try:
conf.log = ('this', 'is', 'a', 'tuple')
self.fail()
except ValueError, e:
self.assertTrue('Not valid' in str(e))
示例12: test_log_set_index
def test_log_set_index(self):
conf = TorConfig(self.protocol)
conf.log[0] = 'info file /tmp/foo.log'
self.assertTrue(conf.needs_save())
conf.save()
self.assertTrue(self.protocol.sets[0] == ('Log', 'info file /tmp/foo.log'))
示例13: _do_launch_tor
def _do_launch_tor(self):
tconfig = TorConfig()
#tconfig.ControlPort = allocate_tcp_port() # defaults to 9052
tconfig.SocksPort = allocate_tcp_port()
socks_desc = "tcp:127.0.0.1:%d" % tconfig.SocksPort
# this could take tor_binary=
tproto = yield launch_tor(tconfig, self._reactor)
returnValue((tproto, tconfig, socks_desc))
示例14: test_log_set_slice
def test_log_set_slice(self):
conf = TorConfig(self.protocol)
conf.log[0:1] = ['info file /tmp/foo.log']
self.assertTrue(conf.needs_save())
conf.save()
self.assertEqual(self.protocol.sets[0], ('Log', 'info file /tmp/foo.log'))
示例15: test_multiple_orports
def test_multiple_orports(self):
self.protocol.post_bootstrap = None
self.protocol.answers.append('config/names=\nOrPort CommaList')
self.protocol.answers.append({'OrPort': '1234'})
conf = TorConfig(self.protocol)
conf.OrPort = ['1234', '4321']
conf.save()
self.assertEqual(self.protocol.sets, [('OrPort', '1234'),
('OrPort', '4321')])