def test_is_built_errback(self): tor = FakeTorController() a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a') tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a state = TorState(tor) circuit = Circuit(tor) circuit.listen(tor) circuit.update( '123 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL' .split()) state.circuit_new(circuit) d = circuit.when_built() called = [] def err(f): called.append(f) return None d.addErrback(err) state.circuit_closed(circuit, REASON='testing') self.assertEqual(1, len(called)) self.assertTrue(isinstance(called[0], Failure)) self.assertTrue('testing' in str(called[0].value)) return d
def setUp(self): self.protocol = TorControlProtocol() self.state = TorState(self.protocol) # avoid spew in trial logs; state prints this by default self.state._attacher_error = lambda f: f self.protocol.connectionMade = lambda: None self.transport = proto_helpers.StringTransport() self.protocol.makeConnection(self.transport)
def _setup_complete(self, proto): """ Called when we read from stdout that Tor has reached 100%. """ log.debug("Building a TorState") config.tor.protocol = proto state = TorState(proto.tor_protocol) state.post_bootstrap.addCallbacks(self._state_complete, self._setup_failed)
def setup_complete(proto): """ Called when we read from stdout that Tor has reached 100%. """ log.debug("Building a TorState") state = TorState(proto.tor_protocol) state.post_bootstrap.addCallback(state_complete) state.post_bootstrap.addErrback(setup_failed) return state.post_bootstrap
def test_path_update(self): cp = TorControlProtocol() state = TorState(cp, False) circuit = Circuit(state) circuit.update('1 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split()) self.assertEqual(1, len(circuit.path)) self.assertEqual( '$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', circuit.path[0].id_hex ) self.assertEqual('eris', circuit.path[0].name)
def _setup_complete(self, proto): """ Called when we read from stdout that Tor has reached 100%. """ log.debug("Building a TorState") config.tor.protocol = proto state = TorState(proto.tor_protocol) # note that errors from _state_complete will only get handled # if we add the errback *after* -- which is why this isn't # using .addCallbacks(..) state.post_bootstrap.addCallback(self._state_complete) state.post_bootstrap.addErrback(self._setup_failed)
def test_is_built_errback(self): tor = FakeTorController() a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a') tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a state = TorState(tor) circuit = Circuit(tor) circuit.listen(tor) circuit.update('123 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split()) state.circuit_new(circuit) d = circuit.when_built() state.circuit_closed(circuit) self.assertTrue(d.called) self.assertTrue(isinstance(d.result, Failure))
def setUp(self): self.protocol = TorControlProtocol() self.state = TorState(self.protocol) self.protocol.connectionMade = lambda: None self.transport = proto_helpers.StringTransport() self.protocol.makeConnection(self.transport)
def test_state_diagram(self): TorState(FakeControlProtocol(), bootstrap=False, write_state_diagram=True) self.assertTrue(os.path.exists('routerfsm.dot'))
def setUp(self): self.controller = TorState(TorControlProtocol()) self.controller.connectionMade = lambda _: None
def launch_and_get_state(ignore): d2 = launch_tor(config, reactor, stdout=sys.stdout) d2.addCallback(lambda tpp: TorState(tpp.tor_protocol).post_bootstrap) return d2
def test_attacher_error_handler(self): # make sure error-handling "does something" that isn't blowing up with patch('sys.stdout') as fake_stdout: TorState(self.protocol)._attacher_error( Failure(RuntimeError("quote")))
def setup_done(proto): log.msg("Setup Complete") state = TorState(proto.tor_protocol) state.post_bootstrap.addCallback(state_complete) state.post_bootstrap.addErrback(setup_fail)