-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fixed block issue and tier issue #12978
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
Merged
gapra-msft
merged 8 commits into
Azure:master
from
gapra-msft:storage/cryptoRemoveBlock
Jul 13, 2020
Merged
Changes from all 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
144 changes: 144 additions & 0 deletions
144
...aphy/src/test/java/com/azure/storage/blob/specialized/cryptography/KeyvaultKeyTest.groovy
This file contains hidden or 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,144 @@ | ||
| package com.azure.storage.blob.specialized.cryptography | ||
|
|
||
|
|
||
| import com.azure.core.credential.TokenCredential | ||
| import com.azure.core.cryptography.AsyncKeyEncryptionKey | ||
| import com.azure.core.http.HttpClient | ||
| import com.azure.core.http.HttpPipeline | ||
| import com.azure.core.http.HttpPipelineBuilder | ||
| import com.azure.core.http.policy.* | ||
| import com.azure.core.test.TestMode | ||
| import com.azure.core.util.Configuration | ||
| import com.azure.identity.ClientSecretCredentialBuilder | ||
| import com.azure.security.keyvault.keys.KeyClient | ||
| import com.azure.security.keyvault.keys.KeyClientBuilder | ||
| import com.azure.security.keyvault.keys.KeyServiceVersion | ||
| 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.Duration | ||
| import java.time.OffsetDateTime | ||
|
|
||
| class KeyvaultKeyTest extends APISpec { | ||
|
|
||
| BlobContainerClient cc | ||
| EncryptedBlobClient bec // encrypted client for download | ||
| KeyClient keyClient | ||
| String keyId | ||
|
|
||
| def setup() { | ||
| def keyVaultUrl = "https://azstoragesdkvault.vault.azure.net/" | ||
| if (testMode != TestMode.PLAYBACK) { | ||
| keyVaultUrl = Configuration.getGlobalConfiguration().get("KEYVAULT_URL") | ||
| } | ||
|
|
||
| keyClient = new KeyClientBuilder() | ||
| .pipeline(getHttpPipeline(getHttpClient(), KeyServiceVersion.V7_0)) | ||
| .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() | ||
| .pipeline(getHttpPipeline(getHttpClient(), KeyServiceVersion.V7_0)) | ||
| .httpClient(getHttpClient()) | ||
| .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() | ||
| } | ||
|
|
||
| HttpPipeline getHttpPipeline(HttpClient httpClient, KeyServiceVersion serviceVersion) { | ||
| TokenCredential credential = null; | ||
|
|
||
| if (!interceptorManager.isPlaybackMode()) { | ||
| String clientId = System.getenv("AZURE_CLIENT_ID"); | ||
| String clientKey = System.getenv("AZURE_CLIENT_SECRET"); | ||
| String tenantId = System.getenv("AZURE_TENANT_ID"); | ||
| Objects.requireNonNull(clientId, "The client id cannot be null"); | ||
| Objects.requireNonNull(clientKey, "The client key cannot be null"); | ||
| Objects.requireNonNull(tenantId, "The tenant id cannot be null"); | ||
| credential = new ClientSecretCredentialBuilder() | ||
| .clientSecret(clientKey) | ||
| .clientId(clientId) | ||
| .tenantId(tenantId) | ||
| .build(); | ||
| } | ||
|
|
||
| // Closest to API goes first, closest to wire goes last. | ||
| final List<HttpPipelinePolicy> policies = new ArrayList<>(); | ||
| policies.add(new UserAgentPolicy("client_name", "client_version", Configuration.getGlobalConfiguration().clone(), serviceVersion)); | ||
| HttpPolicyProviders.addBeforeRetryPolicies(policies); | ||
| RetryStrategy strategy = new ExponentialBackoff(5, Duration.ofSeconds(2), Duration.ofSeconds(16)); | ||
| policies.add(new RetryPolicy(strategy)); | ||
| if (credential != null) { | ||
| policies.add(new BearerTokenAuthenticationPolicy(credential, "https://vault.azure.net/.default")); | ||
| } | ||
| HttpPolicyProviders.addAfterRetryPolicies(policies); | ||
| policies.add(new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))); | ||
|
|
||
| if (!interceptorManager.isPlaybackMode()) { | ||
| if (testMode == TestMode.RECORD) { | ||
| policies.add(interceptorManager.getRecordPolicy()); | ||
| } | ||
| } | ||
|
|
||
| HttpPipeline pipeline = new HttpPipelineBuilder() | ||
| .policies(policies.toArray(new HttpPipelinePolicy[0])) | ||
| .httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient) | ||
| .build() | ||
|
|
||
| return pipeline; | ||
| } | ||
|
|
||
| } |
70 changes: 70 additions & 0 deletions
70
...ography/src/test/java/com/azure/storage/blob/specialized/cryptography/LocalKeyTest.groovy
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.