Skip to content

Commit 5bb80e9

Browse files
author
Frank Natividad
committed
---
yaml --- r: 9615 b: refs/heads/kms-integration c: a1b0087 h: refs/heads/master i: 9613: ccf4179 9611: 9ee1274 9607: 41acbd2 9599: 0d568e1
1 parent 037f0cd commit 5bb80e9

4 files changed

Lines changed: 116 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ refs/tags/v0.42.1: 3d9c15dd66bbe736cfd83b695f805833d7a32299
9191
refs/tags/v0.43.0: af4bfcbcc7c86354b26642d65400ee4accb632a9
9292
refs/heads/add-pubsub-publish-error-handler: 54ac3bf7a1396a71a4ffc350cd409de4dad2d63a
9393
refs/heads/java-release-src-1: 23b4842b1c560f3f1d382de1e0797261307490b4
94-
refs/heads/kms-integration: 4da3796f6978eda777b9f3d300bf286d8cb92482
94+
refs/heads/kms-integration: a1b0087ae33739e9eb741680824fba3bb37bd678
9595
refs/tags/v0.44.0: 1c7d06813aa4d2ac948b1ddda591406a2448371f
9696
refs/tags/v0.45.0: 4b4eb52d0823f5335cb8acf54a88bae199e013ae
9797
refs/tags/v0.46.0: 40dfc83a11b2cf2c21bf0f5a7b1e47087cbf0259

branches/kms-integration/google-cloud-storage/src/test/java/com/google/cloud/storage/BlobTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ public void testWriterWithEncryptionKey() throws Exception {
367367
assertSame(channel, blob.writer(BlobWriteOption.encryptionKey(KEY)));
368368
}
369369

