Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 def test_state_diagram(self):
     TorState(FakeControlProtocol(), bootstrap=False, write_state_diagram=True)
     self.assertTrue(os.path.exists('routerfsm.dot'))
Exemplo n.º 10
0
 def setUp(self):
     self.controller = TorState(TorControlProtocol())
     self.controller.connectionMade = lambda _: None
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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")))
Exemplo n.º 13
0
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)