Ejemplo n.º 1
0
    def check_resolver(self, resolver):
        runner = test.runner.get_runner()

        if test.runner.Torrc.PORT not in runner.get_options():
            self.skipTest('(no control port)')
            return
        elif resolver not in system_resolvers():
            self.skipTest('(resolver unavailable on this platform)')
            return

        with runner.get_tor_socket():
            connections = get_connections(resolver,
                                          process_pid=runner.get_pid())

            for conn in connections:
                if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT:
                    return

            resolver_command = RESOLVER_COMMAND[resolver].format(
                pid=runner.get_pid())
            resolver_output = stem.util.system.call(resolver_command)

            self.fail(
                'Unable to find our controller connection with %s (%s). Connections found were...\n\n%s\n\nCommand output was...\n\n%s'
                % (resolver, resolver_command, '\n'.join(map(
                    str, connections)), resolver_output))
Ejemplo n.º 2
0
    def test_get_cwd_lsof(self):
        """
    Tests the get_pid_by_cwd function with a lsof response.
    """

        runner = test.runner.get_runner()

        if not stem.util.system.is_available('lsof'):
            test.runner.skip(self, '(lsof unavailable)')
            return
        elif not runner.is_ptraceable():
            test.runner.skip(self, '(DisableDebuggerAttachment is set)')
            return

        # filter the call function to only allow this command

        lsof_prefix = 'lsof -a -p '

        call_replacement = filter_system_call([lsof_prefix])

        with patch('stem.util.system.call') as call_mock:
            call_mock.side_effect = call_replacement

            runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
            self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
Ejemplo n.º 3
0
    def test_cwd_pwdx(self):
        """
    Tests the pid_by_cwd function with a pwdx response.
    """

        runner = test.runner.get_runner()

        if not stem.util.system.is_available('pwdx'):
            test.runner.skip(self, '(pwdx unavailable)')
            return
        elif not runner.is_ptraceable():
            test.runner.skip(self, '(DisableDebuggerAttachment is set)')
            return

        # filter the call function to only allow this command

        pwdx_prefix = stem.util.system.GET_CWD_PWDX % ''

        call_replacement = filter_system_call([pwdx_prefix])

        with patch('stem.util.system.call') as call_mock:
            call_mock.side_effect = call_replacement

            runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
            self.assertEqual(tor_cwd, stem.util.system.cwd(runner_pid))
Ejemplo n.º 4
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)))
Ejemplo n.º 5
0
  def test_get_pid_by_port(self):
    """
    Checks general usage of the stem.util.system.get_pid_by_port function.
    """

    runner = test.runner.get_runner()
    if stem.util.system.is_windows():
      test.runner.skip(self, "(unavailable on windows)")
      return
    elif not _has_port():
      test.runner.skip(self, "(test instance has no port)")
      return
    elif stem.util.system.is_mac():
      test.runner.skip(self, "(resolvers unavailable)")
      return
    elif not runner.is_ptraceable():
      test.runner.skip(self, "(DisableDebuggerAttachment is set)")
      return
    elif not (stem.util.system.is_available("netstat") or
              stem.util.system.is_available("sockstat") or
              stem.util.system.is_available("lsof")):
      test.runner.skip(self, "(connection resolvers unavailable)")
      return

    tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
    self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(tor_port))
    self.assertEquals(None, stem.util.system.get_pid_by_port(99999))
Ejemplo n.º 6
0
    def test_get_pid_by_port(self):
        """
    Checks general usage of the stem.util.system.get_pid_by_port function.
    """

        runner = test.runner.get_runner()
        if stem.util.system.is_windows():
            test.runner.skip(self, "(unavailable on windows)")
            return
        elif not _has_port():
            test.runner.skip(self, "(test instance has no port)")
            return
        elif stem.util.system.is_mac():
            test.runner.skip(self, "(resolvers unavailable)")
            return
        elif not runner.is_ptraceable():
            test.runner.skip(self, "(DisableDebuggerAttachment is set)")
            return
        elif not (stem.util.system.is_available("netstat")
                  or stem.util.system.is_available("sockstat")
                  or stem.util.system.is_available("lsof")):
            test.runner.skip(self, "(connection resolvers unavailable)")
            return

        tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
        self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(tor_port))
        self.assertEquals(None, stem.util.system.get_pid_by_port(99999))
Ejemplo n.º 7
0
  def test_cwd_lsof(self):
    """
    Tests the pid_by_cwd function with a lsof response.
    """

    runner = test.runner.get_runner()

    if not stem.util.system.is_available('lsof'):
      test.runner.skip(self, '(lsof unavailable)')
      return
    elif not runner.is_ptraceable():
      test.runner.skip(self, '(DisableDebuggerAttachment is set)')
      return

    # filter the call function to only allow this command

    lsof_prefix = 'lsof -a -p '

    call_replacement = filter_system_call([lsof_prefix])

    with patch('stem.util.system.call') as call_mock:
      call_mock.side_effect = call_replacement

      runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
      self.assertEqual(tor_cwd, stem.util.system.cwd(runner_pid))
