Skip to content

Commit

Permalink
fixing the compareHeaders sorting algorithm (#23545)
Browse files Browse the repository at this point in the history
* fixing the compareHeaders sorting algorithm

* solve linter issues

* another lint error and test recording

* fixin lint errors in datalake and files

* fixing azblob tests

* fixing azblob tests

* fixing azblob tests

* fixing azblob live tests

* fixing azfile tests

* fixing azfile live tests

* disabling failed tests due to azblob dependency

* fixing azfile CI tests

* fixing azblob live tests which were using public access

* reverting asdatalake changes

* fixing lint error in azblob test

* reverting sas token changes for azblob live tests

* fixing azblob tests with sas tokens

* fixing azfile live tests

* fixing azfile lint error

---------

Co-authored-by: tanyasethi-msft <[email protected]>
  • Loading branch information
gunjansingh-msft and tanyasethi-msft authored Oct 16, 2024
1 parent 7e59111 commit 40dcd1b
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 80 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/azblob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azblob",
"Tag": "go/storage/azblob_bbf7a929e3"
"Tag": "go/storage/azblob_e5b4fd09a3"
}
29 changes: 17 additions & 12 deletions sdk/storage/azblob/blob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyDestIfModifiedSinceFalse() {
},
}
_, err = destBlobClient.StartCopyFromURL(context.Background(), bbClient.URL(), &options)
testcommon.ValidateBlobErrorCode(_require, err, bloberror.TargetConditionNotMet)
testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet)
}

func (s *BlobRecordedTestsSuite) TestBlobStartCopyDestIfUnmodifiedSinceTrue() {
Expand Down Expand Up @@ -1073,7 +1073,7 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyDestIfMatchFalse() {

_, err = destBlobClient.StartCopyFromURL(context.Background(), bbClient.URL(), &options)
_require.Error(err)
testcommon.ValidateBlobErrorCode(_require, err, bloberror.TargetConditionNotMet)
testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet)
}

func (s *BlobRecordedTestsSuite) TestBlobStartCopyDestIfNoneMatchTrue() {
Expand Down Expand Up @@ -1140,17 +1140,28 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyDestIfNoneMatchFalse() {

_, err = destBlobClient.StartCopyFromURL(context.Background(), bbClient.URL(), &options)
_require.Error(err)
testcommon.ValidateBlobErrorCode(_require, err, bloberror.TargetConditionNotMet)
testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet)
}

func (s *BlobUnrecordedTestsSuite) TestBlobAbortCopyInProgress() {
_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)
svcClientSharedKey, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)

accountSAS, err := testcommon.GetAccountSAS(sas.AccountPermissions{Read: true, Create: true, Write: true, List: true, Add: true, Delete: true},
sas.AccountResourceTypes{Service: true, Container: true, Object: true})
_require.NoError(err)

svcClientSAS, err := service.NewClientWithNoCredential(svcClientSharedKey.URL()+"?"+accountSAS, nil)
_require.NoError(err)

containerClient := svcClientSAS.NewContainerClient(containerName)
_, err = containerClient.Create(context.Background(), nil)
_require.NoError(err)

defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

blockBlobName := testcommon.GenerateBlobName(testName)
Expand All @@ -1162,12 +1173,6 @@ func (s *BlobUnrecordedTestsSuite) TestBlobAbortCopyInProgress() {
_, err = bbClient.Upload(context.Background(), streaming.NopCloser(blobReader), nil)
_require.NoError(err)

setAccessPolicyOptions := container.SetAccessPolicyOptions{
Access: to.Ptr(container.PublicAccessTypeBlob),
}
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions) // So that we don't have to create a SAS
_require.NoError(err)

// Must copy across accounts so it takes time to copy
serviceClient2, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountSecondary, nil)
if err != nil {
Expand Down
26 changes: 15 additions & 11 deletions sdk/storage/azblob/blockblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"bytes"
"context"
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
"hash/crc64"
"io"
"math/rand"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -367,15 +367,9 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlobCrcResponseHeader() {
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

accountName, accountKey := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault)
blobName := testName
blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName)

