From c2725eb77e18d20d8facb69ecbb7c36ed99d4aeb Mon Sep 17 00:00:00 2001 From: Kendrick Cline Date: Sat, 19 Aug 2017 20:38:23 -0400 Subject: [PATCH] KMS: fixes the kms failing tests. Fix the tests introduced in #816. Some code was still calling encrypt(...) with a key version. --- kms/src/test/java/com/example/SnippetsIT.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/kms/src/test/java/com/example/SnippetsIT.java b/kms/src/test/java/com/example/SnippetsIT.java index fe37acbd70c..a36b0a7033f 100644 --- a/kms/src/test/java/com/example/SnippetsIT.java +++ b/kms/src/test/java/com/example/SnippetsIT.java @@ -259,21 +259,15 @@ public void addAndRemoveMemberToKeyRingPolicy_addsDisplaysAndRemoves() throws Ex @Test public void encryptDecrypt_encryptsAndDecrypts() throws Exception { - // Get an enabled crypto key version, since the primary version is likely disabled - Snippets.listCryptoKeyVersions(PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID); - Matcher matcher = Pattern.compile(".*cryptoKeyVersions/(\\d+)\",\"state\":\"ENABLED\".*", - Pattern.DOTALL | Pattern.MULTILINE).matcher(bout.toString().trim()); - assertTrue(matcher.matches()); - String version = matcher.group(1); - - byte[] encrypted = CryptFile.encrypt( - PROJECT_ID, KEY_RING_ID, CRYPTO_KEY_ID, version, ENCRYPT_STRING.getBytes()); + // Encrypt ENCRYPT_STRING with the current primary version. + byte[] ciphertext = CryptFile.encrypt( + PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, ENCRYPT_STRING.getBytes()); - assertThat(new String(encrypted)).isNotEqualTo(ENCRYPT_STRING); + assertThat(new String(ciphertext)).isNotEqualTo(ENCRYPT_STRING); - byte[] decrypted = CryptFile.decrypt( - PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, encrypted); + byte[] plaintext = CryptFile.decrypt( + PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, ciphertext); - assertThat(new String(decrypted)).isEqualTo(ENCRYPT_STRING); + assertThat(new String(plaintext)).isEqualTo(ENCRYPT_STRING); } }