Skip to content

Commit bfe2381

Browse files
[Communication] Cleanup the Recording Test Infrastructure for Identity, Chat and Phone Numbers (Azure#18715)
* [Communication] Cleanup the Recording Test Infrastructure for Identity, Chat and Phone Numbers * Sanitize Location headers * Onboard the Sms package tests * Update the recorded tests * Disable TollFree tests and record phone number tests * Update the recordings
1 parent 1814567 commit bfe2381

File tree

105 files changed

+5419
-5789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5419
-5789
lines changed

sdk/communication/Azure.Communication.Chat/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using Azure.Communication.Chat;
4747
This will allow you to create, get, or delete chat threads.
4848
```C# Snippet:Azure_Communication_Chat_Tests_Samples_CreateChatClient
4949
ChatClient chatClient = new ChatClient(
50-
new Uri(endpoint),
50+
endpoint,
5151
new CommunicationTokenCredential(userToken));
5252
```
5353

@@ -175,7 +175,7 @@ Use `CreateChatThread` to create a chat thread client object.
175175

176176
```C# Snippet:Azure_Communication_Chat_Tests_Samples_CreateChatClient
177177
ChatClient chatClient = new ChatClient(
178-
new Uri(endpoint),
178+
endpoint,
179179
new CommunicationTokenCredential(userToken));
180180
```
181181
```C# Snippet:Azure_Communication_Chat_Tests_Samples_CreateThread

sdk/communication/Azure.Communication.Chat/tests/Azure.Communication.Chat.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ItemGroup>
1212
<ProjectReference Include="$(AzureCoreTestFramework)" />
1313
<ProjectReference Include="..\..\Azure.Communication.Identity\src\Azure.Communication.Identity.csproj" />
14+
<ProjectReference Include="..\..\Azure.Communication.Common\tests\Azure.Communication.Common.Tests.csproj" />
1415
<ProjectReference Include="..\src\Azure.Communication.Chat.csproj" />
1516
</ItemGroup>
1617

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected ChatClient CreateInstrumentedChatClient(string token)
3636
}
3737

3838
CommunicationTokenCredential communicationTokenCredential = new CommunicationTokenCredential(token);
39-
return InstrumentClient(new ChatClient(new Uri(TestEnvironment.ChatApiUrl()), communicationTokenCredential,
39+
return InstrumentClient(new ChatClient(TestEnvironment.Endpoint, communicationTokenCredential,
4040
InstrumentClientOptions(new ChatClientOptions())));
4141
}
4242

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,24 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6+
using Azure.Communication.Pipeline;
67
using Azure.Core;
7-
using Azure.Core.TestFramework;
88

99
namespace Azure.Communication.Chat.Tests
1010
{
11-
public class ChatRecordedTestSanitizer : RecordedTestSanitizer
11+
public class ChatRecordedTestSanitizer : CommunicationRecordedTestSanitizer
1212
{
1313
public const string SanitizedUnsignedUserTokenValue = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
1414

1515
public ChatRecordedTestSanitizer() : base()
16-
{
17-
JsonPathSanitizers.Add("$..token");
18-
}
16+
=> JsonPathSanitizers.Add("$..token");
1917

20-
public override void SanitizeHeaders(IDictionary<string, string[]> headers)
18+
protected override void SanitizeAuthenticationHeader(IDictionary<string, string[]> headers)
2119
{
22-
if (headers.ContainsKey(HttpHeader.Names.Authorization))
23-
{
24-
if (headers.ContainsKey(HttpHeader.Names.UserAgent) && headers[HttpHeader.Names.UserAgent].Any(x => x.Contains("Communication.Chat")))
25-
{
26-
headers[HttpHeader.Names.Authorization] = new[] { SanitizedUnsignedUserTokenValue };
27-
return;
28-
}
29-
headers[HttpHeader.Names.Authorization] = new[] { SanitizeValue };
30-
}
31-
}
32-
public override string SanitizeVariable(string variableName, string environmentVariableValue)
33-
=> variableName switch
34-
{
35-
ChatTestEnvironment.ConnectionStringEnvironmentVariableName => SanitizeConnectionString(environmentVariableValue),
36-
_ => base.SanitizeVariable(variableName, environmentVariableValue)
37-
};
38-
39-
private static string SanitizeConnectionString(string connectionString)
40-
{
41-
const string accessKey = "accesskey";
42-
43-
var parsed = ConnectionString.Parse(connectionString, allowEmptyValues: true);
44-
parsed.Replace(accessKey, "Kg==;");
45-
46-
return parsed.ToString();
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);
4724
}
4825
}
4926
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using Azure.Core.TestFramework;
4+
using Azure.Communication.Tests;
55

66
namespace Azure.Communication.Chat.Tests
77
{
88
/// <summary>
99
/// A helper class used to retrieve information to be used for tests.
1010
/// </summary>
11-
public class ChatTestEnvironment: TestEnvironment
11+
public class ChatTestEnvironment : CommunicationTestEnvironment
1212
{
13-
/// <summary>The name of the environment variable from which the Azure Communicion Service resource's connection string will be extracted for the live tests.</summary>
14-
internal const string ConnectionStringEnvironmentVariableName = "COMMUNICATION_CONNECTION_STRING";
15-
16-
public string ConnectionString => GetRecordedVariable(ConnectionStringEnvironmentVariableName);
17-
18-
public string ChatApiUrl()
19-
{
20-
var url = ConnectionString.Replace("endpoint=", "");
21-
var len = url.IndexOf("/;accesskey=");
22-
return url.Substring(0, len);
23-
}
2413
}
2514
}

0 commit comments

Comments
 (0)