diff --git a/tools/Azure.Mcp.Tools.Speech/src/Services/Recognizers/FastTranscriptionRecognizer.cs b/tools/Azure.Mcp.Tools.Speech/src/Services/Recognizers/FastTranscriptionRecognizer.cs index b5025a2b13..7b95a02da0 100644 --- a/tools/Azure.Mcp.Tools.Speech/src/Services/Recognizers/FastTranscriptionRecognizer.cs +++ b/tools/Azure.Mcp.Tools.Speech/src/Services/Recognizers/FastTranscriptionRecognizer.cs @@ -8,7 +8,6 @@ using Azure.Mcp.Core.Options; using Azure.Mcp.Core.Services.Azure; using Azure.Mcp.Core.Services.Azure.Tenant; -using Azure.Mcp.Core.Services.Http; using Azure.Mcp.Tools.Speech.Models.FastTranscription; using Microsoft.Extensions.Logging; @@ -19,12 +18,12 @@ namespace Azure.Mcp.Tools.Speech.Services.Recognizers; /// public class FastTranscriptionRecognizer( ITenantService tenantService, - IHttpClientService httpClientService, + IHttpClientFactory httpClientFactory, ILogger logger) : BaseAzureService(tenantService), IFastTranscriptionRecognizer { private readonly ILogger _logger = logger; - private readonly IHttpClientService _httpClientService = httpClientService; + private readonly IHttpClientFactory _httpClientFactory = httpClientFactory; /// public async Task RecognizeAsync( @@ -124,8 +123,9 @@ public async Task RecognizeAsync( Headers = { Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token) } }; - // Make the request using HttpClient from service - var response = await _httpClientService.DefaultClient.SendAsync(requestMessage, cancellationToken); + // Make the request using HttpClient from factory + using var httpClient = _httpClientFactory.CreateClient(); + var response = await httpClient.SendAsync(requestMessage, cancellationToken); var responseContent = await response.Content.ReadAsStringAsync(cancellationToken); if (!response.IsSuccessStatusCode) diff --git a/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/SpeechCommandTests.cs b/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/SpeechCommandTests.cs index 92c46029cc..919cb53369 100644 --- a/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/SpeechCommandTests.cs +++ b/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/SpeechCommandTests.cs @@ -4,14 +4,50 @@ using System.Text.Json; using Azure.Mcp.Tests; using Azure.Mcp.Tests.Client; +using Azure.Mcp.Tests.Client.Helpers; +using Azure.Mcp.Tests.Generated.Models; using Azure.Mcp.Tools.Speech.Models; using Azure.Mcp.Tools.Speech.Models.Realtime; using Xunit; namespace Azure.Mcp.Tools.Speech.LiveTests; -public class SpeechCommandTests(ITestOutputHelper output) : CommandTestsBase(output) +public class SpeechCommandTests(ITestOutputHelper output, TestProxyFixture fixture) : RecordedCommandTestsBase(output, fixture) { + // Sanitize subscription IDs in URIs + public override List UriRegexSanitizers => new() + { + new UriRegexSanitizer(new UriRegexSanitizerBody + { + Regex = "/subscriptions/(?[^/]+)/", + GroupForReplace = "sub", + Value = "00000000-0000-0000-0000-000000000000" + }) + }; + + // Sanitize authorization tokens in headers + public override List HeaderRegexSanitizers => new() + { + new HeaderRegexSanitizer(new HeaderRegexSanitizerBody("Authorization") + { + Regex = "Bearer (?.+)", + GroupForReplace = "token", + Value = "Sanitized" + }) + }; + + // Sanitize cognitive services hostnames in body content + public override List BodyRegexSanitizers => new() + { + // Sanitizes all hostnames in URLs to remove actual cognitive services endpoint names + new BodyRegexSanitizer(new BodyRegexSanitizerBody + { + Regex = "(?<=http://|https://)(?[^/?\\.]+)\\.cognitiveservices\\.azure\\.com", + GroupForReplace = "host", + Value = "sanitized" + }) + }; + #region SpeechToText Tests [Fact] diff --git a/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/assets.json b/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/assets.json new file mode 100644 index 0000000000..baf6fec3c1 --- /dev/null +++ b/tools/Azure.Mcp.Tools.Speech/tests/Azure.Mcp.Tools.Speech.LiveTests/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "", + "TagPrefix": "Azure.Mcp.Tools.Speech.LiveTests", + "Tag": "" +}