本文整理汇总了Python中txtorcon.TorControlProtocol._bootstrap方法的典型用法代码示例。如果您正苦于以下问题:Python TorControlProtocol._bootstrap方法的具体用法?Python TorControlProtocol._bootstrap怎么用?Python TorControlProtocol._bootstrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorControlProtocol
的用法示例。
在下文中一共展示了TorControlProtocol._bootstrap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProtocolTests
# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import _bootstrap [as 别名]
#.........这里部分代码省略.........
VERSION Tor="0.2.2.35"
OK'''.format(unexisting_file))
self.assertEqual(
self.transport.value(),
b'AUTHENTICATE ' + b2a_hex(b'foo') + b'\r\n',
)
def test_authenticate_safecookie_wrong_hash(self):
cookiedata = bytes(bytearray([0] * 32))
server_nonce = bytes(bytearray([0] * 32))
server_hash = bytes(bytearray([0] * 32))
# pretend we already did PROTOCOLINFO and read the cookie
# file
self.protocol._cookie_data = cookiedata
self.protocol.client_nonce = server_nonce # all 0's anyway
try:
self.protocol._safecookie_authchallenge(
'250 AUTHCHALLENGE SERVERHASH={} SERVERNONCE={}'.format(
b2a_hex(server_hash).decode('ascii'),
b2a_hex(server_nonce).decode('ascii'),
)
)
self.assertTrue(False)
except RuntimeError as e:
self.assertTrue('hash not expected' in str(e))
def confirm_version_events(self, arg):
self.assertEqual(self.protocol.version, 'foo')
events = 'GUARD STREAM CIRC NS NEWCONSENSUS ORCONN NEWDESC ADDRMAP STATUS_GENERAL'.split()
self.assertEqual(len(self.protocol.valid_events), len(events))
self.assertTrue(all(x in self.protocol.valid_events for x in events))
def test_bootstrap_callback(self):
d = self.protocol.post_bootstrap
d.addCallback(CallbackChecker(self.protocol))
d.addCallback(self.confirm_version_events)
events = b'GUARD STREAM CIRC NS NEWCONSENSUS ORCONN NEWDESC ADDRMAP STATUS_GENERAL'
self.protocol._bootstrap()
# answer all the requests generated by boostrapping etc.
self.send(b"250-signal/names=")
self.send(b"250 OK")
self.send(b"250-version=foo")
self.send(b"250 OK")
self.send(b"250-events/names=" + events)
self.send(b"250 OK")
self.send(b"250 OK") # for USEFEATURE
return d
def test_bootstrap_tor_does_not_support_signal_names(self):
self.protocol._bootstrap()
self.send(b'552 Unrecognized key "signal/names"')
valid_signals = ["RELOAD", "DUMP", "DEBUG", "NEWNYM", "CLEARDNSCACHE"]
self.assertEqual(self.protocol.valid_signals, valid_signals)
def test_async(self):
"""
test the example from control-spec.txt to see that we
handle interleaved async notifications properly.
"""