Skip to content

Commit de16cad

Browse files
Migrate communication to test proxy (Azure#25736)
* Migrate communication to test proxy * alignment * fix
1 parent b19ea8f commit de16cad

File tree

23 files changed

+2850
-2794
lines changed

23 files changed

+2850
-2794
lines changed

sdk/communication/Azure.Communication.CallingServer/tests/Infrastructure/CallingServerLiveTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected string GetGroupId()
8383
return GROUP_IDENTIFIER;
8484
}
8585

86-
public CallingServerLiveTestBase(bool isAsync) : base(isAsync, useLegacyTransport: true)
86+
public CallingServerLiveTestBase(bool isAsync) : base(isAsync)
8787
=> Sanitizer = new CallingServerRecordedTestSanitizer();
8888

8989
public bool SkipCallingServerInteractionLiveTests

sdk/communication/Azure.Communication.CallingServer/tests/Infrastructure/CallingServerRecordedTestSanitizer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// Licensed under the MIT License.
33

44
using Azure.Communication.Pipeline;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text.RegularExpressions;
5+
using Azure.Core.TestFramework.Models;
86

97
namespace Azure.Communication.CallingServer.Tests
108
{
119
public class CallingServerRecordedTestSanitizer : CommunicationRecordedTestSanitizer
1210
{
13-
private static readonly Regex _phoneNumberRegEx = new Regex(@"\\u002B[0-9]{11,15}", RegexOptions.Compiled);
11+
private const string PhoneNumberRegEx = @"\\u002B[0-9]{11,15}";
1412

15-
public override string SanitizeTextBody(string contentType, string body)
16-
=> base.SanitizeTextBody(contentType, _phoneNumberRegEx.Replace(body, SanitizeValue));
13+
public CallingServerRecordedTestSanitizer()
14+
{
15+
BodyRegexSanitizers.Add(new BodyRegexSanitizer(PhoneNumberRegEx, SanitizeValue));
16+
}
1717
}
1818
}

