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
10 changes: 8 additions & 2 deletions src/DurableTask.ServiceBus/Tracking/BlobStorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@ private async Task<BlobClient> GetCloudBlobClientAsync(string containerNameSuffi
public async Task<IEnumerable<BlobContainerItem>> ListContainersAsync()
{
List<BlobContainerItem> results = new List<BlobContainerItem>();
var response = this.blobServiceClient.GetBlobContainersAsync();
// Use the service client's prefix parameter to only enumerate containers that start with the
// configured containerNamePrefix. Also apply a defensive in-memory filter in case of any
// unexpected differences in casing or service behavior.
var response = this.blobServiceClient.GetBlobContainersAsync(prefix: this.containerNamePrefix);
await foreach (var container in response)
{
results.Add(container);
if (container.Name != null && container.Name.StartsWith(this.containerNamePrefix, StringComparison.OrdinalIgnoreCase))
{
results.Add(container);
}
}
return results;
}
Expand Down
28 changes: 28 additions & 0 deletions test/DurableTask.ServiceBus.Tests/BlobStorageClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,33 @@ public async Task TestDeleteContainers()
containers = (await this.blobStorageClient.ListContainersAsync()).ToList();
Assert.AreEqual(0, containers.Count);
}

[TestMethod]
public async Task TestListContainersOnlyWithPrefix()
{
// Create a container that does NOT use the current client's prefix
string storageConnectionString = TestHelpers.GetTestSetting("StorageConnectionString");
var serviceClient = new BlobServiceClient(storageConnectionString);

string otherHub = "otherhubprefix" + Guid.NewGuid().ToString("N").Substring(0, 8);
string otherPrefix = BlobStorageClientHelper.BuildContainerNamePrefix(otherHub);
string otherContainerName = BlobStorageClientHelper.BuildContainerName(otherPrefix, "message-20100101");

var otherContainer = serviceClient.GetBlobContainerClient(otherContainerName);
await otherContainer.CreateIfNotExistsAsync();

try
{
// Ensure the externally-created container is not returned by the client's listing
List<BlobContainerItem> containers = (await this.blobStorageClient.ListContainersAsync()).ToList();
Assert.IsFalse(containers.Any(c => string.Equals(c.Name, otherContainerName, StringComparison.OrdinalIgnoreCase)),
"ListContainersAsync returned a container that does not match the client's prefix.");
}
finally
{
// Clean up the external container explicitly
await otherContainer.DeleteIfExistsAsync();
}
}
}
}
Loading