Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<Compile Include="$(AzureStorageSharedTestSources)\**\*.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Remove="$(AzureStorageSharedTestSources)\AzuriteFixture.cs" />
<Compile Remove="$(AzureStorageSharedTestSources)\AzuriteNUnitFixture.cs" />
<Compile Remove="$(AzureStorageSharedTestSources)\StorageTestBase.SasVersion.cs" />
<None Include="$(AzureStorageSharedTestSources)\*.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Azure.Core.TestFramework;
using Azure.Storage.Sas;
using NUnit.Framework;

namespace Azure.Storage.Test.Shared
Expand All @@ -17,7 +20,32 @@ public void SetSasVersion()
// WARN! Never ever override SAS version in Live mode. We should test the default there.

// TODO Uncomment this to record/playback with different sas version
// SasQueryParametersInternals.DefaultSasVersionInternal = "2020-08-04";
// SetSasVersion("2020-08-04");
}
}

private void SetSasVersion(string version)
{
// The SasQueryParametersInternals is shared source and compiled also into many assemblies which is technically separate class.
// We're using reflection to set it everywhere.
// The alternative of making it all open to all test packages isn't great because it would lead to name clash.
SetSasVersionInAssemblies(version,
"Azure.Storage.Common",
"Azure.Storage.Blobs",
"Azure.Storage.Files.DataLake",
"Azure.Storage.Files.Shares",
"Azure.Storage.Queues");
}

private void SetSasVersionInAssemblies(string version, params string[] assemblyNames)
{
IEnumerable<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => assemblyNames.Contains(a.GetName().Name));
foreach (Assembly assembly in assemblies)
{
Type sasQueryParametersInternals = assembly.GetType("Azure.Storage.Sas.SasQueryParametersInternals");
PropertyInfo defaultSasVersionInternal = sasQueryParametersInternals.GetProperty(
"DefaultSasVersionInternal", BindingFlags.NonPublic | BindingFlags.Static);
defaultSasVersionInternal.SetValue(null, version);
}
}
}
Expand Down