Skip to content

Rename Sorce Escaping #24288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/storage/azdatalake/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ func (f *Client) GetProperties(ctx context.Context, options *GetPropertiesOption
// Rename renames a file. The original file will no longer exist and the client will be stale.
func (f *Client) Rename(ctx context.Context, destinationPath string, options *RenameOptions) (RenameResponse, error) {
var newBlobClient *blockblob.Client
u, err := url.QueryUnescape(destinationPath)
if err != nil || u == destinationPath {
destinationPath = url.QueryEscape(destinationPath)
}
destinationPath = strings.Trim(strings.TrimSpace(destinationPath), "/")
if len(destinationPath) == 0 {
return RenameResponse{}, errors.New("destination path must not be empty")
Expand Down
41 changes: 41 additions & 0 deletions sdk/storage/azdatalake/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,47 @@ func (s *UnrecordedTestSuite) TestFileRenameUsingSAS() {
testcommon.ValidateErrorCode(_require, err, datalakeerror.PathNotFound)
}

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

cred, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDatalake)
_require.NoError(err)

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)

perms := sas.FilePermissions{Read: true, Create: true, Write: true, Move: true, Delete: true, List: true}
sasQueryParams, err := sas.DatalakeSignatureValues{
Protocol: sas.ProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
ExpiryTime: time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
FileSystemName: filesystemName,
Permissions: perms.String(),
}.SignWithSharedKey(cred)
_require.NoError(err)

sasToken := sasQueryParams.Encode()
dirClient := fsClient.NewDirectoryClient("dir1")
srcFileClient, err := file.NewClientWithNoCredential(dirClient.DFSURL()+"/file1?"+sasToken, nil)
_require.NoError(err)

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

destPathWithSAS := "dir1/lör 006?" + sasToken
_, err = srcFileClient.Rename(context.Background(), destPathWithSAS, nil)
_require.NoError(err)

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

func (s *RecordedTestSuite) TestRenameNoOptions() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down
Loading