当前位置: 首页>>代码示例>>Python>>正文


Python runner.get_options函数代码示例

本文整理汇总了Python中test.runner.get_options函数的典型用法代码示例。如果您正苦于以下问题:Python get_options函数的具体用法?Python get_options怎么用?Python get_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_options函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: assert_matches_test_config

 def assert_matches_test_config(self, protocolinfo_response):
   """
   Makes assertions that the protocolinfo response's attributes match those of
   the test configuration.
   """
   
   runner = test.runner.get_runner()
   tor_options = runner.get_options()
   auth_methods, auth_cookie_path = [], None
   
   if test.runner.Torrc.COOKIE in tor_options:
     auth_methods.append(stem.response.protocolinfo.AuthMethod.COOKIE)
     chroot_path = runner.get_chroot()
     auth_cookie_path = runner.get_auth_cookie_path()
     
     if chroot_path and auth_cookie_path.startswith(chroot_path):
       auth_cookie_path = auth_cookie_path[len(chroot_path):]
   
   if test.runner.Torrc.PASSWORD in tor_options:
     auth_methods.append(stem.response.protocolinfo.AuthMethod.PASSWORD)
   
   if not auth_methods:
     auth_methods.append(stem.response.protocolinfo.AuthMethod.NONE)
   
   self.assertEqual((), protocolinfo_response.unknown_auth_methods)
   self.assertEqual(tuple(auth_methods), protocolinfo_response.auth_methods)
   self.assertEqual(auth_cookie_path, protocolinfo_response.cookie_path)
开发者ID:jacthinman,项目名称:Tor-Stem,代码行数:27,代码来源:protocolinfo.py

示例2: test_get_connections

  def test_get_connections(self):
    """
    Checks for our control port in the stem.util.proc.get_connections output if
    we have one.
    """

    runner = test.runner.get_runner()

    if not proc.is_available():
      test.runner.skip(self, "(proc unavailable)")
      return
    elif not test.runner.Torrc.PORT in runner.get_options():
      test.runner.skip(self, "(no control port)")
      return
    elif not test.runner.get_runner().is_ptraceable():
      test.runner.skip(self, "(DisableDebuggerAttachment is set)")
      return

    # making a controller connection so that we have something to query for
    with runner.get_tor_socket():
      tor_pid = test.runner.get_runner().get_pid()

      for conn in proc.get_connections(tor_pid):
        if ("127.0.0.1", test.runner.CONTROL_PORT) == conn[:2]:
          return

      self.fail()
开发者ID:bwrichte,项目名称:TorFinalProject,代码行数:27,代码来源:proc.py

示例3: test_protocolinfo

  def test_protocolinfo(self):
    """
    Test that the convenient method protocolinfo() works.
    """

    if test.runner.require_control(self):
      return

    runner = test.runner.get_runner()

    with runner.get_tor_controller(False) as controller:
      protocolinfo = controller.get_protocolinfo()
      self.assertTrue(isinstance(protocolinfo, stem.response.protocolinfo.ProtocolInfoResponse))

      # Doing a sanity test on the ProtocolInfoResponse instance returned.
      tor_options = runner.get_options()
      tor_version = runner.get_tor_version()
      auth_methods = []

      if test.runner.Torrc.COOKIE in tor_options:
        auth_methods.append(stem.response.protocolinfo.AuthMethod.COOKIE)

        if tor_version >= stem.version.Requirement.AUTH_SAFECOOKIE:
          auth_methods.append(stem.response.protocolinfo.AuthMethod.SAFECOOKIE)

      if test.runner.Torrc.PASSWORD in tor_options:
        auth_methods.append(stem.response.protocolinfo.AuthMethod.PASSWORD)

      if not auth_methods:
        auth_methods.append(stem.response.protocolinfo.AuthMethod.NONE)

      self.assertEqual(tuple(auth_methods), protocolinfo.auth_methods)
开发者ID:axitkhurana,项目名称:stem,代码行数:32,代码来源:controller.py

