-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adding type in EncryptionKeyWrapMetadata and performing validation on partition key #21407
Merged
simplynaveen20
merged 7 commits into
Azure:master
from
simplynaveen20:user/nakumars/encryptionValidation
May 19, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4c866bb
Adding type in EncryptionKeyWrapMetadata and doing validation on part…
simplynaveen20 66bd4f1
adding beta tag
simplynaveen20 e2db215
Merge branch 'latest-master' into user/nakumars/encryptionValidation
simplynaveen20 60f8f50
fixing build error
simplynaveen20 d2aa214
adding validation on policy format version
simplynaveen20 cdec16e
Adding usnit test for policyFormatVersion deserialization
simplynaveen20 2f6bb0a
resolving comments
simplynaveen20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...-cosmos-encryption/src/test/java/com/azure/cosmos/encryption/ClientEncryptionKeyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.cosmos.encryption; | ||
|
||
import com.azure.cosmos.CosmosAsyncClient; | ||
import com.azure.cosmos.CosmosAsyncDatabase; | ||
import com.azure.cosmos.CosmosClientBuilder; | ||
import com.azure.cosmos.encryption.models.CosmosEncryptionAlgorithm; | ||
import com.azure.cosmos.models.CosmosClientEncryptionKeyProperties; | ||
import com.azure.cosmos.models.EncryptionKeyWrapMetadata; | ||
import com.azure.cosmos.rx.TestSuiteBase; | ||
import com.microsoft.data.encryption.cryptography.EncryptionKeyStoreProvider; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
public class ClientEncryptionKeyTest extends TestSuiteBase { | ||
private CosmosAsyncClient client; | ||
private CosmosAsyncDatabase cosmosAsyncDatabase; | ||
private CosmosEncryptionAsyncClient cosmosEncryptionAsyncClient; | ||
private CosmosEncryptionAsyncDatabase cosmosEncryptionAsyncDatabase; | ||
private EncryptionKeyStoreProvider encryptionKeyStoreProvider; | ||
|
||
@Factory(dataProvider = "clientBuilders") | ||
public ClientEncryptionKeyTest(CosmosClientBuilder clientBuilder) { | ||
super(clientBuilder); | ||
} | ||
|
||
@BeforeClass(groups = {"encryption"}, timeOut = SETUP_TIMEOUT) | ||
public void before_CosmosItemTest() { | ||
assertThat(this.client).isNull(); | ||
this.client = getClientBuilder().buildAsyncClient(); | ||
encryptionKeyStoreProvider = new EncryptionAsyncApiCrudTest.TestEncryptionKeyStoreProvider(); | ||
cosmosAsyncDatabase = getSharedCosmosDatabase(this.client); | ||
cosmosEncryptionAsyncClient = CosmosEncryptionAsyncClient.createCosmosEncryptionAsyncClient(this.client, | ||
encryptionKeyStoreProvider); | ||
cosmosEncryptionAsyncDatabase = | ||
cosmosEncryptionAsyncClient.getCosmosEncryptionAsyncDatabase(cosmosAsyncDatabase); | ||
} | ||
|
||
|
||
@AfterClass(groups = {"encryption"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) | ||
public void afterClass() { | ||
assertThat(this.client).isNotNull(); | ||
this.client.close(); | ||
} | ||
|
||
|
||
@Test(groups = {"encryption"}, timeOut = TIMEOUT) | ||
public void createClientEncryptionKey() { | ||
EncryptionKeyWrapMetadata metadata = | ||
new EncryptionKeyWrapMetadata(encryptionKeyStoreProvider.getProviderName(), "key1", "tempmetadata1"); | ||
|
||
CosmosClientEncryptionKeyProperties clientEncryptionKey = | ||
cosmosEncryptionAsyncDatabase.createClientEncryptionKey("ClientEncryptionKeyTest1", | ||
CosmosEncryptionAlgorithm.AEAES_256_CBC_HMAC_SHA_256, metadata).block().getProperties(); | ||
assertThat(clientEncryptionKey.getEncryptionKeyWrapMetadata()).isEqualTo(metadata); | ||
|
||
clientEncryptionKey = | ||
cosmosEncryptionAsyncDatabase.rewrapClientEncryptionKey("ClientEncryptionKeyTest1", metadata).block().getProperties(); | ||
assertThat(clientEncryptionKey.getEncryptionKeyWrapMetadata()).isEqualTo(metadata); | ||
} | ||
|
||
@Test(groups = {"encryption"}, timeOut = TIMEOUT) | ||
public void createClientEncryptionKeyWithException() { | ||
EncryptionKeyWrapMetadata metadata = | ||
new EncryptionKeyWrapMetadata("wrongName", "key1", "tempmetadata1"); | ||
|
||
try { | ||
cosmosEncryptionAsyncDatabase.createClientEncryptionKey("ClientEncryptionKeyTest1", | ||
CosmosEncryptionAlgorithm.AEAES_256_CBC_HMAC_SHA_256, metadata).block().getProperties(); | ||
fail("createClientEncryptionKey should fail as it has wrong encryptionKeyWrapMetadata type"); | ||
} catch (IllegalArgumentException ex) { | ||
assertThat(ex.getMessage()).isEqualTo("The EncryptionKeyWrapMetadata Type value does not match with the " + | ||
"ProviderName of EncryptionKeyStoreProvider configured on the Client. Please refer to https://aka" + | ||
".ms/CosmosClientEncryption for more details."); | ||
} | ||
|
||
try { | ||
cosmosEncryptionAsyncDatabase.rewrapClientEncryptionKey("ClientEncryptionKeyTest1", metadata).block().getProperties(); | ||
|
||
} catch (IllegalArgumentException ex) { | ||
assertThat(ex.getMessage()).isEqualTo("The EncryptionKeyWrapMetadata Type value does not match with the " + | ||
"ProviderName of EncryptionKeyStoreProvider configured on the Client. Please refer to https://aka" + | ||
".ms/CosmosClientEncryption for more details."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in similar scenario, does non Cosmos Exception type reach public surface area in the DotNet SDK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes .NET has ArgumentException as well. To me this is correct and it should be non cosmos as it is validation on argument passed by user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would it work on the async API? do we do validation upfront? or do we return a
Mono.of(IllegalArgException)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation is on async API itself which is doing validation upfront .