boot_data_test.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env vpython3
  2. # Copyright 2021 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import boot_data
  6. import os
  7. import unittest
  8. from boot_data import _SSH_CONFIG_DIR, _SSH_DIR, _GetAuthorizedKeysPath, \
  9. GetSSHConfigPath
  10. class TestBootData(unittest.TestCase):
  11. def testProvisionSSHGeneratesFiles(self):
  12. fuchsia_authorized_keys_path = _GetAuthorizedKeysPath()
  13. fuchsia_id_key_path = os.path.join(_SSH_DIR, 'fuchsia_ed25519')
  14. fuchsia_pub_key_path = os.path.join(_SSH_DIR, 'fuchsia_ed25519.pub')
  15. ssh_config_path = GetSSHConfigPath()
  16. # Check if the keys exists before generating. If they do, delete them
  17. # afterwards before asserting if ProvisionSSH works.
  18. authorized_key_before = os.path.exists(fuchsia_authorized_keys_path)
  19. id_keys_before = os.path.exists(fuchsia_id_key_path)
  20. pub_keys_before = os.path.exists(fuchsia_pub_key_path)
  21. ssh_config_before = os.path.exists(ssh_config_path)
  22. ssh_dir_before = os.path.exists(_SSH_CONFIG_DIR)
  23. boot_data.ProvisionSSH()
  24. authorized_key_after = os.path.exists(fuchsia_authorized_keys_path)
  25. id_keys_after = os.path.exists(fuchsia_id_key_path)
  26. ssh_config_after = os.path.exists(ssh_config_path)
  27. if not authorized_key_before:
  28. os.remove(fuchsia_authorized_keys_path)
  29. if not id_keys_before:
  30. os.remove(fuchsia_id_key_path)
  31. if not pub_keys_before:
  32. os.remove(fuchsia_pub_key_path)
  33. if not ssh_config_before:
  34. os.remove(ssh_config_path)
  35. if not ssh_dir_before:
  36. os.rmdir(_SSH_CONFIG_DIR)
  37. self.assertTrue(os.path.exists(authorized_key_after))
  38. self.assertTrue(os.path.exists(id_keys_after))
  39. self.assertTrue(os.path.exists(ssh_config_after))
  40. if __name__ == '__main__':
  41. unittest.main()