示例4: test_authenticate_general_password

 def test_authenticate_general_password(self):
   """
   Tests the authenticate function's password argument.
   """
   
   if test.runner.require_control(self): return
   
   # this is a much better test if we're just using password auth, since
   # authenticate will work reguardless if there's something else to
   # authenticate with
   
   runner = test.runner.get_runner()
   tor_options = runner.get_options()
   is_password_only = test.runner.Torrc.PASSWORD in tor_options and not test.runner.Torrc.COOKIE in tor_options
   
   # tests without a password
   with runner.get_tor_socket(False) as control_socket:
     if is_password_only:
       self.assertRaises(stem.connection.MissingPassword, stem.connection.authenticate, control_socket)
     else:
       stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())
       test.runner.exercise_controller(self, control_socket)
   
   # tests with the incorrect password
   with runner.get_tor_socket(False) as control_socket:
     if is_password_only:
       self.assertRaises(stem.connection.IncorrectPassword, stem.connection.authenticate, control_socket, "blarg")
     else:
       stem.connection.authenticate(control_socket, "blarg", runner.get_chroot())
       test.runner.exercise_controller(self, control_socket)
   
   # tests with the right password
   with runner.get_tor_socket(False) as control_socket:
     stem.connection.authenticate(control_socket, test.runner.CONTROL_PASSWORD, runner.get_chroot())
     test.runner.exercise_controller(self, control_socket)
开发者ID:abcdef123,项目名称:stem,代码行数:35,代码来源:authentication.py

示例5: test_authenticate_general_cookie

 def test_authenticate_general_cookie(self):
   """
   Tests the authenticate function with only cookie authentication methods.
   This manipulates our PROTOCOLINFO response to test each method
   individually.
   """
   
   if test.runner.require_control(self): return
   
   runner = test.runner.get_runner()
   tor_options = runner.get_options()
   is_cookie_only = test.runner.Torrc.COOKIE in tor_options and not test.runner.Torrc.PASSWORD in tor_options
   
   # test both cookie authentication mechanisms
   with runner.get_tor_socket(False) as control_socket:
     if is_cookie_only:
       for method in (stem.connection.AuthMethod.COOKIE, stem.connection.AuthMethod.SAFECOOKIE):
         protocolinfo_response = stem.connection.get_protocolinfo(control_socket)
         
         if method in protocolinfo_response.auth_methods:
           # narrow to *only* use cookie auth or safecooke, so we exercise
           # both independently
           
           protocolinfo_response.auth_methods = (method, )
           stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot(), protocolinfo_response = protocolinfo_response)
开发者ID:abcdef123,项目名称:stem,代码行数:25,代码来源:authentication.py

示例6: test_connections

  def test_connections(self):
    """
    Checks for our control port in the stem.util.proc.connections output if
    we have one.
    """

    runner = test.runner.get_runner()

    if not proc.is_available():
      test.runner.skip(self, '(proc unavailable)')
      return
    elif test.runner.Torrc.PORT not in runner.get_options():
      test.runner.skip(self, '(no control port)')
      return
    elif not test.runner.get_runner().is_ptraceable():
      test.runner.skip(self, '(DisableDebuggerAttachment is set)')
      return
    elif not os.access('/proc/net/tcp', os.R_OK) or not os.access('/proc/net/udp', os.R_OK):
      test.runner.skip(self, '(proc lacks read permissions)')
      return

    # making a controller connection so that we have something to query for
    with runner.get_tor_socket():
      tor_pid = test.runner.get_runner().get_pid()

      for conn in proc.connections(tor_pid):
        if ('127.0.0.1', test.runner.CONTROL_PORT) == conn[:2]:
          return

      self.fail()
开发者ID:FedericoCeratto,项目名称:stem,代码行数:30,代码来源:proc.py

示例7: _can_authenticate

def _can_authenticate(auth_type):
  """
  Checks if a given authentication method can authenticate to our control
  socket.

  :param stem.connection.AuthMethod auth_type: authentication method to check

  :returns: bool that's True if we should be able to authenticate and False otherwise
  """

  runner = test.runner.get_runner()
  tor_options = runner.get_options()
  password_auth = test.runner.Torrc.PASSWORD in tor_options
  cookie_auth = test.runner.Torrc.COOKIE in tor_options
  safecookie_auth = cookie_auth and runner.get_tor_version() >= stem.version.Requirement.AUTH_SAFECOOKIE

  if not password_auth and not cookie_auth:
    # open socket, anything but safecookie will work
    return auth_type != stem.connection.AuthMethod.SAFECOOKIE
  elif auth_type == stem.connection.AuthMethod.PASSWORD:
    return password_auth
  elif auth_type == stem.connection.AuthMethod.COOKIE:
    return cookie_auth
  elif auth_type == stem.connection.AuthMethod.SAFECOOKIE:
    return safecookie_auth
  else:
    return False
开发者ID:FedericoCeratto,项目名称:stem,代码行数:27,代码来源:authentication.py