sdk/communication/Azure.Communication.Chat/tests/Infrastructure/ChatLiveTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Azure.Communication.Chat.Tests
88
{
99
public class ChatLiveTestBase : RecordedTestBase<ChatTestEnvironment>
1010
{
11-
public ChatLiveTestBase(bool isAsync) : base(isAsync, useLegacyTransport: true)
11+
public ChatLiveTestBase(bool isAsync) : base(isAsync)
1212
=> Sanitizer = new ChatRecordedTestSanitizer();
1313

1414
/// <summary>
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
using System.Linq;
64
using Azure.Communication.Pipeline;
7-
using Azure.Core;
5+
using Azure.Core.TestFramework;
86

97
namespace Azure.Communication.Chat.Tests
108
{
@@ -14,13 +12,5 @@ public class ChatRecordedTestSanitizer : CommunicationRecordedTestSanitizer
1412

1513
public ChatRecordedTestSanitizer() : base()
1614
=> AddJsonPathSanitizer("$..token");
17-
18-
protected override void SanitizeAuthenticationHeader(IDictionary<string, string[]> headers)
19-
{
20-
if (headers.ContainsKey(HttpHeader.Names.UserAgent) && headers[HttpHeader.Names.UserAgent].Any(x => x.Contains("Communication.Chat")))
21-
headers[HttpHeader.Names.Authorization] = new[] { SanitizedUnsignedUserTokenValue };
22-
else
23-
base.SanitizeAuthenticationHeader(headers);
24-
}
2515
}
2616
}

sdk/communication/Azure.Communication.Chat/tests/SessionRecords/ChatClientsLiveTests/ReadReceipt_GS.json

Lines changed: 183 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Chat/tests/SessionRecords/ChatClientsLiveTests/ReadReceipt_GSAsync.json

Lines changed: 183 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Chat/tests/SessionRecords/ChatClientsLiveTests/Thread_CGUD__Participant_AUR__Message_GSU__Notification_T.json

Lines changed: 1200 additions & 1150 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Chat/tests/SessionRecords/ChatClientsLiveTests/Thread_CGUD__Participant_AUR__Message_GSU__Notification_TAsync.json

Lines changed: 1201 additions & 1151 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
using Azure.Communication.Tests;
6-
using Azure.Core;
74
using Azure.Core.TestFramework;
85

96
namespace Azure.Communication.Pipeline
107
{
118
public class CommunicationRecordedTestSanitizer : RecordedTestSanitizer
129
{
13-
protected virtual void SanitizeAuthenticationHeader(IDictionary<string, string[]> headers)
10+
public CommunicationRecordedTestSanitizer()
1411
{
15-
if (headers.ContainsKey(HttpHeader.Names.Authorization))
16-
headers[HttpHeader.Names.Authorization] = new[] { SanitizeValue };
17-
}
18-
19-
public override void SanitizeHeaders(IDictionary<string, string[]> headers)
20-
{
21-
SanitizeAuthenticationHeader(headers);
22-
if (headers.ContainsKey("x-ms-content-sha256"))
23-
headers["x-ms-content-sha256"] = new[] { SanitizeValue };
24-
}
25-
26-
public override string SanitizeVariable(string variableName, string environmentVariableValue)
27-
=> variableName switch
28-
{
29-
CommunicationTestEnvironment.LiveTestDynamicConnectionStringEnvironmentVariableName => SanitizeConnectionString(environmentVariableValue),
30-
CommunicationTestEnvironment.LiveTestStaticConnectionStringEnvironmentVariableName => SanitizeConnectionString(environmentVariableValue),
31-
_ => base.SanitizeVariable(variableName, environmentVariableValue)
32-
};
33-
34-
protected static string SanitizeConnectionString(string connectionString)
35-
{
36-
const string accessKey = "accesskey";
37-
const string someBase64String = "Kg==";
38-
39-
var parsed = ConnectionString.Parse(connectionString, allowEmptyValues: true);
40-
parsed.Replace(accessKey, someBase64String);
41-
42-
return parsed.ToString();
12+
SanitizedHeaders.Add("x-ms-content-sha256");
4313
}
4414
}
4515
}

sdk/communication/Azure.Communication.Common/tests/CommunicationTestEnvironment.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ public class CommunicationTestEnvironment : TestEnvironment
1414
private const string SkipIntSmsTestEnvironmentVariableName = "SKIP_INT_SMS_TEST";
1515
private const string SkipIntPhoneNumbersTestEnvironmentVariableName = "SKIP_INT_PHONENUMBERS_TEST";
1616

17-
public string LiveTestDynamicConnectionString => GetRecordedVariable(LiveTestDynamicConnectionStringEnvironmentVariableName);
17+
public string LiveTestDynamicConnectionString => GetRecordedVariable(
18+
LiveTestDynamicConnectionStringEnvironmentVariableName,
19+
options => options.HasSecretConnectionStringParameter("accessKey", SanitizedValue.Base64));
1820

1921
public Uri LiveTestDynamicEndpoint => new Uri(Core.ConnectionString.Parse(LiveTestDynamicConnectionString).GetRequired("endpoint"));
2022

2123
public string LiveTestDynamicAccessKey => Core.ConnectionString.Parse(LiveTestDynamicConnectionString).GetRequired("accesskey");
2224

23-
public string LiveTestStaticConnectionString => GetRecordedVariable(LiveTestStaticConnectionStringEnvironmentVariableName);
25+
public string LiveTestStaticConnectionString => GetRecordedVariable(
26+
LiveTestStaticConnectionStringEnvironmentVariableName,
27+
options => options.HasSecretConnectionStringParameter("accessKey", SanitizedValue.Base64));
2428

2529
public Uri LiveTestStaticEndpoint => new Uri(Core.ConnectionString.Parse(LiveTestStaticConnectionString).GetRequired("endpoint"));
2630

2731
public string LiveTestStaticAccessKey => Core.ConnectionString.Parse(LiveTestStaticConnectionString).GetRequired("accesskey");
2832

29-
public string CommunicationTestPhoneNumber => GetVariable(AzurePhoneNumber);
33+
public string CommunicationTestPhoneNumber => GetRecordedVariable(AzurePhoneNumber, options => options.IsSecret("+14255550123"));
3034

3135
public string SkipSmsTest => GetOptionalVariable(SkipIntSmsTestEnvironmentVariableName) ?? "False";
3236

0 commit comments

Comments
 (0)