Пример #1
0
  def test_launch_tor_with_config_via_file(self):
    """
    Exercises launch_tor_with_config when we write a torrc to disk.
    """

    # Launch tor without a torrc, but with a control port. Confirms that this
    # works by checking that we're still able to access the new instance.

    runner = test.runner.get_runner()
    tor_process = stem.process.launch_tor_with_config(
      tor_cmd = runner.get_tor_command(),
      config = {
        'SocksPort': '2777',
        'ControlPort': '2778',
        'DataDirectory': self.data_directory,
      },
      completion_percent = 5
    )

    control_socket = None
    try:
      control_socket = stem.socket.ControlPort(port = 2778)
      stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())

      # exercises the socket
      control_socket.send('GETCONF ControlPort')
      getconf_response = control_socket.recv()
      self.assertEqual('ControlPort=2778', str(getconf_response))
    finally:
      if control_socket:
        control_socket.close()

      tor_process.kill()
      tor_process.wait()
Пример #2
0
  def test_pid_by_name_tasklist(self):
    """
    Tests the pid_by_name function with a tasklist response.
    """

    runner = test.runner.get_runner()
    self.assertEqual(runner.get_pid(), stem.util.system.pid_by_name(runner.get_tor_command(True)))
Пример #3
0
    def test_launch_tor_with_config_via_stdin(self):
        """
    Exercises launch_tor_with_config when we provide our torrc via stdin.
    """

        runner = test.runner.get_runner()
        tor_process = stem.process.launch_tor_with_config(
            tor_cmd=runner.get_tor_command(),
            config={
                'SocksPort': '2777',
                'ControlPort': '2778',
                'DataDirectory': self.data_directory,
            },
            completion_percent=5)

        control_socket = None
        try:
            control_socket = stem.socket.ControlPort(port=2778)
            stem.connection.authenticate(control_socket,
                                         chroot_path=runner.get_chroot())

            # exercises the socket
            control_socket.send('GETCONF ControlPort')
            getconf_response = control_socket.recv()
            self.assertEqual('ControlPort=2778', str(getconf_response))
        finally:
            if control_socket:
                control_socket.close()

            tor_process.kill()
            tor_process.wait()
Пример #4
0
    def test_launch_tor_with_config(self):
        """
    Exercises launch_tor_with_config.
    """

        if test.runner.only_run_once(self, "test_launch_tor_with_config"):
            return

        # Launch tor without a torrc, but with a control port. Confirms that this
        # works by checking that we're still able to access the new instance.

        runner = test.runner.get_runner()
        tor_process = stem.process.launch_tor_with_config(
            tor_cmd=runner.get_tor_command(),
            config={"SocksPort": "2777", "ControlPort": "2778", "DataDirectory": self.data_directory},
            completion_percent=5,
        )

        control_socket = None
        try:
            control_socket = stem.socket.ControlPort(port=2778)
            stem.connection.authenticate(control_socket, chroot_path=runner.get_chroot())

            # exercises the socket
            control_socket.send("GETCONF ControlPort")
            getconf_response = control_socket.recv()
            self.assertEquals("ControlPort=2778", str(getconf_response))
        finally:
            if control_socket:
                control_socket.close()

            tor_process.kill()
            tor_process.communicate()
Пример #5
0
    def test_launch_tor_with_config_via_file(self):
        """
    Exercises launch_tor_with_config when we write a torrc to disk.
    """

        # Launch tor without a torrc, but with a control port. Confirms that this
        # works by checking that we're still able to access the new instance.

        runner = test.runner.get_runner()
        tor_process = stem.process.launch_tor_with_config(
            tor_cmd=runner.get_tor_command(),
            config={
                'SocksPort': '2777',
                'ControlPort': '2778',
                'DataDirectory': self.data_directory,
            },
            completion_percent=5)

        control_socket = None
        try:
            control_socket = stem.socket.ControlPort(port=2778)
            stem.connection.authenticate(control_socket,
                                         chroot_path=runner.get_chroot())

            # exercises the socket
            control_socket.send('GETCONF ControlPort')
            getconf_response = control_socket.recv()
            self.assertEqual('ControlPort=2778', str(getconf_response))
        finally:
            if control_socket:
                control_socket.close()

            tor_process.kill()
            tor_process.wait()
