Skip to content

Commit

Permalink
Blob Batch API fix when / is present in blob path (Azure#21753)
Browse files Browse the repository at this point in the history
  • Loading branch information
souravgupta-msft authored Oct 13, 2023
1 parent c0e76f5 commit 587f7a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/azblob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 20 additions & 11 deletions sdk/storage/azblob/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azblob/internal/exported/blob_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azblob/service/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 587f7a9

Please sign in to comment.