-
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
Fixed block issue and tier issue #12978
Merged
gapra-msft
merged 8 commits into
Azure:master
from
gapra-msft:storage/cryptoRemoveBlock
Jul 13, 2020
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5796f32
Fixed block issue and tier issue
gapra-msft 8bf17d5
removed imports
gapra-msft 1cfc654
fix recordings
gapra-msft 03ee05d
Modified pom to add dep tag
gapra-msft e256ddc
Added fallback url
gapra-msft e1f6660
Updated test resources
gapra-msft b12eba1
Rerecorded tests
gapra-msft 810be64
Fixed playback test
gapra-msft 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
101 changes: 101 additions & 0 deletions
101
...aphy/src/test/java/com/azure/storage/blob/specialized/cryptography/KeyvaultKeyTest.groovy
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,101 @@ | ||
package com.azure.storage.blob.specialized.cryptography | ||
|
||
import com.azure.core.cryptography.AsyncKeyEncryptionKey | ||
import com.azure.core.test.TestMode | ||
import com.azure.core.util.Configuration | ||
import com.azure.identity.DefaultAzureCredentialBuilder | ||
import com.azure.identity.EnvironmentCredentialBuilder | ||
import com.azure.security.keyvault.keys.KeyClient | ||
import com.azure.security.keyvault.keys.KeyClientBuilder | ||
import com.azure.security.keyvault.keys.cryptography.KeyEncryptionKeyClientBuilder | ||
import com.azure.security.keyvault.keys.models.CreateRsaKeyOptions | ||
import com.azure.security.keyvault.keys.models.KeyVaultKey | ||
import com.azure.storage.blob.BlobContainerClient | ||
import com.azure.storage.common.implementation.Constants | ||
|
||
import java.time.OffsetDateTime | ||
|
||
class KeyvaultKeyTest extends APISpec { | ||
|
||
BlobContainerClient cc | ||
EncryptedBlobClient bec // encrypted client for download | ||
KeyClient keyClient | ||
String keyId | ||
|
||
def setup() { | ||
def keyVaultUrl = Configuration.getGlobalConfiguration().get("KEYVAULT_URL") | ||
|
||
KeyClientBuilder builder = new KeyClientBuilder() | ||
|
||
if (testMode != TestMode.PLAYBACK) { | ||
if (testMode == TestMode.RECORD) { | ||
builder.addPolicy(interceptorManager.getRecordPolicy()) | ||
} | ||
// AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET | ||
builder.credential(new EnvironmentCredentialBuilder().build()) | ||
} else { | ||
builder.credential(new DefaultAzureCredentialBuilder().build()) | ||
} | ||
|
||
keyClient = builder | ||
.httpClient(getHttpClient()) | ||
.vaultUrl(keyVaultUrl) | ||
.buildClient() | ||
|
||
keyId = generateResourceName("keyId", entityNo++) | ||
|
||
KeyVaultKey keyVaultKey = keyClient.createRsaKey(new CreateRsaKeyOptions(keyId) | ||
.setExpiresOn(OffsetDateTime.now().plusYears(1)) | ||
.setKeySize(2048)) | ||
|
||
AsyncKeyEncryptionKey akek = new KeyEncryptionKeyClientBuilder() | ||
.credential(new DefaultAzureCredentialBuilder().build()) | ||
.buildAsyncKeyEncryptionKey(keyVaultKey.getId()) | ||
.block() | ||
|
||
cc = getServiceClientBuilder(primaryCredential, | ||
String.format(defaultEndpointTemplate, primaryCredential.getAccountName())) | ||
.buildClient() | ||
.getBlobContainerClient(generateContainerName()) | ||
cc.create() | ||
|
||
bec = getEncryptedClientBuilder(akek, null, primaryCredential, | ||
cc.getBlobContainerUrl().toString()) | ||
.blobName(generateBlobName()) | ||
.buildEncryptedBlobClient() | ||
} | ||
|
||
def cleanup() { | ||
keyClient.beginDeleteKey(keyId) | ||
} | ||
|
||
def "upload download"() { | ||
setup: | ||
def inputArray = getRandomByteArray(Constants.KB) | ||
InputStream stream = new ByteArrayInputStream(inputArray) | ||
def os = new ByteArrayOutputStream() | ||
|
||
when: | ||
bec.upload(stream, Constants.KB) | ||
bec.download(os) | ||
|
||
then: | ||
inputArray == os.toByteArray() | ||
} | ||
|
||
|
||
def "encryption not a noop"() { | ||
setup: | ||
def inputArray = getRandomByteArray(Constants.KB) | ||
InputStream stream = new ByteArrayInputStream(inputArray) | ||
def os = new ByteArrayOutputStream() | ||
|
||
when: | ||
bec.upload(stream, Constants.KB) | ||
cc.getBlobClient(bec.getBlobName()).download(os) | ||
|
||
then: | ||
inputArray != os.toByteArray() | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...ography/src/test/java/com/azure/storage/blob/specialized/cryptography/LocalKeyTest.groovy
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,70 @@ | ||
package com.azure.storage.blob.specialized.cryptography | ||
|
||
import com.azure.core.cryptography.AsyncKeyEncryptionKey | ||
import com.azure.security.keyvault.keys.cryptography.LocalKeyEncryptionKeyClientBuilder | ||
import com.azure.security.keyvault.keys.models.JsonWebKey | ||
import com.azure.security.keyvault.keys.models.KeyOperation | ||
import com.azure.storage.blob.BlobContainerClient | ||
import com.azure.storage.common.implementation.Constants | ||
|
||
import javax.crypto.spec.SecretKeySpec | ||
|
||
class LocalKeyTest extends APISpec { | ||
|
||
BlobContainerClient cc | ||
EncryptedBlobClient bec // encrypted client for download | ||
|
||
def setup() { | ||
|
||
/* Insecurely generate a local key*/ | ||
def byteKey = getRandomByteArray(256) | ||
|
||
JsonWebKey localKey = JsonWebKey.fromAes(new SecretKeySpec(byteKey, "AES"), | ||
Arrays.asList(KeyOperation.WRAP_KEY, KeyOperation.UNWRAP_KEY)) | ||
.setId("local") | ||
AsyncKeyEncryptionKey akek = new LocalKeyEncryptionKeyClientBuilder() | ||
.buildAsyncKeyEncryptionKey(localKey) | ||
.block(); | ||
|
||
cc = getServiceClientBuilder(primaryCredential, | ||
String.format(defaultEndpointTemplate, primaryCredential.getAccountName())) | ||
.buildClient() | ||
.getBlobContainerClient(generateContainerName()) | ||
cc.create() | ||
|
||
bec = getEncryptedClientBuilder(akek, null, primaryCredential, | ||
cc.getBlobContainerUrl().toString()) | ||
.blobName(generateBlobName()) | ||
.buildEncryptedBlobClient() | ||
} | ||
|
||
def "upload download"() { | ||
setup: | ||
def inputArray = getRandomByteArray(Constants.KB) | ||
InputStream stream = new ByteArrayInputStream(inputArray) | ||
def os = new ByteArrayOutputStream() | ||
|
||
when: | ||
bec.upload(stream, Constants.KB) | ||
bec.download(os) | ||
|
||
then: | ||
inputArray == os.toByteArray() | ||
} | ||
|
||
|
||
def "encryption not a noop"() { | ||
setup: | ||
def inputArray = getRandomByteArray(Constants.KB) | ||
InputStream stream = new ByteArrayInputStream(inputArray) | ||
def os = new ByteArrayOutputStream() | ||
|
||
when: | ||
bec.upload(stream, Constants.KB) | ||
cc.getBlobClient(bec.getBlobName()).download(os) | ||
|
||
then: | ||
inputArray != os.toByteArray() | ||
} | ||
|
||
} |
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.
Ideally, I would build a pipeline here and in playback mode skip adding the BearerTokenAuth policy in the pipeline.
Then set the pipeline on the builder.
But, to keep the setup as it is, the below line might work too. The credential should return a dummy token in playback mode.
.credential(trc -> Mono.just(new AccessToken("Dummy-Token", OffsetDateTime.now().plusHours(2))));
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.
Thanks for catching that! Forgot about this client