370+
@Test
371+
public void testWriterWithKmsKeyName() throws Exception {
372+
initializeExpectedBlob(2);
373+
BlobWriteChannel channel = createMock(BlobWriteChannel.class);
374+
expect(storage.getOptions()).andReturn(mockOptions);
375+
expect(storage.writer(eq(expectedBlob), eq(BlobWriteOption.kmsKeyName(KMS_KEY_NAME))))
376+
.andReturn(channel);
377+
replay(storage);
378+
initializeBlob();
379+
assertSame(channel, blob.writer(BlobWriteOption.kmsKeyName(KMS_KEY_NAME)));
380+
}
381+
370382
@Test
371383
public void testSignUrl() throws Exception {
372384
initializeExpectedBlob(2);

branches/kms-integration/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,22 @@ public void testCreateWithEncryptionKey() throws Exception {
366366
assertEquals(expectedBlob, blob);
367367
}
368368

369+
@Test
370+
public void testCreateWithKmsKeyName() throws Exception {
371+
initializeExpectedBucket(5);
372+
BlobInfo info = BlobInfo.newBuilder(BlobId.of("b", "n")).setContentType(CONTENT_TYPE).build();
373+
Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info));
374+
byte[] content = {0xD, 0xE, 0xA, 0xD};
375+
expect(storage.getOptions()).andReturn(mockOptions);
376+
expect(storage.create(info, content, Storage.BlobTargetOption.kmsKeyName(DEFAULT_KMS_KEY_NAME)))
377+
.andReturn(expectedBlob);
378+
replay(storage);
379+
initializeBucket();
380+
Blob blob =
381+
bucket.create("n", content, CONTENT_TYPE, Bucket.BlobTargetOption.kmsKeyName(DEFAULT_KMS_KEY_NAME));
382+
assertEquals(expectedBlob, blob);
383+
}
384+
369385
@Test
370386
public void testCreateNotExists() throws Exception {
371387
initializeExpectedBucket(5);

branches/kms-integration/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,40 @@ public void testCreateBlobWithEncryptionKey() throws IOException {
566566
assertEquals(-1, byteStream.read(streamBytes));
567567
}
568568

569+
@Test
570+
public void testCreateBlobWithKmsKeyName() throws IOException {
571+
Capture<ByteArrayInputStream> capturedStream = Capture.newInstance();
572+
EasyMock.expect(
573+
storageRpcMock.create(
574+
EasyMock.eq(
575+
BLOB_INFO1
576+
.toBuilder()
577+
.setMd5(CONTENT_MD5)
578+
.setCrc32c(CONTENT_CRC32C)
579+
.build()
580+
.toPb()),
581+
EasyMock.capture(capturedStream),
582+
EasyMock.eq(KMS_KEY_NAME_OPTIONS)))
583+
.andReturn(BLOB_INFO1.toPb())
584+
.times(2);
585+
EasyMock.replay(storageRpcMock);
586+
initializeService();
587+
Blob blob = storage.create(BLOB_INFO1, BLOB_CONTENT, BlobTargetOption.kmsKeyName(KMS_KEY_NAME));
588+
assertEquals(expectedBlob1, blob);
589+
ByteArrayInputStream byteStream = capturedStream.getValue();
590+
byte[] streamBytes = new byte[BLOB_CONTENT.length];
591+
assertEquals(BLOB_CONTENT.length, byteStream.read(streamBytes));
592+
assertArrayEquals(BLOB_CONTENT, streamBytes);
593+
assertEquals(-1, byteStream.read(streamBytes));
594+
blob = storage.create(BLOB_INFO1, BLOB_CONTENT, BlobTargetOption.kmsKeyName(KMS_KEY_NAME));
595+
assertEquals(expectedBlob1, blob);
596+
byteStream = capturedStream.getValue();
597+
streamBytes = new byte[BLOB_CONTENT.length];
598+
assertEquals(BLOB_CONTENT.length, byteStream.read(streamBytes));
599+
assertArrayEquals(BLOB_CONTENT, streamBytes);
600+
assertEquals(-1, byteStream.read(streamBytes));
601+
}
602+
569603
@Test
570604
public void testCreateBlobFromStream() throws IOException {
571605
Capture<ByteArrayInputStream> capturedStream = Capture.newInstance();
@@ -1243,6 +1277,43 @@ public void testCopyWithEncryptionKey() {
12431277
assertTrue(!writer.isDone());
12441278
}
12451279

1280+
@Test
1281+
public void testCopyFromEncryptionKeyToKmsKeyName() {
1282+
CopyRequest request =
1283+
Storage.CopyRequest.newBuilder()
1284+
.setSource(BLOB_INFO2.getBlobId())
1285+
.setSourceOptions(BlobSourceOption.decryptionKey(KEY))
1286+
.setTarget(BLOB_INFO1, BlobTargetOption.kmsKeyName(KMS_KEY_NAME))
1287+
.build();
1288+
StorageRpc.RewriteRequest rpcRequest =
1289+
new StorageRpc.RewriteRequest(
1290+
request.getSource().toPb(),
1291+
ENCRYPTION_KEY_OPTIONS,
1292+
true,
1293+
request.getTarget().toPb(),
1294+
KMS_KEY_NAME_OPTIONS,
1295+
null);
1296+
StorageRpc.RewriteResponse rpcResponse =
1297+
new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
1298+
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse).times(2);
1299+
EasyMock.replay(storageRpcMock);
1300+
initializeService();
1301+
CopyWriter writer = storage.copy(request);
1302+
assertEquals(42L, writer.getBlobSize());
1303+
assertEquals(21L, writer.getTotalBytesCopied());
1304+
assertTrue(!writer.isDone());
1305+
request =
1306+
Storage.CopyRequest.newBuilder()
1307+
.setSource(BLOB_INFO2.getBlobId())
1308+
.setSourceOptions(BlobSourceOption.decryptionKey(BASE64_KEY))
1309+
.setTarget(BLOB_INFO1, BlobTargetOption.kmsKeyName(KMS_KEY_NAME))
1310+
.build();
1311+
writer = storage.copy(request);
1312+
assertEquals(42L, writer.getBlobSize());
1313+
assertEquals(21L, writer.getTotalBytesCopied());
1314+
assertTrue(!writer.isDone());
1315+
}
1316+
12461317
@Test
12471318
public void testCopyWithOptionsFromBlobId() {
12481319
CopyRequest request =
@@ -1494,6 +1565,22 @@ public void testWriterWithEncryptionKey() {
14941565
assertTrue(channel.isOpen());
14951566
}
14961567

1568+
@Test
1569+
public void testWriterWithKmsKeyName() {
1570+
BlobInfo info = BLOB_INFO1.toBuilder().setMd5(null).setCrc32c(null).build();
1571+
EasyMock.expect(storageRpcMock.open(info.toPb(), KMS_KEY_NAME_OPTIONS))
1572+
.andReturn("upload-id")
1573+
.times(2);
1574+
EasyMock.replay(storageRpcMock);
1575+
initializeService();
1576+
WriteChannel channel = storage.writer(info, BlobWriteOption.kmsKeyName(KMS_KEY_NAME));
1577+
assertNotNull(channel);
1578+
assertTrue(channel.isOpen());
1579+
channel = storage.writer(info, BlobWriteOption.kmsKeyName(KMS_KEY_NAME));
1580+
assertNotNull(channel);
1581+
assertTrue(channel.isOpen());
1582+
}
1583+
14971584
@Test
14981585
public void testSignUrl()
14991586
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException,

0 commit comments

Comments
 (0)