Skip to content

Commit 3ba2bca

Browse files
author
Walter Poupore
committed
Updated test to schedule key version destruction prior to restore attempt
1 parent a9e8519 commit 3ba2bca

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,21 @@ public void destroyCryptoKeyVersion_destroys() throws Exception {
209209
public void restoreCryptoKeyVersion_restores() throws Exception {
210210
Snippets.createCryptoKeyVersion(PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID);
211211

212-
Matcher matcher = Pattern.compile(".*cryptoKeyVersions/(\\d+)\",\"state\":\"DESTROY_SCHEDULED\".*",
212+
Matcher matcher = Pattern.compile(".*cryptoKeyVersions/(\\d+)\",\"state\":\"ENABLED\".*",
213213
Pattern.DOTALL | Pattern.MULTILINE).matcher(bout.toString().trim());
214214
assertTrue(matcher.matches());
215215

216216
String version = matcher.group(1);
217217

218+
// Only key versions schedule for destruction are restorable, so schedule this key
219+
// version for destruction.
220+
Snippets.destroyCryptoKeyVersion(PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, version);
221+
222+
assertThat(bout.toString()).containsMatch(String.format(
223+
"keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s\",\"state\":\"DESTROY_SCHEDULED\"",
224+
KEY_RING_ID, CRYPTO_KEY_ID, version));
225+
226+
// Now restore the key version.
218227
Snippets.restoreCryptoKeyVersion(PROJECT_ID, LOCATION_ID, KEY_RING_ID, CRYPTO_KEY_ID, version);
219228

220229
assertThat(bout.toString()).containsMatch(String.format(

0 commit comments

Comments
 (0)