예제 #1
0
파일: process.py 프로젝트: sammyshj/stem
  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
파일: system.py 프로젝트: momor666/stem
  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
파일: process.py 프로젝트: neelchauhan/stem
    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
파일: process.py 프로젝트: soult/stem
    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
파일: process.py 프로젝트: neelchauhan/stem
    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
파일: process.py 프로젝트: sammyshj/stem
  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
파일: system.py 프로젝트: patrickod/stem
  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
파일: version.py 프로젝트: paraschetal/stem
  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
파일: process.py 프로젝트: sammyshj/stem
  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
파일: system.py 프로젝트: Fuzew/sharp-stem
  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
파일: process.py 프로젝트: soult/stem
    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
파일: process.py 프로젝트: neelchauhan/stem
    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
파일: process.py 프로젝트: eoinof/stem
 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
파일: process.py 프로젝트: abcdef123/stem
 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)