Ejemplo n.º 8
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)))
Ejemplo n.º 9
0
    def test_cwd(self):
        """
    Checks that stem.util.proc.cwd matches our tor instance's cwd.
    """

        runner = test.runner.get_runner()
        runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
        self.assertEqual(tor_cwd, proc.cwd(runner_pid))
Ejemplo n.º 10
0
    def test_cwd(self):
        """
    Checks general usage of the stem.util.system.cwd function.
    """

        if stem.util.system.is_windows():
            self.skipTest('(unavailable on windows)')

        runner = test.runner.get_runner()
        runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
        self.assertEqual(tor_cwd, stem.util.system.cwd(runner_pid))
        self.assertEqual(None, stem.util.system.cwd(99999))
Ejemplo n.º 11
0
 def test_get_cwd(self):
   """
   Checks general usage of the stem.util.system.get_cwd function.
   """
   
   runner = test.runner.get_runner()
   
   if not runner.is_ptraceable():
     self.skipTest("(DisableDebuggerAttachment is set)")
   
   runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
   self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
   self.assertEquals(None, stem.util.system.get_cwd(99999))
Ejemplo n.º 12
0
  def test_cwd(self):
    """
    Checks general usage of the stem.util.system.cwd function.
    """

    if stem.util.system.is_windows():
      self.skipTest('(unavailable on windows)')
      return

    runner = test.runner.get_runner()
    runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
    self.assertEqual(tor_cwd, stem.util.system.cwd(runner_pid))
    self.assertEqual(None, stem.util.system.cwd(99999))
Ejemplo n.º 13
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)))
Ejemplo n.º 14
0
 def test_get_pid_by_port(self):
   """
   Checks general usage of the stem.util.system.get_pid_by_port function.
   """
   
   runner = test.runner.get_runner()
   if not _has_port():
     self.skipTest("(test instance has no port)")
   elif not runner.is_ptraceable():
     self.skipTest("(DisableDebuggerAttachment is set)")
   
   tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
   self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(tor_port))
   self.assertEquals(None, stem.util.system.get_pid_by_port(99999))
Ejemplo n.º 15
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)))
Ejemplo n.º 16
0
    def test_get_cwd(self):
        """
    Checks that stem.util.proc.get_cwd matches our tor instance's cwd.
    """

        if not proc.is_available():
            test.runner.skip(self, "(proc unavailable)")
            return
        elif not test.runner.get_runner().is_ptraceable():
            test.runner.skip(self, "(DisableDebuggerAttachment is set)")
            return

        runner = test.runner.get_runner()
        runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
        self.assertEquals(tor_cwd, proc.get_cwd(runner_pid))
Ejemplo n.º 17
0
  def test_get_cwd(self):
    """
    Checks that stem.util.proc.get_cwd matches our tor instance's cwd.
    """

    if not proc.is_available():
      test.runner.skip(self, "(proc unavailable)")
      return
    elif not test.runner.get_runner().is_ptraceable():
      test.runner.skip(self, "(DisableDebuggerAttachment is set)")
      return

    runner = test.runner.get_runner()
    runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
    self.assertEquals(tor_cwd, proc.get_cwd(runner_pid))
Ejemplo n.º 18
0
    def test_get_cwd(self):
        """
    Checks general usage of the stem.util.system.get_cwd function.
    """

        runner = test.runner.get_runner()

        if stem.util.system.is_windows():
            test.runner.skip(self, "(unavailable on windows)")
            return
        elif not runner.is_ptraceable():
            test.runner.skip(self, "(DisableDebuggerAttachment is set)")
            return

        runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
        self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
        self.assertEquals(None, stem.util.system.get_cwd(99999))
Ejemplo n.º 19
0
  def test_get_cwd(self):
    """
    Checks general usage of the stem.util.system.get_cwd function.
    """

    runner = test.runner.get_runner()

    if stem.util.system.is_windows():
      test.runner.skip(self, "(unavailable on windows)")
      return
    elif not runner.is_ptraceable():
      test.runner.skip(self, "(DisableDebuggerAttachment is set)")
      return

    runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
    self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
    self.assertEquals(None, stem.util.system.get_cwd(99999))
Ejemplo n.º 20
0
    def test_cwd_lsof(self):
        """
    Tests the pid_by_cwd function with a lsof response.
    """

        # filter the call function to only allow this command

        lsof_prefix = 'lsof -a -p '

        call_replacement = filter_system_call([lsof_prefix])

        with patch('stem.util.system.call') as call_mock:
            call_mock.side_effect = call_replacement

            runner = test.runner.get_runner()
            runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
            self.assertEqual(tor_cwd, stem.util.system.cwd(runner_pid))
