def testRemoveKnownHostDefaultFile(self):
    """Tests RemoveKnownHost() on the default known_hosts file.

    `ssh-keygen -R` on its own fails when run from within the chroot
    since the default known_hosts is bind mounted.
    """
    # It doesn't matter if known_hosts actually has this host in it or not,
    # this test just makes sure the command doesn't fail. The default
    # known_hosts file always exists in the chroot due to the bind mount.
    remote_access.RemoveKnownHost(self._HOST)
示例#2
0
 def Run(self):
     """Runs `cros shell`."""
     self.options.Freeze()
     self._ReadOptions()
     try:
         return self._StartSsh()
     except remote_access.SSHConnectionError as e:
         # Handle a mismatched host key; mismatched keys are a bit of a pain to
         # fix manually since `ssh-keygen -R` doesn't work within the chroot.
         if e.IsKnownHostsMismatch():
             # The full SSH error message has extra info for the user.
             logging.warning('\n%s', e)
             if self._UserConfirmKeyChange():
                 remote_access.RemoveKnownHost(self.device.hostname)
                 # The user already OK'd so we can skip the additional SSH check.
                 self.host_key_checking = 'no'
                 return self._StartSsh()
             else:
                 return 1
         raise
 def testRemoveKnownHostNonexistentFile(self):
   """Tests RemoveKnownHost() on a nonexistent known_hosts file."""
   path = os.path.join(self.tempdir, 'known_hosts')
   remote_access.RemoveKnownHost(self._HOST, known_hosts_path=path)
 def testRemoveKnownHostCustomFile(self):
   """Tests RemoveKnownHost() on a custom known_hosts file."""
   path = os.path.join(self.tempdir, 'known_hosts')
   osutils.WriteFile(path, self._HOST_KEY)
   remote_access.RemoveKnownHost(self._HOST, known_hosts_path=path)
   self.assertEqual(osutils.ReadFile(path), '')