Skip to content

Commit

Permalink
Added x-ms-file-request-itent to PutRangeFromUrl (Azure#39278)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcc-msft authored and matthohn-msft committed Oct 27, 2023
1 parent 31e2545 commit 8c5dfc5
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 15 deletions.
7 changes: 1 addition & 6 deletions sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Release History

## 12.17.0-beta.2 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed
- Fixed bug where the x-ms-file-request-intent request header was not being sent for ShareFileClient.UploadRangeFromUri() and .UploadRangeFromUriAsync().

### Other Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Files.Shares/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.Files.Shares",
"Tag": "net/storage/Azure.Storage.Files.Shares_29361a65db"
"Tag": "net/storage/Azure.Storage.Files.Shares_6317487064"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Files.Shares/src/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Run `dotnet build /t:GenerateCode` to generate code.

``` yaml
input-file:
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/ccae65b66ac23a9fd891ba86f45abc4372a9c688/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-01-03/file.json
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/4bafbf3ab1532e390ad5757433679e9ebb5cbf38/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-08-03/file.json
generation1-convenience-client: true
# https://github.com/Azure/autorest/issues/4075
skip-semantics-validation: true
Expand Down
78 changes: 75 additions & 3 deletions sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3331,14 +3331,22 @@ await fileClient.UploadRangeAsync(
}
}

[RecordedTest]
[ServiceVersion(Min = ShareClientOptions.ServiceVersion.V2021_04_10)]
public async Task UploadRangeAsync_OAuth()
{
var data = GetRandomBuffer(Constants.KB);

await using DisposingFile test = await SharesClientBuilder.GetTestFileAsync(
SharesClientBuilder.GetServiceClient_OAuth());
ShareFileClient file = test.File;
string shareName = GetNewShareName();
ShareServiceClient sharedKeyServiceClient = SharesClientBuilder.GetServiceClient_OAuthAccount_SharedKey();
await using DisposingShare sharedKeyShare = await GetTestShareAsync(sharedKeyServiceClient, shareName);
ShareServiceClient oauthServiceClient = SharesClientBuilder.GetServiceClient_OAuth();

string directoryName = GetNewDirectoryName();
ShareDirectoryClient directory = InstrumentClient(oauthServiceClient.GetShareClient(shareName).GetDirectoryClient(directoryName));
await directory.CreateAsync();

ShareFileClient file = await directory.CreateFileAsync(GetNewFileName(), Constants.MB);

using (var stream = new MemoryStream(data))
{
Expand Down Expand Up @@ -4404,6 +4412,70 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
}
}

[RecordedTest]
[ServiceVersion(Min = ShareClientOptions.ServiceVersion.V2021_04_10)]
public async Task UploadRangeFromUriAsync_OAuth()
{
string shareName = GetNewShareName();
ShareServiceClient sharedKeyServiceClient = SharesClientBuilder.GetServiceClient_OAuthAccount_SharedKey();
await using DisposingShare sharedKeyShare = await GetTestShareAsync(sharedKeyServiceClient, shareName);
ShareServiceClient oauthServiceClient = SharesClientBuilder.GetServiceClient_OAuth();
ShareClient oauthShareClient = InstrumentClient(oauthServiceClient.GetShareClient(shareName));

// Arrange
var directoryName = GetNewDirectoryName();
var directory = InstrumentClient(oauthShareClient.GetDirectoryClient(directoryName));
await directory.CreateIfNotExistsAsync();

var fileName = GetNewFileName();
var data = GetRandomBuffer(Constants.KB);
var sourceFile = InstrumentClient(directory.GetFileClient(fileName));
await sourceFile.CreateAsync(maxSize: 1024);
using (var stream = new MemoryStream(data))
{
await sourceFile.UploadRangeAsync(new HttpRange(0, 1024), stream);
}

var destFile = directory.GetFileClient("destFile");
await destFile.CreateAsync(maxSize: 1024);
var destRange = new HttpRange(256, 256);
var sourceRange = new HttpRange(512, 256);

var sasFile = InstrumentClient(
GetServiceClient_FileServiceSasShare(shareName)
.GetShareClient(shareName)
.GetDirectoryClient(directoryName)
.GetFileClient(fileName));

// Act
Response<ShareFileUploadInfo> response = await destFile.UploadRangeFromUriAsync(
sourceUri: sasFile.Uri,
range: destRange,
sourceRange: sourceRange);

// Assert
// Ensure that we grab the whole ETag value from the service without removing the quotes
Assert.AreEqual(response.Value.ETag.ToString(), $"\"{response.GetRawResponse().Headers.ETag}\"");

// Ensure the contents of the source and destination Files after the UploadRangeFromUri call
var sourceDownloadResponse = await sourceFile.DownloadAsync(new ShareFileDownloadOptions
{
Range = sourceRange
});
var destDownloadResponse = await destFile.DownloadAsync(new ShareFileDownloadOptions
{
Range = destRange
});

var sourceStream = new MemoryStream();
await sourceDownloadResponse.Value.Content.CopyToAsync(sourceStream);

var destStream = new MemoryStream();
await destDownloadResponse.Value.Content.CopyToAsync(destStream);

TestHelper.AssertSequenceEqual(sourceStream.ToArray(), destStream.ToArray());
}

[RecordedTest]
public async Task ListHandles()
{
Expand Down

0 comments on commit 8c5dfc5

Please sign in to comment.