Пример #6
0
  def test_launch_tor_with_config_via_stdin(self):
    """
    Exercises launch_tor_with_config when we provide our torrc via stdin.
    """

    runner = test.runner.get_runner()
    tor_process = stem.process.launch_tor_with_config(
      tor_cmd = runner.get_tor_command(),
      config = {
        'SocksPort': '2777',
        'ControlPort': '2778',
        'DataDirectory': self.data_directory,
      },
      completion_percent = 5
    )

    control_socket = None
    try:
      control_socket = stem.socket.ControlPort(port = 2778)
      stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())

      # exercises the socket
      control_socket.send('GETCONF ControlPort')
      getconf_response = control_socket.recv()
      self.assertEqual('ControlPort=2778', str(getconf_response))
    finally:
      if control_socket:
        control_socket.close()

      tor_process.kill()
      tor_process.wait()
Пример #7
0
  def test_pid_by_name_tasklist(self):
    """
    Tests the pid_by_name function with a tasklist response.
    """

    runner = test.runner.get_runner()
    self.assertEqual(runner.get_pid(), stem.util.system.pid_by_name(runner.get_tor_command(True)))
Пример #8
0
  def test_get_system_tor_version_value(self):
    """
    Checks that the get_system_tor_version() provides the same value as our
    test instance provides.
    """

    runner = test.runner.get_runner()
    system_tor_version = stem.version.get_system_tor_version(runner.get_tor_command())
    self.assertEqual(runner.get_tor_version(), system_tor_version)
Пример #9
0
  def test_launch_tor_with_timeout(self):
    """
    Runs launch_tor where it times out before completing.
    """

    runner = test.runner.get_runner()
    start_time = time.time()
    config = {'SocksPort': '2777', 'DataDirectory': self.data_directory}
    self.assertRaises(OSError, stem.process.launch_tor_with_config, config, runner.get_tor_command(), 100, None, 2)
    runtime = time.time() - start_time

    if not (runtime > 2 and runtime < 3):
      self.fail('Test should have taken 2-3 seconds, took %0.1f instead' % runtime)
Пример #10
0
  def test_pid_by_name_tasklist(self):
    """
    Tests the pid_by_name function with a tasklist response.
    """

    if self._is_extra_tor_running():
      test.runner.skip(self, '(multiple tor instances)')
      return
    elif not stem.util.system.is_available('tasklist'):
      test.runner.skip(self, '(tasklist unavailable)')
      return

    runner = test.runner.get_runner()
    self.assertEqual(runner.get_pid(), stem.util.system.pid_by_name(runner.get_tor_command(True)))
Пример #11
0
  def test_pid_by_name_tasklist(self):
    """
    Tests the pid_by_name function with a tasklist response.
    """

    if self._is_extra_tor_running():
      test.runner.skip(self, '(multiple tor instances)')
      return
    elif not stem.util.system.is_available('tasklist'):
      test.runner.skip(self, '(tasklist unavailable)')
      return

    runner = test.runner.get_runner()
    self.assertEqual(runner.get_pid(), stem.util.system.pid_by_name(runner.get_tor_command(True)))
Пример #12
0
    def test_launch_tor_with_timeout(self):
        """
    Runs launch_tor where it times out before completing.
    """

        if test.runner.only_run_once(self, "test_launch_tor_with_timeout"):
            return

        runner = test.runner.get_runner()
        start_time = time.time()
        config = {"SocksPort": "2777", "DataDirectory": self.data_directory}
        self.assertRaises(OSError, stem.process.launch_tor_with_config, config, runner.get_tor_command(), 100, None, 2)
        runtime = time.time() - start_time

        if not (runtime > 2 and runtime < 3):
            self.fail("Test should have taken 2-3 seconds, took %i instead" % runtime)
Пример #13
0
    def test_launch_tor_with_timeout(self):
        """
    Runs launch_tor where it times out before completing.
    """

        runner = test.runner.get_runner()
        start_time = time.time()
        config = {'SocksPort': '2777', 'DataDirectory': self.data_directory}
        self.assertRaises(OSError, stem.process.launch_tor_with_config, config,
                          runner.get_tor_command(), 100, None, 2)
        runtime = time.time() - start_time

        if not (runtime > 2 and runtime < 3):
            self.fail(
                'Test should have taken 2-3 seconds, took %0.1f instead' %
                runtime)
Пример #14
0
 def test_launch_tor_with_config(self):
   """
   Exercises launch_tor_with_config.
   """
   
   if not stem.prereq.is_python_26() and stem.util.system.is_windows():
     test.runner.skip(self, "(unable to kill subprocesses)")
     return
   
   if test.runner.only_run_once(self, "test_launch_tor_with_config"): return
   
   # Launch tor without a torrc, but with a control port. Confirms that this
   # works by checking that we're still able to access the new instance.
   
   runner = test.runner.get_runner()
   tor_process = stem.process.launch_tor_with_config(
     tor_cmd = runner.get_tor_command(),
     config = {'SocksPort': '2777', 'ControlPort': '2778'},
     completion_percent = 5
   )
   
   control_socket = None
   try:
     control_socket = stem.socket.ControlPort(control_port = 2778)
     stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())
     
     # exercises the socket
     control_socket.send("GETCONF ControlPort")
     getconf_response = control_socket.recv()
     self.assertEquals("ControlPort=2778", str(getconf_response))
   finally:
     if control_socket: control_socket.close()
     
     if stem.prereq.is_python_26():
       tor_process.kill()
     elif not stem.util.system.is_windows():
       os.kill(tor_process.pid, signal.SIGTERM)
       
       # On OSX, python 2.5 this kill call doesn't seem to block, causing our
       # tor instance to linger and cause a port conflict with the following
       # test. Giving it a moment to kill for realz.
       
       time.sleep(0.5)
