Skip to content

Commit

Permalink
Test Encryption Scope support for Sync Blob Copy (SyncCopyFromUrl) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
siminsavani-msft committed Aug 16, 2023
1 parent c669617 commit a009bcb
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions sdk/storage/azblob/blockblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,57 @@ func (s *BlockBlobRecordedTestsSuite) TestCommitBlockListWithCRC64() {
_require.Error(err, bloberror.UnsupportedChecksum)
}

func (s *BlockBlobUnrecordedTestsSuite) TestCopyBlockBlobFromURLWithEncryptionScope() {
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)

containerName := testcommon.GenerateContainerName(testName)
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

// set up source blob
const contentSize = 4 * 1024 * 1024 // 4 MB
contentReader, _ := testcommon.GetDataAndReader(testName, contentSize)

srcBlob := containerClient.NewBlockBlobClient(testcommon.GenerateBlobName(testName))
_, err = srcBlob.Upload(context.Background(), streaming.NopCloser(contentReader), nil)
_require.Nil(err)

// Get source blob url with SAS for StageFromURL.
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

sasQueryParams, err := sas.AccountSignatureValues{
Protocol: sas.ProtocolHTTPS,
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration,
Permissions: to.Ptr(sas.AccountPermissions{Read: true, List: true}).String(),
ResourceTypes: to.Ptr(sas.AccountResourceTypes{Container: true, Object: true}).String(),
}.SignWithSharedKey(credential)
_require.Nil(err)

srcBlobParts, _ := blob.ParseURL(srcBlob.URL())
srcBlobParts.SAS = sasQueryParams
srcBlobURLWithSAS := srcBlobParts.String()

destBlobName := testcommon.GenerateBlobName(testName)
destBlob := containerClient.NewBlockBlobClient(testcommon.GenerateBlobName(destBlobName))

encryptionScope, err := testcommon.GetRequiredEnv(testcommon.EncryptionScopeEnvVar)
_require.Nil(err)
cpk := blob.CPKScopeInfo{
EncryptionScope: to.Ptr(encryptionScope),
}
copyBlockBlobFromURLOptions := blob.CopyFromURLOptions{
CPKScopeInfo: &cpk,
}
resp, err := destBlob.CopyFromURL(context.Background(), srcBlobURLWithSAS, &copyBlockBlobFromURLOptions)
_require.Nil(err)
_require.Equal(*resp.CopyStatus, "success")
_require.Equal(*resp.EncryptionScope, encryptionScope)
}

func (s *BlockBlobUnrecordedTestsSuite) TestSetTierOnCopyBlockBlobFromURL() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down

0 comments on commit a009bcb

Please sign in to comment.