Ejemplo n.º 21
0
  def test_cwd_lsof(self):
    """
    Tests the pid_by_cwd function with a lsof response.
    """

    # filter the call function to only allow this command

    lsof_prefix = 'lsof -a -p '

    call_replacement = filter_system_call([lsof_prefix])

    with patch('stem.util.system.call') as call_mock:
      call_mock.side_effect = call_replacement

      runner = test.runner.get_runner()
      runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
      self.assertEqual(tor_cwd, stem.util.system.cwd(runner_pid))
Ejemplo n.º 22
0
 def test_get_cwd_lsof(self):
   """
   Tests the get_pid_by_cwd function with a lsof response.
   """
   
   runner = test.runner.get_runner()
   if not stem.util.system.is_available("lsof"):
     self.skipTest("(lsof unavailable)")
   elif not runner.is_ptraceable():
     self.skipTest("(DisableDebuggerAttachment is set)")
   
   # filter the call function to only allow this command
   lsof_prefix = "lsof -a -p "
   mocking.mock(stem.util.system.call, filter_system_call([lsof_prefix]))
   
   runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
   self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
Ejemplo n.º 23
0
  def check_resolver(self, resolver):
    runner = test.runner.get_runner()

    if test.runner.Torrc.PORT not in runner.get_options():
      self.skipTest('(no control port)')
      return
    elif resolver not in system_resolvers():
      self.skipTest('(resolver unavailable on this platform)')
      return

    with runner.get_tor_socket():
      connections = get_connections(resolver, process_pid = runner.get_pid())

      for conn in connections:
        if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT:
          return

      self.fail('Unable to find localhost connection with %s:\n%s' % (resolver, '\n'.join(connections)))
Ejemplo n.º 24
0
    def test_pid_by_port(self):
        """
    Checks general usage of the stem.util.system.pid_by_port function.
    """

        if stem.util.system.is_windows():
            self.skipTest('(unavailable on windows)')
        elif stem.util.system.is_mac() or stem.util.system.is_gentoo():
            self.skipTest('(resolvers unavailable)')
        elif not stem.util.system.is_available('netstat') or \
                 stem.util.system.is_available('sockstat') or \
                  stem.util.system.is_available('lsof'):
            self.skipTest('(connection resolvers unavailable)')

        runner = test.runner.get_runner()
        tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
        self.assertEqual(tor_pid, stem.util.system.pid_by_port(tor_port))
        self.assertEqual(None, stem.util.system.pid_by_port(99999))
Ejemplo n.º 25
0
    def test_get_cwd_lsof(self):
        """
    Tests the get_pid_by_cwd function with a lsof response.
    """

        runner = test.runner.get_runner()
        if not stem.util.system.is_available("lsof"):
            test.runner.skip(self, "(lsof unavailable)")
            return
        elif not runner.is_ptraceable():
            test.runner.skip(self, "(DisableDebuggerAttachment is set)")
            return

        # filter the call function to only allow this command
        lsof_prefix = "lsof -a -p "
        mocking.mock(stem.util.system.call, filter_system_call([lsof_prefix]))

        runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
        self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
Ejemplo n.º 26
0
  def test_get_cwd_pwdx(self):
    """
    Tests the get_pid_by_cwd function with a pwdx response.
    """

    runner = test.runner.get_runner()
    if not stem.util.system.is_available("pwdx"):
      test.runner.skip(self, "(pwdx unavailable)")
      return
    elif not runner.is_ptraceable():
      test.runner.skip(self, "(DisableDebuggerAttachment is set)")
      return

    # filter the call function to only allow this command
    pwdx_prefix = stem.util.system.GET_CWD_PWDX % ""
    mocking.mock(stem.util.system.call, filter_system_call([pwdx_prefix]))

    runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
    self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
Ejemplo n.º 27
0
    def check_resolver(self, resolver):
        runner = test.runner.get_runner()

        if test.runner.Torrc.PORT not in runner.get_options():
            self.skipTest('(no control port)')
            return
        elif resolver not in system_resolvers():
            self.skipTest('(resolver unavailable on this platform)')
            return

        with runner.get_tor_socket():
            connections = get_connections(resolver,
                                          process_pid=runner.get_pid())

            for conn in connections:
                if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT:
                    return

            self.fail('Unable to find localhost connection with %s:\n%s' %
                      (resolver, '\n'.join(connections)))
Ejemplo n.º 28
0
  def test_pid_by_port(self):
    """
    Checks general usage of the stem.util.system.pid_by_port function.
    """

    if stem.util.system.is_windows():
      self.skipTest('(unavailable on windows)')
      return
    elif stem.util.system.is_mac() or stem.util.system.is_gentoo():
      self.skipTest('(resolvers unavailable)')
      return
    elif not (stem.util.system.is_available('netstat') or
              stem.util.system.is_available('sockstat') or
              stem.util.system.is_available('lsof')):
      self.skipTest('(connection resolvers unavailable)')
      return

    runner = test.runner.get_runner()
    tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
    self.assertEqual(tor_pid, stem.util.system.pid_by_port(tor_port))
    self.assertEqual(None, stem.util.system.pid_by_port(99999))