cred, err := blob.NewSharedKeyCredential(accountName, accountKey)
_require.NoError(err)

bbClient, err := blockblob.NewClientWithSharedKeyCredential(blobURL, cred, nil)
_require.NoError(err)
bbClient := containerClient.NewBlockBlobClient(blobName)

contentSize := 4 * 1024 // 4 KB
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
Expand Down Expand Up @@ -771,6 +765,11 @@ func (s *BlockBlobRecordedTestsSuite) TestStageBlockWithGeneratedCRC64() {
func (s *BlockBlobRecordedTestsSuite) TestStageBlockWithCRC64() {
_require := require.New(s.T())
testName := s.T().Name()
var b [8]byte
_, err := rand.Read(b[:])
if err != nil {
return
}
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)

Expand All @@ -796,7 +795,8 @@ func (s *BlockBlobRecordedTestsSuite) TestStageBlockWithCRC64() {
_require.EqualValues(binary.LittleEndian.Uint64(putResp.ContentCRC64), contentCrc64)

// test put block with bad CRC64 value
badContentCrc64 := rand.Uint64()
badContentCrc64 := binary.LittleEndian.Uint64(b[:])

_, _ = rsc.Seek(0, io.SeekStart)
blockID2 := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%6d", 1)))
_, err = bbClient.StageBlock(context.Background(), blockID2, rsc, &blockblob.StageBlockOptions{
Expand Down Expand Up @@ -5143,7 +5143,10 @@ func (s *BlockBlobUnrecordedTestsSuite) TestBlobUploadStreamDownloadBuffer() {
const MiB = 1024 * 1024
testUploadDownload := func(contentSize int) {
content := make([]byte, contentSize)
_, _ = rand.Read(content)
_, err := rand.Read(content)
if err != nil {
return
}
contentMD5 := md5.Sum(content)
body := streaming.NopCloser(bytes.NewReader(content))

Expand Down Expand Up @@ -5882,7 +5885,8 @@ func (m serviceVersionTest) Do(req *policy.Request) (*http.Response, error) {

currentVersion := map[string][]string(req.Raw().Header)[versionHeader]
if currentVersion[0] != generated.ServiceVersion {
return nil, fmt.Errorf(currentVersion[0] + " service version doesn't match expected version: " + generated.ServiceVersion)
return nil, fmt.Errorf("%s service version doesn't match expected version: %s", currentVersion[0], generated.ServiceVersion)

}

return &http.Response{
Expand Down
36 changes: 9 additions & 27 deletions sdk/storage/azblob/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerCreateInvalidName() {
_require.NoError(err)
containerClient := svcClient.NewContainerClient("foo bar")

access := container.PublicAccessTypeBlob
createContainerOptions := container.CreateOptions{
Access: &access,
Metadata: map[string]*string{},
}
_, err = containerClient.Create(context.Background(), &createContainerOptions)
Expand Down Expand Up @@ -168,9 +166,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerCreateNameCollision() {

defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

access := container.PublicAccessTypeBlob
createContainerOptions := container.CreateOptions{
Access: &access,
Metadata: map[string]*string{},
}

Expand Down Expand Up @@ -208,9 +204,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerCreateNilMetadata() {
containerName := testcommon.GenerateContainerName(testName)
containerClient := testcommon.GetContainerClient(containerName, svcClient)

access := container.PublicAccessTypeBlob
createContainerOptions := container.CreateOptions{
Access: &access,
Metadata: map[string]*string{},
}
_, err = containerClient.Create(context.Background(), &createContainerOptions)
Expand All @@ -231,9 +225,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerCreateEmptyMetadata() {
containerName := testcommon.GenerateContainerName(testName)
containerClient := testcommon.GetContainerClient(containerName, svcClient)

access := container.PublicAccessTypeBlob
createContainerOptions := container.CreateOptions{
Access: &access,
Metadata: map[string]*string{},
}
_, err = containerClient.Create(context.Background(), &createContainerOptions)
Expand Down Expand Up @@ -1196,10 +1188,8 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetMetadataEmpty() {
containerName := testcommon.GenerateContainerName(testName)
containerClient := testcommon.GetContainerClient(containerName, svcClient)

access := container.PublicAccessTypeBlob
createContainerOptions := container.CreateOptions{
Metadata: testcommon.BasicMetadata,
Access: &access,
}
_, err = containerClient.Create(context.Background(), &createContainerOptions)
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
Expand All @@ -1223,9 +1213,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetMetadataNil() {
_require.NoError(err)
containerName := testcommon.GenerateContainerName(testName)
containerClient := testcommon.GetContainerClient(containerName, svcClient)
access := container.PublicAccessTypeBlob
createContainerOptions := container.CreateOptions{
Access: &access,
Metadata: testcommon.BasicMetadata,
}
_, err = containerClient.Create(context.Background(), &createContainerOptions)
Expand Down Expand Up @@ -1741,6 +1729,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerGetSetPermissionsMultiplePoli
}

func (s *ContainerRecordedTestsSuite) TestContainerGetPermissionsPublicAccessNotNone() {
s.T().Skip("this test is not needed as public access is disabled")
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
Expand Down Expand Up @@ -1807,6 +1796,7 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerSetPermissionsPublicAccessN
}

func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsPublicAccessTypeBlob() {
s.T().Skip("this test is not needed as public access is disabled")
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
Expand All @@ -1827,6 +1817,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsPublicAccessTyp
}

func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsPublicAccessContainer() {
s.T().Skip("This test is not valid because public access is disabled")
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
Expand Down Expand Up @@ -1932,9 +1923,8 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsACLMoreThanFive
}
}

access := container.PublicAccessTypeBlob
setAccessPolicyOptions := container.SetAccessPolicyOptions{
Access: &access,
ContainerACL: permissions,
}
setAccessPolicyOptions.ContainerACL = permissions
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions)
Expand Down Expand Up @@ -1971,9 +1961,8 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsDeleteAndModify
}
}

access := container.PublicAccessTypeBlob
setAccessPolicyOptions := container.SetAccessPolicyOptions{
Access: &access,
ContainerACL: permissions,
}
setAccessPolicyOptions.ContainerACL = permissions
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions)
Expand All @@ -1987,7 +1976,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsDeleteAndModify
newId := "0004"
permissions[0].ID = &newId // Modify the remaining policy which is at index 0 in the new slice
setAccessPolicyOptions1 := container.SetAccessPolicyOptions{
Access: &access,
ContainerACL: permissions,
}
setAccessPolicyOptions1.ContainerACL = permissions
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions1)
Expand Down Expand Up @@ -2028,7 +2017,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsDeleteAllPolici
}

setAccessPolicyOptions := container.SetAccessPolicyOptions{
Access: to.Ptr(container.PublicAccessTypeBlob),
ContainerACL: permissions,
}
setAccessPolicyOptions.ContainerACL = permissions
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions)
Expand All @@ -2040,7 +2029,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsDeleteAllPolici
_require.EqualValues(resp.SignedIdentifiers, permissions)

setAccessPolicyOptions = container.SetAccessPolicyOptions{
Access: to.Ptr(container.PublicAccessTypeBlob),
ContainerACL: []*container.SignedIdentifier{},
}
setAccessPolicyOptions.ContainerACL = []*container.SignedIdentifier{}
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions)
Expand Down Expand Up @@ -2079,13 +2068,6 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsInvalidPolicyTi
},
}
}

setAccessPolicyOptions := container.SetAccessPolicyOptions{
Access: to.Ptr(container.PublicAccessTypeBlob),
}
setAccessPolicyOptions.ContainerACL = permissions
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions)
_require.NoError(err)
}

