Skip to content

Commit

Permalink
Adding test coverage for account SAS generated in different resource … (
Browse files Browse the repository at this point in the history
  • Loading branch information
amnguye authored Jul 11, 2022
1 parent 407ce06 commit 2feda32
Show file tree
Hide file tree
Showing 116 changed files with 17,141 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Azure.Management.Storage\src\Microsoft.Azure.Management.Storage.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(AzureStorageSharedTestSources)..\Sas\*.cs" LinkBase="Shared\Sas" />
<Compile Include="$(AzureStorageSharedTestSources)\**\*.cs" LinkBase="Shared" />
<None Include="$(AzureStorageSharedTestSources)\*.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
69 changes: 69 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobSasTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Azure.Storage.Blobs.Tests;
using Azure.Storage.Sas;
using Azure.Storage.Test.Shared;
using NUnit.Framework;

namespace Azure.Storage.Blobs.Test
{
Expand Down Expand Up @@ -305,5 +306,73 @@ public async Task AccountSas_AllPermissions()
AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions()));
await sasBlobClient.GetPropertiesAsync();
}

private async Task InvokeAccountSasTest(
string permissions = "rwdylacuptfi",
string services = "bqtf",
string resourceType = "sco")
{
// Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewBlobName();
AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName));
await blob.CreateAsync();

// Generate a SAS that would set the srt / ResourceTypes in a different order than
// the .NET SDK would normally create the SAS
TestAccountSasBuilder accountSasBuilder = new TestAccountSasBuilder(
permissions: permissions,
expiresOn: Recording.UtcNow.AddDays(1),
services: services,
resourceTypes: resourceType);

UriBuilder blobUriBuilder = new UriBuilder(blob.Uri)
{
Query = accountSasBuilder.ToTestSasQueryParameters(Tenants.GetNewSharedKeyCredentials()).ToString()
};

// Assert
AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.Uri, GetOptions()));
await sasBlobClient.GetPropertiesAsync();
}

[RecordedTest]
[TestCase("sco")]
[TestCase("soc")]
[TestCase("cos")]
[TestCase("ocs")]
[TestCase("os")]
[TestCase("oc")]
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2020_06_12)]
public async Task AccountSas_ResourceTypeOrder(string resourceType)
{
await InvokeAccountSasTest(resourceType: resourceType);
}

[RecordedTest]
[TestCase("bfqt")]
[TestCase("qftb")]
[TestCase("tqfb")]
[TestCase("bqt")]
[TestCase("qb")]
[TestCase("fb")]
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2020_06_12)]
public async Task AccountSas_ServiceOrder(string services)
{
await InvokeAccountSasTest(services: services);
}

[RecordedTest]
[TestCase("rwdylacuptfi")]
[TestCase("cuprwdylatfi")]
[TestCase("cudypafitrwl")]
[TestCase("cuprwdyla")]
[TestCase("rywdlcaup")]
[TestCase("larwdycup")]
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2020_06_12)]
public async Task AccountSas_PermissionsOrder(string permissions)
{
await InvokeAccountSasTest(permissions: permissions);
}
}
}

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.

Loading

0 comments on commit 2feda32

Please sign in to comment.