Skip to content
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

Fixed storage bug where blob, file, and directory names were not url … #11657

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
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: 2 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/src/BlobUriBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ private RequestUriBuilder BuildUri()
if (!string.IsNullOrWhiteSpace(BlobContainerName))
{
path.Append("/").Append(BlobContainerName);
if (!String.IsNullOrWhiteSpace(BlobName))
if (!string.IsNullOrWhiteSpace(BlobName))
{
path.Append("/").Append(BlobName);
path.Append("/").Append(Uri.EscapeDataString(BlobName));
}
}

Expand Down
22 changes: 22 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ public void Ctor_ConnectionString()
Assert.AreEqual("accountName", builder2.AccountName);
}

[Test]
[Ignore("Test framework doesn't allow recorded tests with connection string because the word 'Sanitized' is not base-64 encoded, so we can't pass connection string validation")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Live test then ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public async Task Ctor_ConnectionStringEscapeBlobName()
{
// Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = "!*'();[]:@&%=+$,/?#";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I recall (@rickle-msft plz chime in if I'm wrong here) @rickle-msft was/is chasing a bug in Java where German Umlauts got encoded with different target encoding (turns out Url encoding/percent encoding has target encoding...) than expected by server side. Might be worth adding that to test case suite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's target encoding?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the PR where this was addressed in Java.

Copy link
Member Author

@seanmcc-msft seanmcc-msft May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added German characters to all the new tests, they are still passing.


BlockBlobClient initalBlob = InstrumentClient(test.Container.GetBlockBlobClient(blobName));
var data = GetRandomBuffer(Constants.KB);

using var stream = new MemoryStream(data);
Response<BlobContentInfo> uploadResponse = await initalBlob.UploadAsync(stream);

// Act
BlobBaseClient blob = new BlobBaseClient(TestConfigDefault.ConnectionString, test.Container.Name, blobName, GetOptions());
Response<BlobProperties> propertiesResponse = await blob.GetPropertiesAsync();

// Assert
Assert.AreEqual(uploadResponse.Value.ETag, propertiesResponse.Value.ETag);
}

[Test]
public void Ctor_Uri()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private RequestUriBuilder BuildUri()
path.Append("/").Append(ShareName);
if (!string.IsNullOrWhiteSpace(DirectoryOrFilePath))
{
path.Append("/").Append(DirectoryOrFilePath);
path.Append("/").Append(Uri.EscapeDataString(DirectoryOrFilePath));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ public void Ctor_ConnectionString()
//Assert.AreEqual("accountName", builder.AccountName);
}

[Test]
[Ignore("Test framework doesn't allow recorded tests with connection string because the word 'Sanitized' is not base-64 encoded, so we can't pass connection string validation")]
public async Task Ctor_ConnectionStringEscapePath()
{
// Arrange
await using DisposingShare test = await GetTestShareAsync();
string directoryName = "!#@&=;";
ShareDirectoryClient initalDirectory = InstrumentClient(test.Share.GetDirectoryClient(directoryName));
Response<ShareDirectoryInfo> createResponse = await initalDirectory.CreateAsync();

// Act
ShareDirectoryClient directory = new ShareDirectoryClient(
TestConfigDefault.ConnectionString,
test.Share.Name,
directoryName,
GetOptions());
Response<ShareDirectoryProperties> propertiesResponse = await directory.GetPropertiesAsync();

// Assert
Assert.AreEqual(createResponse.Value.ETag, propertiesResponse.Value.ETag);
}

[Test]
public void DirectoryPathsParsing()
{
Expand Down
25 changes: 25 additions & 0 deletions sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ public void Ctor_ConnectionString()
//Assert.AreEqual("accountName", builder.AccountName);
}

[Test]
[Ignore("Test framework doesn't allow recorded tests with connection string because the word 'Sanitized' is not base-64 encoded, so we can't pass connection string validation")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be "Live" as well ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, my bad.

public async Task Ctor_ConnectionStringEscapePath()
{
// Arrange
await using DisposingShare test = await GetTestShareAsync();
string directoryName = "!#@&=;";
string fileName = "#$=;!";
ShareDirectoryClient directory = InstrumentClient(test.Share.GetDirectoryClient(directoryName));
await directory.CreateAsync();
ShareFileClient initalFile = InstrumentClient(directory.GetFileClient(fileName));
Response<ShareFileInfo> createResponse = await initalFile.CreateAsync(Constants.KB);

// Act
ShareFileClient file = new ShareFileClient(
TestConfigDefault.ConnectionString,
test.Share.Name,
$"{directoryName}/{fileName}",
GetOptions());
Response<ShareFileProperties> propertiesResponse = await file.GetPropertiesAsync();

// Assert
Assert.AreEqual(createResponse.Value.ETag, propertiesResponse.Value.ETag);
}

[Test]
public void FilePathsParsing()
{
Expand Down