func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsNilPolicySlice() {
Expand Down Expand Up @@ -2133,7 +2115,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerSetPermissionsSignedIdentifie
}

setAccessPolicyOptions := container.SetAccessPolicyOptions{
Access: to.Ptr(container.PublicAccessTypeBlob),
ContainerACL: permissions,
}
setAccessPolicyOptions.ContainerACL = permissions
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions)
Expand Down
14 changes: 10 additions & 4 deletions sdk/storage/azblob/internal/exported/shared_key_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,19 @@ func compareHeaders(lhs, rhs string, tables [][]int) int {
return 0
}

w1 := tables[currLevel][lhs[i]]
if i >= lhsLen {
var w1, w2 int

// Check bounds before accessing lhs[i]
if i < lhsLen {
w1 = tables[currLevel][lhs[i]]
} else {
w1 = 0x1
}

w2 := tables[currLevel][rhs[j]]
if j >= rhsLen {
// Check bounds before accessing rhs[j]
if j < rhsLen {
w2 = tables[currLevel][rhs[j]]
} else {
w2 = 0x1
}

Expand Down
13 changes: 10 additions & 3 deletions sdk/storage/azblob/pageblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,18 @@ func (s *PageBlobUnrecordedTestsSuite) TestIncrementalCopy() {
_require.NoError(err)

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

_, err = containerClient.SetAccessPolicy(context.Background(), &container.SetAccessPolicyOptions{Access: to.Ptr(container.PublicAccessTypeBlob)})
accountSAS, err := testcommon.GetAccountSAS(sas.AccountPermissions{Read: true, Create: true, Write: true, List: true, Add: true, Delete: true},
sas.AccountResourceTypes{Service: true, Container: true, Object: true})
_require.NoError(err)

svcClientSAS, err := service.NewClientWithNoCredential(svcClient.URL()+"?"+accountSAS, nil)
_require.NoError(err)
containerClient := svcClientSAS.NewContainerClient(containerName)
_, err = containerClient.Create(context.Background(), nil)
_require.NoError(err)

defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

srcBlob := createNewPageBlob(context.Background(), _require, "src"+testcommon.GenerateBlobName(testName), containerClient)

Expand Down
7 changes: 5 additions & 2 deletions sdk/storage/azblob/pageblob/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ package pageblob_test
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"log"
"math/rand"
"os"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
Expand Down Expand Up @@ -50,7 +50,10 @@ func Example_pageblob_Client() {
for i := 0; i < 5; i++ {
count := int64(1024)
page := make([]byte, 2*pageblob.PageBytes)
rand.Read(page)
_, err := rand.Read(page)
if err != nil {
return
}
_, err = pageBlobClient.UploadPages(context.Background(), streaming.NopCloser(bytes.NewReader(page)),
blob.HTTPRange{Offset: int64(i) * count, Count: count}, nil)
handleError(err)
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 @@ -323,7 +323,7 @@ func (u userAgentTest) Do(req *policy.Request) (*http.Response, error) {

currentUserAgentHeader := req.Raw().Header.Get(userAgentHeader)
if !strings.HasPrefix(currentUserAgentHeader, "azsdk-go-azblob/"+exported.ModuleVersion) {
return nil, fmt.Errorf(currentUserAgentHeader + " user agent doesn't match expected agent: azsdk-go-azdatalake/v1.2.0 (go1.19.3; Windows_NT)")
return nil, fmt.Errorf("%s user agent doesn't match expected agent: azsdk-go-azdatalake/v1.2.0 (go1.19.3; Windows_NT)", currentUserAgentHeader)
}

return &http.Response{
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azfile/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azfile",
"Tag": "go/storage/azfile_4114e1e5d6"
"Tag": "go/storage/azfile_d1ce45b622"
}
Loading

0 comments on commit 40dcd1b

Please sign in to comment.