From 587f7a9062012861470591b07b38cd4f8ccf00ea Mon Sep 17 00:00:00 2001 From: Sourav Gupta <98318303+souravgupta-msft@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:11:54 +0530 Subject: [PATCH] Blob Batch API fix when / is present in blob path (#21753) --- sdk/storage/azblob/CHANGELOG.md | 2 ++ sdk/storage/azblob/container/client_test.go | 31 ++++++++++++------- .../azblob/internal/exported/blob_batch.go | 2 +- sdk/storage/azblob/service/client_test.go | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/sdk/storage/azblob/CHANGELOG.md b/sdk/storage/azblob/CHANGELOG.md index 1a1505e766c8..d598dec58b62 100644 --- a/sdk/storage/azblob/CHANGELOG.md +++ b/sdk/storage/azblob/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +* Fixed case in Blob Batch API when blob path has / in it. Fixes [#21649](https://github.com/Azure/azure-sdk-for-go/issues/21649). + ### Other Changes ## 1.2.0 (2023-10-11) diff --git a/sdk/storage/azblob/container/client_test.go b/sdk/storage/azblob/container/client_test.go index 403ddac73665..54466fb7f126 100644 --- a/sdk/storage/azblob/container/client_test.go +++ b/sdk/storage/azblob/container/client_test.go @@ -2581,6 +2581,15 @@ func (s *ContainerUnrecordedTestsSuite) TestSASContainerClientTags() { _require.NoError(err) } +func getBlobNameForBatch(i int) string { + bbName := fmt.Sprintf("blockblob%v", i) + if i%2 == 0 { + // doing this so that there is a mix of blobs with and without / in its name + bbName = fmt.Sprintf("block/blob%v", i) + } + return bbName +} + func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteSuccessUsingSharedKey() { _require := require.New(s.T()) testName := s.T().Name() @@ -2595,7 +2604,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteSuccessUsing _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) err = bb.Delete(bbName, nil) _require.NoError(err) @@ -2648,7 +2657,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierPartialFail // add 5 blobs to BatchBuilder which does not exist for i := 0; i < 15; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) if i < 10 { _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) } @@ -2733,7 +2742,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingTokenCr _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) err = bb.Delete(bbName, nil) _require.NoError(err) @@ -2783,7 +2792,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingTokenC _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) err = bb.SetTier(bbName, blob.AccessTierCool, nil) _require.NoError(err) @@ -2851,7 +2860,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingAccount _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) err = bb.Delete(bbName, nil) _require.NoError(err) @@ -2904,7 +2913,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingAccoun _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) err = bb.SetTier(bbName, blob.AccessTierCool, nil) _require.NoError(err) @@ -2968,7 +2977,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingService _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS) err = bb.Delete(bbName, nil) _require.NoError(err) @@ -3017,7 +3026,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingServic _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS) err = bb.SetTier(bbName, blob.AccessTierCool, nil) _require.NoError(err) @@ -3087,7 +3096,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingUserDel _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS) err = bb.Delete(bbName, nil) _require.NoError(err) @@ -3142,7 +3151,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingUserDe _require.NoError(err) for i := 0; i < 10; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS) err = bb.SetTier(bbName, blob.AccessTierCool, nil) _require.NoError(err) @@ -3200,7 +3209,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteMoreThan256( _require.NoError(err) for i := 0; i < 256; i++ { - bbName := fmt.Sprintf("blockblob%v", i) + bbName := getBlobNameForBatch(i) _ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient) err = bb.Delete(bbName, nil) _require.NoError(err) diff --git a/sdk/storage/azblob/internal/exported/blob_batch.go b/sdk/storage/azblob/internal/exported/blob_batch.go index 64a88688a49d..02966ee3e9ab 100644 --- a/sdk/storage/azblob/internal/exported/blob_batch.go +++ b/sdk/storage/azblob/internal/exported/blob_batch.go @@ -49,7 +49,7 @@ func createBatchID() (string, error) { // Content-Length: 0 func buildSubRequest(req *policy.Request) []byte { var batchSubRequest strings.Builder - blobPath := req.Raw().URL.Path + blobPath := req.Raw().URL.EscapedPath() if len(req.Raw().URL.RawQuery) > 0 { blobPath += "?" + req.Raw().URL.RawQuery } diff --git a/sdk/storage/azblob/service/client_test.go b/sdk/storage/azblob/service/client_test.go index debc92df9a20..e25c74f4e1e5 100644 --- a/sdk/storage/azblob/service/client_test.go +++ b/sdk/storage/azblob/service/client_test.go @@ -1169,7 +1169,7 @@ func batchSetup(containerName string, svcClient *service.Client, bb *service.Bat } cntClients = append(cntClients, cntClient) - bbName := fmt.Sprintf("blockblob%v", i*2) + bbName := fmt.Sprintf("block/blob%v", i*2) bbClient := cntClient.NewBlockBlobClient(bbName) _, err = bbClient.Upload(context.Background(), streaming.NopCloser(strings.NewReader(testcommon.BlockBlobDefaultData)), nil) if err != nil {