Esempio n. 1
0
 def test_download_key_does_not_create_directory_if_its_present(
         self, unused_mock_set_key_permissions, unused_mock_exists,
         mock_makedirs, mock_isdir):
     """Test that _download_key() does not create key dir if it's present."""
     host_utils._download_key(_TEST_KEY_SSH_PRIVATE)
     mock_isdir.assert_called_once_with(_EXPECTED_KEY_DIR)
     mock_makedirs.assert_not_called()
Esempio n. 2
0
 def test_download_key_sets_permissions_for_private_ssh_keys(
         self, mock_set_key_permissions, unused_mock_exists,
         unused_mock_makedirs, unused_mock_isdir):
     """Test that _download_key() changes permissions for SSH keys."""
     host_utils._download_key(_TEST_KEY_SSH_PRIVATE)
     mock_set_key_permissions.assert_called_once_with(
         _EXPECTED_KEY_SSH_PRIVATE_PATH)
Esempio n. 3
0
 def test_download_key_raises_if_key_isnt_downloaded(
         self, mock_exists, unused_mock_makedirs, unused_mock_isdir):
     """Test that _download_key() raises an error if key isn't downloaded."""
     error_regex = r"Key .*{}.* was not downloaded to {}".format(
         _TEST_KEY_SSH_PRIVATE_NAME, _EXPECTED_KEY_SSH_PRIVATE_PATH)
     with self.assertRaisesRegex(FileNotFoundError, error_regex):
         host_utils._download_key(_TEST_KEY_SSH_PRIVATE)
     mock_exists.assert_called_once_with(_EXPECTED_KEY_SSH_PRIVATE_PATH)
Esempio n. 4
0
 def test_download_key_creates_directory_if_its_absent(
         self, unused_mock_set_key_permissions, unused_mock_exists,
         mock_makedirs, mock_isdir):
     """Test that _download_key() creates package key dir if it's absent."""
     host_utils._download_key(_TEST_KEY_SSH_PRIVATE)
     mock_isdir.assert_called_once_with(_EXPECTED_KEY_DIR)
     mock_makedirs.assert_called_once_with(_EXPECTED_KEY_DIR)
     self.mock_download_key.assert_called_once_with(
         _TEST_KEY_SSH_PRIVATE, _EXPECTED_KEY_SSH_PRIVATE_PATH)
Esempio n. 5
0
 def test_download_key_doesnt_set_permissions_for_public_ssh_keys(
         self, mock_set_key_permissions, unused_mock_exists,
         unused_mock_mkdir, unused_mock_isdir):
     """Test that _download_key() doesn't set permissions for public SSH keys."""
     host_utils._download_key(_TEST_KEY_SSH_PUBLIC)
     mock_set_key_permissions.assert_not_called()
Esempio n. 6
0
 def test_download_key_doesnt_set_permissions_for_non_ssh_keys(
         self, mock_set_key_permissions, unused_mock_exists,
         unused_mock_makedirs, unused_mock_isdir):
     """Test that _download_key() doesn't change permissions for non-SSH keys."""
     host_utils._download_key(_TEST_KEY_OTHER)
     mock_set_key_permissions.assert_not_called()