From 7dbed477d993ac7a823e54ce0a2a00d7ac40da3f Mon Sep 17 00:00:00 2001 From: Han Chong Date: Wed, 2 Oct 2024 09:08:40 +0800 Subject: [PATCH] Use random key for storage account in unit test --- test/Common/CustomTestStorageAccountProvider.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/Common/CustomTestStorageAccountProvider.cs b/test/Common/CustomTestStorageAccountProvider.cs index 3f6d3e45d..41337555a 100644 --- a/test/Common/CustomTestStorageAccountProvider.cs +++ b/test/Common/CustomTestStorageAccountProvider.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using System; using DurableTask.AzureStorage; using Microsoft.WindowsAzure.Storage; @@ -8,18 +9,25 @@ namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests { internal class CustomTestStorageAccountProvider : IStorageAccountProvider { - private const string CustomConnectionString = "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=dGVzdA==;EndpointSuffix=core.windows.net"; + private readonly string customConnectionString; private readonly string customConnectionName; public CustomTestStorageAccountProvider(string connectionName) { this.customConnectionName = connectionName; + this.customConnectionString = $"DefaultEndpointsProtocol=https;AccountName=test;AccountKey={GenerateRandomKey()};EndpointSuffix=core.windows.net"; } public CloudStorageAccount GetCloudStorageAccount(string name) => - CloudStorageAccount.Parse(name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : CustomConnectionString); + CloudStorageAccount.Parse(name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : this.customConnectionString); public StorageAccountDetails GetStorageAccountDetails(string name) => - new StorageAccountDetails { ConnectionString = name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : CustomConnectionString }; + new StorageAccountDetails { ConnectionString = name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : this.customConnectionString }; + + private static string GenerateRandomKey() + { + string key = Guid.NewGuid().ToString(); + return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(key)); + } } }