Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public <T> Mono<CosmosItemResponse<T>> readItem(String id,
PartitionKey partitionKey,
CosmosItemRequestOptions requestOptions,
Class<T> classType) {
if (requestOptions == null) {
requestOptions = new CosmosItemRequestOptions();
}

Mono<CosmosItemResponse<byte[]>> responseMessageMono = this.readItemHelper(id, partitionKey, requestOptions, false);

return responseMessageMono.publishOn(encryptionScheduler).flatMap(cosmosItemResponse -> setByteArrayContent(cosmosItemResponse,
Expand Down Expand Up @@ -311,7 +315,7 @@ private Mono<CosmosItemResponse<byte[]>> setByteArrayContent(CosmosItemResponse<
this.cosmosItemResponseBuilderAccessor.setByteArrayContent(rsp, bytes);
return Mono.just(rsp);
}
);
).defaultIfEmpty(rsp);
}

private <T> Function<CosmosPagedFluxOptions, Flux<FeedResponse<T>>> queryDecryptionTransformer(Class<T> classType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ public Mono<byte[]> decrypt(byte[] input) {
input == null ? null : input.length,
Thread.currentThread().getName());
}
ObjectNode itemJObj = Utils.parse(input, ObjectNode.class);

if (input == null || input.length == 0) {
return Mono.empty();
}

ObjectNode itemJObj = Utils.parse(input, ObjectNode.class);
assert (itemJObj != null);
return initEncryptionSettingsIfNotInitializedAsync().then(Mono.defer(() -> {
for (ClientEncryptionIncludedPath includedPath : this.clientEncryptionPolicy.getIncludedPaths()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public EncryptionAsyncApiCrudTest(CosmosClientBuilder clientBuilder) {
public void before_CosmosItemTest() {
assertThat(this.client).isNull();
this.client = getClientBuilder().buildAsyncClient();
EncryptionKeyStoreProvider encryptionKeyStoreProvider = new TestEncryptionKeyStoreProvider();
TestEncryptionKeyStoreProvider encryptionKeyStoreProvider = new TestEncryptionKeyStoreProvider();
cosmosAsyncDatabase = getSharedCosmosDatabase(this.client);
cosmosEncryptionAsyncClient = CosmosEncryptionAsyncClient.createCosmosEncryptionAsyncClient(this.client,
encryptionKeyStoreProvider);
Expand Down Expand Up @@ -123,6 +123,17 @@ public void createItemEncrypt_readItemDecrypt() {
validateResponse(properties, responseItem);
}

@Test(groups = {"encryption"}, timeOut = TIMEOUT)
public void createItemEncryptWithContentResponseOnWriteEnabledFalse() {
CosmosItemRequestOptions requestOptions = new CosmosItemRequestOptions();
requestOptions.setContentResponseOnWriteEnabled(false);
EncryptionPojo properties = getItem(UUID.randomUUID().toString());
CosmosItemResponse<EncryptionPojo> itemResponse = cosmosEncryptionAsyncContainer.createItem(properties,
new PartitionKey(properties.getMypk()), requestOptions).block();
assertThat(itemResponse.getRequestCharge()).isGreaterThan(0);
assertThat(itemResponse.getItem()).isNull();
}

@Test(groups = {"encryption"}, timeOut = TIMEOUT)
public void upsertItem_readItem() {
EncryptionPojo properties = getItem(UUID.randomUUID().toString());
Expand Down