Пример #15
0
 def test_launch_tor_with_timeout(self):
   """
   Runs launch_tor where it times out before completing.
   """
   
   if not stem.prereq.is_python_26() and stem.util.system.is_windows():
     test.runner.skip(self, "(unable to kill subprocesses)")
     return
   
   if test.runner.only_run_once(self, "test_launch_tor_with_timeout"): return
   
   runner = test.runner.get_runner()
   start_time = time.time()
   config = {'SocksPort': '2777', 'DataDirectory': DATA_DIRECTORY}
   self.assertRaises(OSError, stem.process.launch_tor_with_config, config, runner.get_tor_command(), 100, None, 2)
   runtime = time.time() - start_time
   
   if not (runtime > 2 and runtime < 3):
     self.fail("Test should have taken 2-3 seconds, took %i instead" % runtime)
Пример #16
0
  def test_launch_tor_with_timeout(self):
    """
    Runs launch_tor where it times out before completing.
    """

    if not stem.prereq.is_python_26() and stem.util.system.is_windows():
      test.runner.skip(self, "(unable to kill subprocesses)")
      return

    if test.runner.only_run_once(self, "test_launch_tor_with_timeout"):
      return

    runner = test.runner.get_runner()
    start_time = time.time()
    config = {'SocksPort': '2777', 'DataDirectory': self.data_directory}
    self.assertRaises(OSError, stem.process.launch_tor_with_config, config, runner.get_tor_command(), 100, None, 2)
    runtime = time.time() - start_time

    if not (runtime > 2 and runtime < 3):
      self.fail("Test should have taken 2-3 seconds, took %i instead" % runtime)
Пример #17
0
  def test_launch_tor_with_config(self):
    """
    Exercises launch_tor_with_config.
    """

    if not stem.prereq.is_python_26() and stem.util.system.is_windows():
      test.runner.skip(self, "(unable to kill subprocesses)")
      return

    if test.runner.only_run_once(self, "test_launch_tor_with_config"):
      return

    # Launch tor without a torrc, but with a control port. Confirms that this
    # works by checking that we're still able to access the new instance.

    runner = test.runner.get_runner()
    tor_process = stem.process.launch_tor_with_config(
      tor_cmd = runner.get_tor_command(),
      config = {
        'SocksPort': '2777',
        'ControlPort': '2778',
        'DataDirectory': self.data_directory,
      },
      completion_percent = 5
    )

    control_socket = None
    try:
      control_socket = stem.socket.ControlPort(port = 2778)
      stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())

      # exercises the socket
      control_socket.send("GETCONF ControlPort")
      getconf_response = control_socket.recv()
      self.assertEquals("ControlPort=2778", str(getconf_response))
    finally:
      if control_socket:
        control_socket.close()

      _kill_process(tor_process)
Пример #18
0
    def test_launch_tor_with_config(self):
        """
    Exercises launch_tor_with_config.
    """

        if not stem.prereq.is_python_26() and stem.util.system.is_windows():
            test.runner.skip(self, "(unable to kill subprocesses)")
            return

        if test.runner.only_run_once(self, "test_launch_tor_with_config"):
            return

        # Launch tor without a torrc, but with a control port. Confirms that this
        # works by checking that we're still able to access the new instance.

        runner = test.runner.get_runner()
        tor_process = stem.process.launch_tor_with_config(
            tor_cmd=runner.get_tor_command(),
            config={
                'SocksPort': '2777',
                'ControlPort': '2778',
                'DataDirectory': DATA_DIRECTORY,
            },
            completion_percent=5)

        control_socket = None
        try:
            control_socket = stem.socket.ControlPort(control_port=2778)
            stem.connection.authenticate(control_socket,
                                         chroot_path=runner.get_chroot())

            # exercises the socket
            control_socket.send("GETCONF ControlPort")
            getconf_response = control_socket.recv()
            self.assertEquals("ControlPort=2778", str(getconf_response))
        finally:
            if control_socket:
                control_socket.close()

            _kill_process(tor_process)