Skip to content

Commit b6ecf17

Browse files
minnieliuMinnie Liu
andauthored
[Communication] - All SDKs- Print headers (Azure#18462)
* Custom logger for ms-cv headers * Custom logger for ms-cv headers * using System * Integrate custom policy with SMS tests * Fix build * New changes * Integrating logger with chat tests * Supress good logging * Remove unused import * Integrate with phone number * Fix build * Fix build * Update names * Update test names * Clean up PR * Fix checkstyle * Update log * Address comments * Add line back * Fix build * add test scope * Update headers change * Clean up PR Co-authored-by: Minnie Liu <peiliu@microsoft.com>
1 parent 5d0fb2d commit b6ecf17

23 files changed

+2107
-4152
lines changed

sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/CommunicationIdentityAsyncTests.java

Lines changed: 56 additions & 26 deletions
Large diffs are not rendered by default.

sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/CommunicationIdentityClientTestBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ private static TestMode initializeTestMode() {
9292
return TestMode.PLAYBACK;
9393
}
9494
}
95+
96+
protected CommunicationIdentityClientBuilder addLoggingPolicy(CommunicationIdentityClientBuilder builder, String testName) {
97+
return builder.addPolicy(new CommunicationLoggerPolicy(testName));
98+
}
9599

96100
static class FakeCredentials implements TokenCredential {
97101
@Override

sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/CommunicationIdentityTests.java

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ protected void beforeTest() {
3030
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
3131
public void createIdentityClientUsingManagedIdentity(HttpClient httpClient) {
3232
// Arrange
33-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
33+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
34+
client = setupClient(builder, "createIdentityClientUsingManagedIdentitySync");
3435
assertNotNull(client);
3536

3637
// Action & Assert
@@ -43,7 +44,8 @@ public void createIdentityClientUsingManagedIdentity(HttpClient httpClient) {
4344
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
4445
public void createIdentityClientUsingConnectionString(HttpClient httpClient) {
4546
// Arrange
46-
client = getCommunicationIdentityClientUsingConnectionString(httpClient).buildClient();
47+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientUsingConnectionString(httpClient);
48+
client = setupClient(builder, "createIdentityClientUsingConnectionStringSync");
4749
assertNotNull(client);
4850

4951
// Action & Assert
@@ -57,7 +59,8 @@ public void createIdentityClientUsingConnectionString(HttpClient httpClient) {
5759
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
5860
public void createUser(HttpClient httpClient) {
5961
// Arrange
60-
client = getCommunicationIdentityClient(httpClient).buildClient();
62+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
63+
client = setupClient(builder, "createUserSync");
6164

6265
// Action & Assert
6366
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -69,7 +72,8 @@ public void createUser(HttpClient httpClient) {
6972
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
7073
public void createUserWithResponse(HttpClient httpClient) {
7174
// Arrange
72-
client = getCommunicationIdentityClient(httpClient).buildClient();
75+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
76+
client = setupClient(builder, "createUserWithResponseSync");
7377

7478
// Action & Assert
7579
Response<CommunicationUserIdentifier> response = client.createUserWithResponse(Context.NONE);
@@ -82,7 +86,8 @@ public void createUserWithResponse(HttpClient httpClient) {
8286
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
8387
public void deleteUser(HttpClient httpClient) {
8488
// Arrange
85-
client = getCommunicationIdentityClient(httpClient).buildClient();
89+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
90+
client = setupClient(builder, "deleteUserSync");
8691

8792
// Action & Assert
8893
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -94,7 +99,8 @@ public void deleteUser(HttpClient httpClient) {
9499
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
95100
public void deleteUserWithResponse(HttpClient httpClient) {
96101
// Arrange
97-
client = getCommunicationIdentityClient(httpClient).buildClient();
102+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
103+
client = setupClient(builder, "deleteUserWithResponseSync");
98104

99105
// Action & Assert
100106
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -106,7 +112,8 @@ public void deleteUserWithResponse(HttpClient httpClient) {
106112
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
107113
public void revokeToken(HttpClient httpClient) {
108114
// Arrange
109-
client = getCommunicationIdentityClient(httpClient).buildClient();
115+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
116+
client = setupClient(builder, "revokeTokenSync");
110117

111118
// Action & Assert
112119
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -120,7 +127,8 @@ public void revokeToken(HttpClient httpClient) {
120127
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
121128
public void revokeTokenWithResponse(HttpClient httpClient) {
122129
// Arrange
123-
client = getCommunicationIdentityClient(httpClient).buildClient();
130+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
131+
client = setupClient(builder, "revokeTokenWithResponseSync");
124132

125133
// Action & Assert
126134
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -135,7 +143,8 @@ public void revokeTokenWithResponse(HttpClient httpClient) {
135143
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
136144
public void issueToken(HttpClient httpClient) {
137145
// Arrange
138-
client = getCommunicationIdentityClient(httpClient).buildClient();
146+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
147+
client = setupClient(builder, "issueTokenSync");
139148

140149
// Action & Assert
141150
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -153,7 +162,8 @@ public void issueToken(HttpClient httpClient) {
153162
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
154163
public void issueTokenWithResponse(HttpClient httpClient) {
155164
// Arrange
156-
client = getCommunicationIdentityClient(httpClient).buildClient();
165+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClient(httpClient);
166+
client = setupClient(builder, "issueTokenWithResponseSync");
157167

158168
// Action & Assert
159169
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -173,7 +183,8 @@ public void issueTokenWithResponse(HttpClient httpClient) {
173183
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
174184
public void createUserWithResponseUsingManagedIdentity(HttpClient httpClient) {
175185
// Arrange
176-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
186+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
187+
client = setupClient(builder, "createUserWithResponseUsingManagedIdentitySync");
177188

178189
// Action & Assert
179190
Response<CommunicationUserIdentifier> response = client.createUserWithResponse(Context.NONE);
@@ -186,7 +197,8 @@ public void createUserWithResponseUsingManagedIdentity(HttpClient httpClient) {
186197
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
187198
public void deleteUserUsingManagedIdentity(HttpClient httpClient) {
188199
// Arrange
189-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
200+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
201+
client = setupClient(builder, "deleteUserUsingManagedIdentitySync");
190202

191203
// Action & Assert
192204
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -198,7 +210,8 @@ public void deleteUserUsingManagedIdentity(HttpClient httpClient) {
198210
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
199211
public void deleteUserWithResponseUsingManagedIdentity(HttpClient httpClient) {
200212
// Arrange
201-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
213+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
214+
client = setupClient(builder, "deleteUserWithResponseUsingManagedIdentitySync");
202215

203216
// Action & Assert
204217
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -210,7 +223,8 @@ public void deleteUserWithResponseUsingManagedIdentity(HttpClient httpClient) {
210223
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
211224
public void revokeTokenUsingManagedIdentity(HttpClient httpClient) {
212225
// Arrange
213-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
226+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
227+
client = setupClient(builder, "revokeTokenUsingManagedIdentitySync");
214228

215229
// Action & Assert
216230
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -224,7 +238,8 @@ public void revokeTokenUsingManagedIdentity(HttpClient httpClient) {
224238
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
225239
public void revokeTokenWithResponseUsingManagedIdentity(HttpClient httpClient) {
226240
// Arrange
227-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
241+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
242+
client = setupClient(builder, "revokeTokenWithResponseUsingManagedIdentitySync");
228243

229244
// Action & Assert
230245
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -239,7 +254,8 @@ public void revokeTokenWithResponseUsingManagedIdentity(HttpClient httpClient) {
239254
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
240255
public void issueTokenUsingManagedIdentity(HttpClient httpClient) {
241256
// Arrange
242-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
257+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
258+
client = setupClient(builder, "issueTokenUsingManagedIdentitySync");
243259

244260
// Action & Assert
245261
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -257,7 +273,8 @@ public void issueTokenUsingManagedIdentity(HttpClient httpClient) {
257273
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
258274
public void issueTokenWithResponseUsingManagedIdentity(HttpClient httpClient) {
259275
// Arrange
260-
client = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient).buildClient();
276+
CommunicationIdentityClientBuilder builder = getCommunicationIdentityClientBuilderUsingManagedIdentity(httpClient);
277+
client = setupClient(builder, "issueTokenWithResponseUsingManagedIdentitySync");
261278

262279
// Action & Assert
263280
CommunicationUserIdentifier communicationUser = client.createUser();
@@ -272,4 +289,8 @@ public void issueTokenWithResponseUsingManagedIdentity(HttpClient httpClient) {
272289
assertFalse(issuedToken.getExpiresOn().toString().isEmpty());
273290
assertNotNull(issuedToken.getUser());
274291
}
292+
293+
private CommunicationIdentityClient setupClient(CommunicationIdentityClientBuilder builder, String testName) {
294+
return addLoggingPolicy(builder, testName).buildClient();
295+
}
275296
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.communication.administration;
5+
6+
import com.azure.core.http.HttpPipelineCallContext;
7+
import com.azure.core.http.HttpPipelineNextPolicy;
8+
import com.azure.core.http.HttpResponse;
9+
import com.azure.core.http.policy.HttpPipelinePolicy;
10+
import com.azure.core.util.logging.ClientLogger;
11+
12+
import reactor.core.publisher.Mono;
13+
14+
/**
15+
* A policy that logs the Http Response
16+
*/
17+
public class CommunicationLoggerPolicy implements HttpPipelinePolicy {
18+
19+
private final ClientLogger logger = new ClientLogger(CommunicationLoggerPolicy.class);
20+
private final String testName;
21+
22+
/**
23+
* Creates a policy that logs the Http Response
24+
* @param testName Name of the test to log
25+
*/
26+
public CommunicationLoggerPolicy(String testName) {
27+
this.testName = testName;
28+
}
29+
30+
@Override
31+
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
32+
return next.process()
33+
.flatMap(httpResponse -> {
34+
final HttpResponse bufferedResponse = httpResponse.buffer();
35+
36+
// Should sanitize printed reponse url
37+
System.out.println("MS-CV header for " + testName + " request "
38+
+ bufferedResponse.getRequest().getUrl() + ": " + bufferedResponse.getHeaderValue("MS-CV"));
39+
return Mono.just(bufferedResponse);
40+
});
41+
}
42+
}

0 commit comments

Comments
 (0)