Skip to content
Draft
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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageVersion Include="Azure.Extensions.AspNetCore.DataProtection.Blobs" Version="1.3.4" />
<PackageVersion Include="Azure.Extensions.AspNetCore.DataProtection.Keys" Version="1.2.3" />
<PackageVersion Include="Azure.Identity" Version="1.12.0" />
<PackageVersion Include="Azure.Messaging.EventHubs" Version="5.11.5" />
<PackageVersion Include="Azure.ResourceManager.EventHubs" Version="1.1.0" />
<PackageVersion Include="Azure.ResourceManager.ServiceBus" Version="1.1.0-beta.7" />
<PackageVersion Include="Azure.ResourceManager.Storage" Version="1.3.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;
using Azure.ResourceManager.EventHubs;
using Azure.ResourceManager.EventHubs.Models;
using Azure.Security.KeyVault.Secrets;
Expand Down Expand Up @@ -80,6 +83,37 @@ public async Task RotateConnectionStringSecretTest()
Assert.That(connectionStringSecret.Value.Value, Is.EqualTo(accessKeysRotated.First()));
}

[Test]
public async Task ManagedIdentityConnectionTest()
{
// Test direct managed identity connection to the same Event Hub
var credential = new DefaultAzureCredential();
string fullyQualifiedNamespace = $"{Namespace}.servicebus.windows.net";

var producer = new EventHubProducerClient(fullyQualifiedNamespace, Name, credential);

try
{
// Test that we can connect and get partition information
var partitions = await producer.GetPartitionIdsAsync();
Assert.That(partitions, Is.Not.Empty, "Should be able to get partition IDs using managed identity");

// Test that we can send a test event
var testEvent = new EventData("MI test message");
await producer.SendAsync(new[] { testEvent });

Assert.Pass("Managed identity authentication successful");
}
catch (Exception ex)
{
Assert.Fail($"Managed identity authentication failed: {ex.Message}");
}
finally
{
await producer.DisposeAsync();
}
}

[OneTimeTearDown]
public async Task Cleanup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Messaging.EventHubs" />
<PackageReference Include="Microsoft.DotNet.Internal.DependencyInjection.Testing" />
</ItemGroup>

Expand Down