torproject / stem

Python controller library for Tor
https://stem.torproject.org/
GNU Lesser General Public License v3.0
260 stars 75 forks source link

End-to-end integ test for hidden service #34

Open atagar opened 4 years ago

atagar commented 4 years ago

Migrated from ticket 15999.

While adding support for ephemeral hidden services I tried to add a end-to-end integ test without success. Ideally the test would create a new hidden service, then use tor to retrieve its content.

Really shouldn't be a big whoop. We have a tutorial for something similar after all. But for some reason even the tutorial wasn't working for me (hidden service was inaccessible)...

  @require_online
  @require_controller
  @require_version(Requirement.ADD_ONION)
  def test_using_ephemeral_hidden_services(self):
    """  
    Create and use a live ephemeral hidden service.
    """

    # TODO: Not having success getting... well, just about any damn hidden
    # serivce working. Even our prior tutorial is failing right now. >:(

    return

    with test.runner.get_runner().get_tor_controller() as controller:
      incoming_address = None, None 

      def run_server():
        serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        serversocket.bind(('localhost', 4567))
        serversocket.listen(5)
        incoming_socket, incoming_address = serversocket.accept()
        incoming_socket.write('hello world')
        serversocket.shutdown(socket.SHUT_RDWR)

      server_thread = threading.Thread(target = run_server)
      server_thread.setDaemon(True)
      server_thread.start()

      response = controller.create_ephemeral_hidden_service({80: 4567})

      with test.network.Socks(controller.get_socks_listeners()[0]) as s:
        s.settimeout(30)
        s.connect(('%s.onion' % response.service_id, 80)) 
        print s.read()

      self.assertTrue(incoming_address is not None)

      server_thread.join()

rj76 mentioned having a branch that might cover this.