示例8: test_authenticate_general_example

  def test_authenticate_general_example(self):
    """
    Tests the authenticate function with something like its pydoc example.
    """

    runner = test.runner.get_runner()
    tor_options = runner.get_options()

    try:
      control_socket = stem.socket.ControlPort(port = test.runner.CONTROL_PORT)
    except stem.SocketError:
      # assert that we didn't have a socket to connect to
      self.assertFalse(test.runner.Torrc.PORT in tor_options)
      return

    try:
      # this authenticate call should work for everything but password-only auth
      stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())
      test.runner.exercise_controller(self, control_socket)
    except stem.connection.IncorrectSocketType:
      self.fail()
    except stem.connection.MissingPassword:
      self.assertTrue(test.runner.Torrc.PASSWORD in tor_options)
      controller_password = test.runner.CONTROL_PASSWORD

      try:
        stem.connection.authenticate_password(control_socket, controller_password)
        test.runner.exercise_controller(self, control_socket)
      except stem.connection.PasswordAuthFailed:
        self.fail()
    except stem.connection.AuthenticationFailure:
      self.fail()
    finally:
      control_socket.close()
开发者ID:FedericoCeratto,项目名称:stem,代码行数:34,代码来源:authentication.py

示例9: test_wrong_password_with_controller

  def test_wrong_password_with_controller(self):
    """
    We ran into a race condition where providing the wrong password to the
    Controller caused inconsistent responses. Checking for that...

    https://trac.torproject.org/projects/tor/ticket/22679
    """

    runner = test.runner.get_runner()

    if test.runner.Torrc.PASSWORD not in runner.get_options() or test.runner.Torrc.COOKIE in runner.get_options():
      self.skipTest('(requires only password auth)')
      return

    for i in range(10):
      with runner.get_tor_controller(False) as controller:
        self.assertRaises(stem.connection.IncorrectPassword, controller.authenticate, 'wrong_password')
开发者ID:patrickod,项目名称:stem,代码行数:17,代码来源:authentication.py

示例10: test_connect_socket_file

 def test_connect_socket_file(self):
   """
   Basic sanity checks for the connect_socket_file function.
   """
   
   runner = test.runner.get_runner()
   
   control_socket = stem.connection.connect_socket_file(
     socket_path = test.runner.CONTROL_SOCKET_PATH,
     password = test.runner.CONTROL_PASSWORD,
     chroot_path = runner.get_chroot(),
     controller = None)
   
   if test.runner.Torrc.SOCKET in runner.get_options():
     test.runner.exercise_controller(self, control_socket)
     control_socket.close()
   else:
     self.assertEquals(control_socket, None)
开发者ID:jacthinman,项目名称:Tor-Stem,代码行数:18,代码来源:connect.py

示例11: check_resolver

  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)))
开发者ID:patrickod,项目名称:stem,代码行数:18,代码来源:connection.py

示例12: test_get_listeners

  def test_get_listeners(self):
    """
    Test Controller.get_listeners against a running tor instance.
    """

    runner = test.runner.get_runner()

    with runner.get_tor_controller() as controller:
      self.assertEqual([], controller.get_listeners(Listener.OR))
      self.assertEqual([], controller.get_listeners(Listener.DIR))
      self.assertEqual([('127.0.0.1', test.runner.SOCKS_PORT)], controller.get_listeners(Listener.SOCKS))
      self.assertEqual([], controller.get_listeners(Listener.TRANS))
      self.assertEqual([], controller.get_listeners(Listener.NATD))
      self.assertEqual([], controller.get_listeners(Listener.DNS))

      if test.runner.Torrc.PORT in runner.get_options():
        self.assertEqual([('127.0.0.1', test.runner.CONTROL_PORT)], controller.get_listeners(Listener.CONTROL))
      else:
        self.assertEqual([], controller.get_listeners(Listener.CONTROL))
开发者ID:patrickod,项目名称:stem,代码行数:19,代码来源:controller.py

示例13: test_connect_port

 def test_connect_port(self):
   """
   Basic sanity checks for the connect_port function.
   """
   
   if test.runner.require_control(self): return
   
   runner = test.runner.get_runner()
   
   control_socket = stem.connection.connect_port(
     control_port = test.runner.CONTROL_PORT,
     password = test.runner.CONTROL_PASSWORD,
     chroot_path = runner.get_chroot(),
     controller = None)
   
   if test.runner.Torrc.PORT in runner.get_options():
     test.runner.exercise_controller(self, control_socket)
     control_socket.close()
   else:
     self.assertEquals(control_socket, None)
开发者ID:abcdef123,项目名称:stem,代码行数:20,代码来源:connect.py


注:本文中的test.runner.get_options函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。