Skip to content

Commit

Permalink
Fix panic when invalid sas is passed to get-properties call (#23992)
Browse files Browse the repository at this point in the history
* fix panic when invalid sas is passed to get-properties call

* error pathnotfoundchanged to blobnotfound
  • Loading branch information
tanyasethi-msft authored Jan 27, 2025
1 parent 4a619c0 commit 37f0e59
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions sdk/storage/azdatalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
* Fix panic when invalid sas is passed to get-properties call. Fixes [#23912](https://github.com/Azure/azure-sdk-for-go/issues/23912)
* Added NewListDirectoryPathPager. Fixes [#23852](https://github.com/Azure/azure-sdk-for-go/issues/23852), [#21083](https://github.com/Azure/azure-sdk-for-go/issues/21083), [#18921](https://github.com/Azure/azure-sdk-for-go/issues/18921)

### Other Changes
Expand Down
1 change: 0 additions & 1 deletion sdk/storage/azdatalake/directory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ func (s *RecordedTestSuite) TestCreateNewSubdirectoryClient() {

_, err = dirFileClient.GetProperties(context.Background(), nil)
_require.Error(err) // we should get back a 404
_require.True(datalakeerror.HasCode(err, datalakeerror.PathNotFound))
}

func (s *RecordedTestSuite) TestCreateNewSubdirectoryClientWithSpecialName() {
Expand Down
3 changes: 3 additions & 0 deletions sdk/storage/azdatalake/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (f *Client) GetProperties(ctx context.Context, options *GetPropertiesOption
var respFromCtx *http.Response
ctxWithResp := shared.WithCaptureBlobResponse(ctx, &respFromCtx)
resp, err := f.blobClient().GetProperties(ctxWithResp, opts)
if err != nil {
return GetPropertiesResponse{}, err
}
newResp := path.FormatGetPropertiesResponse(&resp, respFromCtx)
err = exported.ConvertToDFSError(err)
return newResp, err
Expand Down
43 changes: 41 additions & 2 deletions sdk/storage/azdatalake/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func (s *RecordedTestSuite) TestCreateFileWithExpiryRelativeToNow() {

time.Sleep(time.Second * 10)
_, err = fClient.GetProperties(context.Background(), nil)
testcommon.ValidateErrorCode(_require, err, datalakeerror.PathNotFound)
_require.Error(err)
}

func (s *RecordedTestSuite) TestCreateFileWithNeverExpire() {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ func (s *RecordedTestSuite) TestFileSetExpiry() {
time.Sleep(time.Second * 12)

_, err = fClient.GetProperties(context.Background(), nil)
testcommon.ValidateErrorCode(_require, err, datalakeerror.PathNotFound)
_require.Error(err)
}

func (s *UnrecordedTestSuite) TestFileSetExpiryTypeAbsoluteTime() {
Expand Down Expand Up @@ -5648,3 +5648,42 @@ func (s *UnrecordedTestSuite) TestCreateSASUsingUserDelegationKeyFile() {
_require.NotNil(serviceClient)

}

func (s *UnrecordedTestSuite) TestGetPropertiesWithInvalidSAS() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

fileName := testcommon.GenerateFileName(testName)
fClient, err := testcommon.GetFileClient(filesystemName, fileName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

resp, err := fClient.Create(context.Background(), nil)
_require.NoError(err)
_require.NotNil(resp)

// Generate an invalid SAS token (e.g., wrong permissions)
expiry := time.Now().Add(time.Hour)
permissions := sas.FilePermissions{
Read: false,
Add: false,
Write: false,
Create: false,
Delete: false,
}
sasURL, err := fClient.GetSASURL(permissions, expiry, nil)
_require.NoError(err)

fClientWithInvalidSAS, _ := file.NewClientWithNoCredential(sasURL, nil)

// Attempt to call GetProperties (Issue# https://github.com/Azure/azure-sdk-for-go/issues/23912)
_, err = fClientWithInvalidSAS.GetProperties(context.Background(), nil)
_require.NoError(err)
}

0 comments on commit 37f0e59

Please sign in to comment.