Skip to content

Commit

Permalink
Enabling encryption test back again after recent service side change (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
simplynaveen20 authored Nov 1, 2021
1 parent 7896758 commit 17ddb06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.encryption.implementation.Constants;
import com.azure.cosmos.implementation.ImplementationBridgeHelpers;
import com.azure.cosmos.models.ClientEncryptionPolicy;
import com.azure.cosmos.models.CosmosClientEncryptionKeyProperties;
import com.azure.cosmos.models.CosmosContainerProperties;
Expand Down Expand Up @@ -35,6 +37,7 @@ public class DotNetCompatibleTest extends TestSuiteBase {
private CosmosEncryptionAsyncClient cosmosEncryptionAsyncClient;
private CosmosEncryptionAsyncDatabase cosmosEncryptionAsyncDatabase;
private CosmosEncryptionAsyncContainer cosmosEncryptionAsyncContainer;
private ImplementationBridgeHelpers.CosmosItemRequestOptionsHelper.CosmosItemRequestOptionsAccessor cosmosItemRequestOptionsAccessor;

@Factory(dataProvider = "clientBuilders")
public DotNetCompatibleTest(CosmosClientBuilder clientBuilder) {
Expand Down Expand Up @@ -72,6 +75,8 @@ public void before_CosmosItemTest() throws IOException {
containerProperties.setClientEncryptionPolicy(clientEncryptionPolicy);
cosmosEncryptionAsyncDatabase.getCosmosAsyncDatabase().createContainer(containerProperties).block();
cosmosEncryptionAsyncContainer = cosmosEncryptionAsyncDatabase.getCosmosEncryptionAsyncContainer(containerId);
this.cosmosItemRequestOptionsAccessor =
ImplementationBridgeHelpers.CosmosItemRequestOptionsHelper.getCosmosItemRequestOptionsAccessor();
}

@AfterClass(groups = {"encryption"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true)
Expand All @@ -80,18 +85,19 @@ public void afterClass() {
safeClose(this.client);
}

// Disabling this test, as something has changed on .Net encryption SDK which is causing it to break.
// Will re-enable it once we know the reason.
@Test(groups = {"encryption"}, timeOut = TIMEOUT, enabled = false)
@Test(groups = {"encryption"}, timeOut = TIMEOUT)
public void createItemEncrypt_readItemDecrypt() throws IOException {
JsonNode dotNetEncryptedPocoJsonNode = MAPPER.readTree(new File("src/test/resources/dotnetEncryption" +
"/EncryptedPOCO.json"));


//storing .net encrypted json into database as it is
CosmosItemRequestOptions requestOptions = new CosmosItemRequestOptions();
//Service wont allow to insert plain item in encrypted container, this is a work around to insert the plain item in container
this.cosmosItemRequestOptionsAccessor.setHeader(requestOptions, Constants.IS_CLIENT_ENCRYPTED_HEADER, "true");
PartitionKey partitionKey = new PartitionKey(dotNetEncryptedPocoJsonNode.get("mypk").asText());
this.cosmosEncryptionAsyncContainer.getCosmosAsyncContainer().createItem(dotNetEncryptedPocoJsonNode,
partitionKey, new CosmosItemRequestOptions()).block();
partitionKey, requestOptions).block();

//reading above saved .net encrypted json via java encryption library
EncryptionPojo unencryptedPojo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ public void itemPatchContentResponseOnWriteEnabled() {
assertThat(response.getItem()).isEqualTo(patchedItem);
}

// Disabling this test for now, because of emulator issues, something related to a header change.
// Will enable it once the emulator issues are fixed.
@Test(groups = { "emulator" }, timeOut = TIMEOUT, enabled = false)
@Test(groups = { "emulator" }, timeOut = TIMEOUT)
public void itemPatchFailure() {
// Create an item
ToDoActivity testItem = ToDoActivity.createRandomItem(this.container);
Expand Down Expand Up @@ -245,7 +243,7 @@ public void itemPatchFailure() {
} catch (CosmosException ex) {
assertThat(ex.getStatusCode()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
assertThat(ex.getMessage())
.contains("Add Operation only support adding a leaf node of an existing node(array or object), no path found beyond: 'nonExistentParent'");
.contains("no path found beyond: 'nonExistentParent'");
}

// precondition failure - 412 response
Expand Down

0 comments on commit 17ddb06

Please sign in to comment.