Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KMS: fixes the kms failing tests. #817

Merged
merged 2 commits into from
Aug 21, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions kms/src/test/java/com/example/SnippetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}