From 42debc4cfdf22f72259e858d1e3e3a2ec5cf2bdd Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Mon, 3 Aug 2015 17:26:29 -0400 Subject: [PATCH] Test cases for better handling of SSH key comments sshd man page says: "The optional comment field continues to the end of the line, and is not used." http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8?query=sshd&sec=8 This bug has been fixed in upstream https://github.com/pyca/cryptography/issues/2199 Closes-Bug: #1481084 Depends-On: I28b7ab2e49ef4063a33c6122ea8355a16c3105a5 Change-Id: Ic157961a4282f0d54d4682d9374c170a66ddde5c --- nova/tests/unit/test_crypto.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nova/tests/unit/test_crypto.py b/nova/tests/unit/test_crypto.py index 0052af3f47..8db6c6fdf6 100644 --- a/nova/tests/unit/test_crypto.py +++ b/nova/tests/unit/test_crypto.py @@ -241,6 +241,12 @@ e6fCXWECgYEAqgpGvva5kJ1ISgNwnJbwiNw0sOT9BMOsdNZBElf0kJIIy6FMPvap raise exception.DecryptionFailure(reason=exc.stderr) def test_ssh_encrypt_decrypt_text(self): + self._test_ssh_encrypt_decrypt_text(self.pubkey) + key_with_spaces_in_comment = self.pubkey.replace('test@test', + 'Generated by Nova') + self._test_ssh_encrypt_decrypt_text(key_with_spaces_in_comment) + + def _test_ssh_encrypt_decrypt_text(self, key): enc = crypto.ssh_encrypt_text(self.pubkey, self.text) self.assertIsInstance(enc, bytes) # Comparison between bytes and str raises a TypeError @@ -322,6 +328,12 @@ class KeyPairTest(test.TestCase): "uYREz7iLRCP7BwUt8R+ZWzFZDeOLIWU= Generated-by-Nova" ) + ecdsa_pub_with_spaces = ( + "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAy" + "NTYAAABBBG1r4wzPTIjSo78POCq+u/czb8gYK0KvqlmCvcRPrnDWxgLw7y6BX51t" + "uYREz7iLRCP7BwUt8R+ZWzFZDeOLIWU= Generated by Nova" + ) + ecdsa_fp = "16:6a:c9:ec:80:4d:17:3e:d5:3b:6f:c0:d7:15:04:40" def test_generate_fingerprint(self): @@ -334,6 +346,9 @@ class KeyPairTest(test.TestCase): fingerprint = crypto.generate_fingerprint(self.ecdsa_pub) self.assertEqual(self.ecdsa_fp, fingerprint) + fingerprint = crypto.generate_fingerprint(self.ecdsa_pub_with_spaces) + self.assertEqual(self.ecdsa_fp, fingerprint) + def test_generate_key_pair_2048_bits(self): (private_key, public_key, fingerprint) = crypto.generate_key_pair() pub_bytes = public_key.encode('utf-8')