Skip to content

Commit c2725eb

Browse files
committed
KMS: fixes the kms failing tests.
Fix the tests introduced in GoogleCloudPlatform#816. Some code was still calling encrypt(...) with a key version.
1 parent 6661719 commit c2725eb

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

kms/src/test/java/com/example/SnippetsIT.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,15 @@ public void addAndRemoveMemberToKeyRingPolicy_addsDisplaysAndRemoves() throws Ex
259259

260260
@Test
261261
public void encryptDecrypt_encryptsAndDecrypts() throws Exception {
262-
// Get an enabled crypto key version, since the primary version is likely disabled
263-
Snippets.listCryptoKeyVersions(PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID);
264-
Matcher matcher = Pattern.compile(".*cryptoKeyVersions/(\\d+)\",\"state\":\"ENABLED\".*",
265-
Pattern.DOTALL | Pattern.MULTILINE).matcher(bout.toString().trim());
266-
assertTrue(matcher.matches());
267-
String version = matcher.group(1);
268-
269-
byte[] encrypted = CryptFile.encrypt(
270-
PROJECT_ID, KEY_RING_ID, CRYPTO_KEY_ID, version, ENCRYPT_STRING.getBytes());
262+
// Encrypt ENCRYPT_STRING with the current primary version.
263+
byte[] ciphertext = CryptFile.encrypt(
264+
PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, ENCRYPT_STRING.getBytes());
271265

272-
assertThat(new String(encrypted)).isNotEqualTo(ENCRYPT_STRING);
266+
assertThat(new String(ciphertext)).isNotEqualTo(ENCRYPT_STRING);
273267

274-
byte[] decrypted = CryptFile.decrypt(
275-
PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, encrypted);
268+
byte[] plaintext = CryptFile.decrypt(
269+
PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, ciphertext);
276270

277-
assertThat(new String(decrypted)).isEqualTo(ENCRYPT_STRING);
271+
assertThat(new String(plaintext)).isEqualTo(ENCRYPT_STRING);
278272
}
279273
}

0 commit comments

Comments
 (0)