Skip to content

Commit 587f7a9

Browse files
Blob Batch API fix when / is present in blob path (Azure#21753)
1 parent c0e76f5 commit 587f7a9

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

sdk/storage/azblob/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
* Fixed case in Blob Batch API when blob path has / in it. Fixes [#21649](https://github.com/Azure/azure-sdk-for-go/issues/21649).
12+
1113
### Other Changes
1214

1315
## 1.2.0 (2023-10-11)

sdk/storage/azblob/container/client_test.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,15 @@ func (s *ContainerUnrecordedTestsSuite) TestSASContainerClientTags() {
25812581
_require.NoError(err)
25822582
}
25832583

2584+
func getBlobNameForBatch(i int) string {
2585+
bbName := fmt.Sprintf("blockblob%v", i)
2586+
if i%2 == 0 {
2587+
// doing this so that there is a mix of blobs with and without / in its name
2588+
bbName = fmt.Sprintf("block/blob%v", i)
2589+
}
2590+
return bbName
2591+
}
2592+
25842593
func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteSuccessUsingSharedKey() {
25852594
_require := require.New(s.T())
25862595
testName := s.T().Name()
@@ -2595,7 +2604,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteSuccessUsing
25952604
_require.NoError(err)
25962605

25972606
for i := 0; i < 10; i++ {
2598-
bbName := fmt.Sprintf("blockblob%v", i)
2607+
bbName := getBlobNameForBatch(i)
25992608
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
26002609
err = bb.Delete(bbName, nil)
26012610
_require.NoError(err)
@@ -2648,7 +2657,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierPartialFail
26482657

26492658
// add 5 blobs to BatchBuilder which does not exist
26502659
for i := 0; i < 15; i++ {
2651-
bbName := fmt.Sprintf("blockblob%v", i)
2660+
bbName := getBlobNameForBatch(i)
26522661
if i < 10 {
26532662
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
26542663
}
@@ -2733,7 +2742,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingTokenCr
27332742
_require.NoError(err)
27342743

27352744
for i := 0; i < 10; i++ {
2736-
bbName := fmt.Sprintf("blockblob%v", i)
2745+
bbName := getBlobNameForBatch(i)
27372746
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
27382747
err = bb.Delete(bbName, nil)
27392748
_require.NoError(err)
@@ -2783,7 +2792,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingTokenC
27832792
_require.NoError(err)
27842793

27852794
for i := 0; i < 10; i++ {
2786-
bbName := fmt.Sprintf("blockblob%v", i)
2795+
bbName := getBlobNameForBatch(i)
27872796
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
27882797
err = bb.SetTier(bbName, blob.AccessTierCool, nil)
27892798
_require.NoError(err)
@@ -2851,7 +2860,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingAccount
28512860
_require.NoError(err)
28522861

28532862
for i := 0; i < 10; i++ {
2854-
bbName := fmt.Sprintf("blockblob%v", i)
2863+
bbName := getBlobNameForBatch(i)
28552864
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
28562865
err = bb.Delete(bbName, nil)
28572866
_require.NoError(err)
@@ -2904,7 +2913,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingAccoun
29042913
_require.NoError(err)
29052914

29062915
for i := 0; i < 10; i++ {
2907-
bbName := fmt.Sprintf("blockblob%v", i)
2916+
bbName := getBlobNameForBatch(i)
29082917
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
29092918
err = bb.SetTier(bbName, blob.AccessTierCool, nil)
29102919
_require.NoError(err)
@@ -2968,7 +2977,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingService
29682977
_require.NoError(err)
29692978

29702979
for i := 0; i < 10; i++ {
2971-
bbName := fmt.Sprintf("blockblob%v", i)
2980+
bbName := getBlobNameForBatch(i)
29722981
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS)
29732982
err = bb.Delete(bbName, nil)
29742983
_require.NoError(err)
@@ -3017,7 +3026,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingServic
30173026
_require.NoError(err)
30183027

30193028
for i := 0; i < 10; i++ {
3020-
bbName := fmt.Sprintf("blockblob%v", i)
3029+
bbName := getBlobNameForBatch(i)
30213030
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS)
30223031
err = bb.SetTier(bbName, blob.AccessTierCool, nil)
30233032
_require.NoError(err)
@@ -3087,7 +3096,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteUsingUserDel
30873096
_require.NoError(err)
30883097

30893098
for i := 0; i < 10; i++ {
3090-
bbName := fmt.Sprintf("blockblob%v", i)
3099+
bbName := getBlobNameForBatch(i)
30913100
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS)
30923101
err = bb.Delete(bbName, nil)
30933102
_require.NoError(err)
@@ -3142,7 +3151,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchSetTierUsingUserDe
31423151
_require.NoError(err)
31433152

31443153
for i := 0; i < 10; i++ {
3145-
bbName := fmt.Sprintf("blockblob%v", i)
3154+
bbName := getBlobNameForBatch(i)
31463155
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, cntClientSAS)
31473156
err = bb.SetTier(bbName, blob.AccessTierCool, nil)
31483157
_require.NoError(err)
@@ -3200,7 +3209,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerBlobBatchDeleteMoreThan256(
32003209
_require.NoError(err)
32013210

32023211
for i := 0; i < 256; i++ {
3203-
bbName := fmt.Sprintf("blockblob%v", i)
3212+
bbName := getBlobNameForBatch(i)
32043213
_ = testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
32053214
err = bb.Delete(bbName, nil)
32063215
_require.NoError(err)

sdk/storage/azblob/internal/exported/blob_batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func createBatchID() (string, error) {
4949
// Content-Length: 0
5050
func buildSubRequest(req *policy.Request) []byte {
5151
var batchSubRequest strings.Builder
52-
blobPath := req.Raw().URL.Path
52+
blobPath := req.Raw().URL.EscapedPath()
5353
if len(req.Raw().URL.RawQuery) > 0 {
5454
blobPath += "?" + req.Raw().URL.RawQuery
5555
}

sdk/storage/azblob/service/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ func batchSetup(containerName string, svcClient *service.Client, bb *service.Bat
11691169
}
11701170
cntClients = append(cntClients, cntClient)
11711171

1172-
bbName := fmt.Sprintf("blockblob%v", i*2)
1172+
bbName := fmt.Sprintf("block/blob%v", i*2)
11731173
bbClient := cntClient.NewBlockBlobClient(bbName)
11741174
_, err = bbClient.Upload(context.Background(), streaming.NopCloser(strings.NewReader(testcommon.BlockBlobDefaultData)), nil)
11751175
if err != nil {

0 commit comments

Comments
 (0)