Skip to content

Commit 311d8f1

Browse files
authored
[Messaging] Fix Functions test host credential use (Azure#48389)
The focus of these changes is to fix the approach used for token credential management in the Function extensions end-to-end tests for Event Hubs and Service Bus. The previous approach used simple logic to set in-memory configuration with assumptions about the test environment. These assumptions are no longer accurate with the security changes in the testing pipelines. The new approach delegates to the test environment for credential management, as it has the conditional logic for environmental factors needed for credential selection and creation. The configuration-to-credential mapping and creation logic is part of the `Microsoft.Extensions.Azure` package and has full test coverage there; there is no benefit to duplicating test environment logic just to force Function configuration to control the credential locally for the test host.
1 parent af60779 commit 311d8f1

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubEndToEndTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,7 @@ await AssertCanSendReceiveMessage(host =>
242242
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>()
243243
{
244244
{"TestConnection:fullyQualifiedNamespace", EventHubsTestEnvironment.Instance.FullyQualifiedNamespace},
245-
{"TestConnection:clientId", EventHubsTestEnvironment.Instance.ClientId},
246-
{"TestConnection:clientSecret", EventHubsTestEnvironment.Instance.ClientSecret},
247-
{"TestConnection:tenantId", EventHubsTestEnvironment.Instance.TenantId},
248-
{"AzureWebJobsStorage:serviceUri", GetServiceUri()},
249-
{"AzureWebJobsStorage:clientId", EventHubsTestEnvironment.Instance.ClientId},
250-
{"AzureWebJobsStorage:clientSecret", EventHubsTestEnvironment.Instance.ClientSecret},
251-
{"AzureWebJobsStorage:tenantId", EventHubsTestEnvironment.Instance.TenantId},
245+
{"AzureWebJobsStorage:serviceUri", GetServiceUri()}
252246
})));
253247
}
254248

sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/WebJobsEventHubTestBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Threading.Tasks;
7-
using Azure.Core.Diagnostics;
87
using Azure.Messaging.EventHubs.Tests;
98
using Microsoft.Azure.WebJobs.Host.TestCommon;
9+
using Microsoft.Extensions.Azure;
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.Extensions.Hosting;
1212
using Microsoft.Extensions.Logging;
@@ -64,6 +64,13 @@ protected void ConfigureTestEventHub(IHostBuilder builder)
6464

6565
var hostBuilder = new HostBuilder();
6666
hostBuilder
67+
.ConfigureServices(services =>
68+
{
69+
services.AddAzureClients(clientBuilder =>
70+
{
71+
clientBuilder.UseCredential(EventHubsTestEnvironment.Instance.Credential);
72+
});
73+
})
6774
.ConfigureAppConfiguration(builder =>
6875
{
6976
builder.AddInMemoryCollection(new Dictionary<string, string>()

sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/tests/WebJobsServiceBusTestBase.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
8-
using System.Runtime.Serialization;
9-
using System.Threading;
10-
using System.Threading.Tasks;
11-
using System.Xml;
124
using Azure.Core.TestFramework;
135
using Azure.Messaging.ServiceBus;
146
using Azure.Messaging.ServiceBus.Administration;
157
using Azure.Messaging.ServiceBus.Tests;
168
using Microsoft.Azure.WebJobs.Host.TestCommon;
17-
using Microsoft.Azure.WebJobs.ServiceBus;
9+
using Microsoft.Extensions.Azure;
1810
using Microsoft.Extensions.Configuration;
1911
using Microsoft.Extensions.DependencyInjection;
2012
using Microsoft.Extensions.Hosting;
2113
using Microsoft.Extensions.Logging;
2214
using NUnit.Framework;
15+
using System;
16+
using System.Collections.Generic;
17+
using System.IO;
18+
using System.Linq;
19+
using System.Runtime.Serialization;
20+
using System.Threading;
21+
using System.Threading.Tasks;
22+
using System.Xml;
2323
using static Azure.Messaging.ServiceBus.Tests.ServiceBusScope;
2424

2525
namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
@@ -144,9 +144,6 @@ protected IHost BuildHost<TJobClass>(
144144
if (useTokenCredential)
145145
{
146146
settings.Add("AzureWebJobsServiceBus:fullyQualifiedNamespace", ServiceBusTestEnvironment.Instance.FullyQualifiedNamespace);
147-
settings.Add("AzureWebJobsServiceBus:clientId", ServiceBusTestEnvironment.Instance.ClientId);
148-
settings.Add("AzureWebJobsServiceBus:clientSecret", ServiceBusTestEnvironment.Instance.ClientSecret);
149-
settings.Add("AzureWebJobsServiceBus:tenantId", ServiceBusTestEnvironment.Instance.TenantId);
150147
}
151148
else
152149
{
@@ -156,6 +153,11 @@ protected IHost BuildHost<TJobClass>(
156153
var hostBuilder = new HostBuilder()
157154
.ConfigureServices(s =>
158155
{
156+
s.AddAzureClients(clientBuilder =>
157+
{
158+
clientBuilder.UseCredential(ServiceBusTestEnvironment.Instance.Credential);
159+
});
160+
159161
s.Configure<HostOptions>(opts => opts.ShutdownTimeout = HostShutdownTimeout);
160162
// Configure ServiceBusEndToEndTestService before WebJobs stuff so that the ServiceBusEndToEndTestService.StopAsync will be called after
161163
// the WebJobsHost.StopAsync (service that is started first will be stopped last by the IHost).

0 commit comments

Comments
 (0)