Skip to content

Commit

Permalink
Use random key for storage account in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hctan committed Oct 2, 2024
1 parent 32bb7ab commit 7dbed47
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/Common/CustomTestStorageAccountProvider.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
// 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;

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));
}
}
}

0 comments on commit 7dbed47

Please sign in to comment.