text: #!/bin/env python
  
  # Import modules
  import unittest
  import platform
  import paramiko
  import logging
  
  # Standard testing strategy: try to check each side of each branch statement
  # for correctness
  
  # Test basic host-based authentication for Paramiko
  class HostBasedAuthTestCase(unittest.TestCase):
      """Test Paramiko host-based auth patch"""
  
      #@unittest.skipUnless(platform.node().startswith('bohr'), 'Requires q200 hosts')
      def test_hostbased(self):
          """Test between host-auth allowed bohr nodes"""
  
          # Check and make sure this is a bohr node
          host = platform.node()
              
          # Short circuit the test on non-bohr nodes
          if not host.startswith('bohr'):
  	    return
  
          # Choose a destination
          dest = 'bohr04'
  	if host.startswith('bohr04'):
              dest = 'bohr03'
  
          # Try to load key
          candidates = ['/etc/ssh/ssh_host_rsa_key.pub', '/etc/ssh_host_rsa_key.pub']
          for candidate in candidates:
              try:
                  match = paramiko.opensshkey.load_pubkey_from_file(candidate)
                  break
              except paramiko.SSHException:
                  print 'Unable to load', candidate
                  pass
          self.assertNotEqual(None, match)
  
          # Try to connect
          logging.basicConfig()
          ssh = paramiko.SSHClient()
  	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          try:
              ssh.connect(dest, hostkey=match)
          except paramiko.AuthenticationException:
              self.assertEqual(0, 1, 'Host-based authentication failed')
  
      #@unittest.skipUnless(platform.node().startswith('bohr'), 'Requires q200 hosts')
      def test_invalid_hostbased(self):
          """Test construction with an invalid hostname"""
  
          # Check and make sure this is a bohr node
          host = platform.node()
  
          # Short circuit the test on non-bohr nodes
          if not host.startswith('bohr'):
              return
  
          # Choose a destination
          dest = 'home.ccs.ornl.gov'
  
          # Try to load key
          candidates = ['/etc/ssh/ssh_host_rsa_key.pub', '/etc/ssh_host_rsa_key.pub']
          for candidate in candidates:
              try:
                  match = paramiko.opensshkey.load_pubkey_from_file(candidate)
                  break
              except paramiko.SSHException:
                  print 'Unable to load', candidate
                  pass
          self.assertNotEqual(None, match)
  
          # Try to connect
          logging.basicConfig()
          ssh = paramiko.SSHClient()
          ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          try:
              ssh.connect(dest, hostkey=match)
              self.assertEqual(0, 1, 'Host-based authentication worked when it should not have')
          except paramiko.AuthenticationException:
              self.assertEqual(0, 0)
  
  
              
  if __name__ == '__main__':
      unittest.main()
  