Example #1
0
 def test_set_key_permissions_already_correct(self, mock_chmod):
     """Test _set_key_permissions for already correct permissions."""
     mock_stat_result = mock.Mock()
     mock_stat_result.st_mode = int("400", 8)
     with mock.patch.object(os, "stat", return_value=mock_stat_result):
         host_utils._set_key_permissions(_EXPECTED_KEY_SSH_PRIVATE_PATH)
     mock_chmod.assert_not_called()
Example #2
0
 def test_set_key_permissions_incorrect_permissions_failure(self, mock_chmod):
   """Test _set_key_permissions failing to correct permissions."""
   mock_stat_result = mock.Mock()
   mock_stat_result.st_mode = int("644", 8)
   with mock.patch.object(os, "stat", return_value=mock_stat_result):
     with self.assertRaisesRegex(ValueError, "Unable to change permissions"):
       host_utils._set_key_permissions(_EXPECTED_KEY_SSH_PRIVATE_PATH)
   mock_chmod.assert_called_once_with(_EXPECTED_KEY_SSH_PRIVATE_PATH,
                                      int("400", 8))