Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,11 @@ public void listConfigurationSettingsAcceptDateTime(HttpClient httpClient, Confi
final ConfigurationSetting updated2 = new ConfigurationSetting().setKey(original.getKey()).setValue("anotherValue2");

// Create 3 revisions of the same key.
try {
assertConfigurationEquals(original, client.setConfigurationSettingWithResponse(original, false, Context.NONE).getValue());
Thread.sleep(2000);
assertConfigurationEquals(updated, client.setConfigurationSettingWithResponse(updated, false, Context.NONE).getValue());
Thread.sleep(2000);
assertConfigurationEquals(updated2, client.setConfigurationSettingWithResponse(updated2, false, Context.NONE).getValue());
} catch (InterruptedException ex) {
// Do nothing.
}
assertConfigurationEquals(original, client.setConfigurationSettingWithResponse(original, false, Context.NONE).getValue());
sleepIfRunningAgainstService(2000);
assertConfigurationEquals(updated, client.setConfigurationSettingWithResponse(updated, false, Context.NONE).getValue());
sleepIfRunningAgainstService(2000);
assertConfigurationEquals(updated2, client.setConfigurationSettingWithResponse(updated2, false, Context.NONE).getValue());

// Gets all versions of this value so we can get the one we want at that particular date.
List<ConfigurationSetting> revisions = client.listRevisions(new SettingSelector().setKeyFilter(keyName)).stream().collect(Collectors.toList());
Expand Down Expand Up @@ -886,15 +882,11 @@ public void listRevisionsAcceptDateTime(HttpClient httpClient, ConfigurationServ
final ConfigurationSetting updated2 = new ConfigurationSetting().setKey(original.getKey()).setValue("anotherValue2");

// Create 3 revisions of the same key.
try {
assertConfigurationEquals(original, client.setConfigurationSettingWithResponse(original, false, Context.NONE).getValue());
Thread.sleep(2000);
assertConfigurationEquals(updated, client.setConfigurationSettingWithResponse(updated, false, Context.NONE).getValue());
Thread.sleep(2000);
assertConfigurationEquals(updated2, client.setConfigurationSettingWithResponse(updated2, false, Context.NONE).getValue());
} catch (InterruptedException ex) {
// Do nothing.
}
assertConfigurationEquals(original, client.setConfigurationSettingWithResponse(original, false, Context.NONE).getValue());
sleepIfRunningAgainstService(2000);
assertConfigurationEquals(updated, client.setConfigurationSettingWithResponse(updated, false, Context.NONE).getValue());
sleepIfRunningAgainstService(2000);
assertConfigurationEquals(updated2, client.setConfigurationSettingWithResponse(updated2, false, Context.NONE).getValue());

// Gets all versions of this value.
List<ConfigurationSetting> revisions = client.listRevisions(new SettingSelector().setKeyFilter(keyName)).stream().collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.core.test.utils.TestUtils;
import com.azure.core.util.BinaryData;
import com.azure.core.util.Context;
import com.azure.core.util.logging.LogLevel;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.security.attestation.models.AttestationData;
import com.azure.security.attestation.models.AttestationDataInterpretation;
Expand Down Expand Up @@ -354,7 +355,8 @@ void testTpmAttestation(HttpClient httpClient, String clientUri) {
.setAttestationSigner(new AttestationSigningKey(getIsolatedSigningCertificate(), getIsolatedSigningKey())));

if (result.getPolicyResolution() != PolicyModification.UPDATED) {
System.out.printf("Unexpected resolution setting TPM policy: %s", result.getPolicyResolution().toString());
LOGGER.log(LogLevel.VERBOSE,
() -> "Unexpected resolution setting TPM policy: " + result.getPolicyResolution());
return;
}

Expand All @@ -373,11 +375,11 @@ void testTpmAttestation(HttpClient httpClient, String clientUri) {

Object deserializedResponse = assertDoesNotThrow(() -> ADAPTER.deserialize(tpmResponse.getTpmResult().toBytes(),
Object.class, SerializerEncoding.JSON));
assertTrue(deserializedResponse instanceof LinkedHashMap);
assertInstanceOf(LinkedHashMap.class, deserializedResponse);
@SuppressWarnings("unchecked")
LinkedHashMap<String, Object> initialResponse = (LinkedHashMap<String, Object>) deserializedResponse;
assertTrue(initialResponse.containsKey("payload"));
assertTrue(initialResponse.get("payload") instanceof LinkedHashMap);
assertInstanceOf(LinkedHashMap.class, initialResponse.get("payload"));
@SuppressWarnings("unchecked")
LinkedHashMap<String, Object> payload = (LinkedHashMap<String, Object>) initialResponse.get("payload");
assertTrue(payload.containsKey("challenge"));
Expand All @@ -402,7 +404,8 @@ void testTpmAttestationWithResult(HttpClient httpClient, String clientUri) {
.setAttestationSigner(new AttestationSigningKey(getIsolatedSigningCertificate(), getIsolatedSigningKey())));

if (result.getPolicyResolution() != PolicyModification.UPDATED) {
System.out.printf("Unexpected resolution setting TPM policy: %s", result.getPolicyResolution().toString());
LOGGER.log(LogLevel.VERBOSE,
() -> "Unexpected resolution setting TPM policy: " + result.getPolicyResolution());
return;
}

Expand All @@ -423,11 +426,11 @@ void testTpmAttestationWithResult(HttpClient httpClient, String clientUri) {

Object deserializedResponse = assertDoesNotThrow(() -> ADAPTER.deserialize(
tpmResponse.getValue().getTpmResult().toBytes(), Object.class, SerializerEncoding.JSON));
assertTrue(deserializedResponse instanceof LinkedHashMap);
assertInstanceOf(LinkedHashMap.class, deserializedResponse);
@SuppressWarnings("unchecked")
LinkedHashMap<String, Object> initialResponse = (LinkedHashMap<String, Object>) deserializedResponse;
assertTrue(initialResponse.containsKey("payload"));
assertTrue(initialResponse.get("payload") instanceof LinkedHashMap);
assertInstanceOf(LinkedHashMap.class, initialResponse.get("payload"));
@SuppressWarnings("unchecked")
LinkedHashMap<String, Object> payload = (LinkedHashMap<String, Object>) initialResponse.get("payload");
assertTrue(payload.containsKey("challenge"));
Expand All @@ -450,7 +453,8 @@ void testTpmAttestationAsync(HttpClient httpClient, String clientUri) {
.setAttestationSigner(new AttestationSigningKey(getIsolatedSigningCertificate(), getIsolatedSigningKey())));

if (result.getPolicyResolution() != PolicyModification.UPDATED) {
System.out.printf("Unexpected resolution setting TPM policy: %s", result.getPolicyResolution().toString());
LOGGER.log(LogLevel.VERBOSE,
() -> "Unexpected resolution setting TPM policy: " + result.getPolicyResolution());
return;
}

Expand All @@ -469,11 +473,11 @@ void testTpmAttestationAsync(HttpClient httpClient, String clientUri) {
.assertNext(tpmResponse -> {
Object deserializedResponse = assertDoesNotThrow(() -> ADAPTER.deserialize(
tpmResponse.getTpmResult().toBytes(), Object.class, SerializerEncoding.JSON));
assertTrue(deserializedResponse instanceof LinkedHashMap);
assertInstanceOf(LinkedHashMap.class, deserializedResponse);
@SuppressWarnings("unchecked")
LinkedHashMap<String, Object> initialResponse = (LinkedHashMap<String, Object>) deserializedResponse;
assertTrue(initialResponse.containsKey("payload"));
assertTrue(initialResponse.get("payload") instanceof LinkedHashMap);
assertInstanceOf(LinkedHashMap.class, initialResponse.get("payload"));
@SuppressWarnings("unchecked")
LinkedHashMap<String, Object> payload = (LinkedHashMap<String, Object>) initialResponse.get("payload");
assertTrue(payload.containsKey("challenge"));
Expand Down Expand Up @@ -669,7 +673,7 @@ private static void verifyAttestationResult(TestMode testMode, String clientUri,
assertNull(result.getNonce());

if (expectJson) {
assertTrue(result.getRuntimeClaims() instanceof Map);
assertInstanceOf(Map.class, result.getRuntimeClaims());
@SuppressWarnings("unchecked")
Map<String, Object> runtimeClaims = (Map<String, Object>) result.getRuntimeClaims();
Map<String, Object> expectedClaims = assertDoesNotThrow(() ->
Expand All @@ -685,7 +689,7 @@ static void assertObjectEqual(Map<String, Object> expected, Map<String, Object>
LOGGER.verbose("Key: " + key);
assertTrue(actual.containsKey(key));
if (expected.get(key) instanceof Map) {
assertTrue(actual.get(key) instanceof Map);
assertInstanceOf(Map.class, actual.get(key));
@SuppressWarnings("unchecked")
Map<String, Object> expectedInner = (Map<String, Object>) expected.get(key);
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@
import com.azure.communication.callautomation.models.events.CallAutomationEventBase;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.amqp.AmqpTransportType;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.test.TestMode;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
import com.azure.messaging.servicebus.ServiceBusClientBuilder;
import com.azure.messaging.servicebus.ServiceBusErrorContext;
import com.azure.messaging.servicebus.ServiceBusException;
import com.azure.messaging.servicebus.ServiceBusFailureReason;
import com.azure.messaging.servicebus.ServiceBusProcessorClient;
import com.azure.core.http.HttpClient;
import com.azure.messaging.servicebus.ServiceBusReceivedMessage;
import com.azure.messaging.servicebus.ServiceBusReceivedMessageContext;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.azure.core.util.CoreUtils;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -39,11 +38,15 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CallAutomationAutomatedLiveTestBase extends CallAutomationLiveTestBase {
private static final ClientLogger LOGGER = new ClientLogger(CallAutomationAutomatedLiveTestBase.class);

protected ConcurrentHashMap<String, ServiceBusProcessorClient> processorStore;
// Key: callerId + receiverId, Value: incomingCallContext
protected ConcurrentHashMap<String, String> incomingCallContextStore;
Expand All @@ -60,7 +63,7 @@ public class CallAutomationAutomatedLiveTestBase extends CallAutomationLiveTestB
protected static final String BOT_APP_ID = Configuration.getGlobalConfiguration()
.get("BOT_APP_ID", "REDACTED-bedb-REDACTED-b8c6-REDACTED");

private static final StringJoiner JSON_PROPERTIES_TO_REDACT
private static final StringJoiner JSON_PROPERTIES_TO_REDACT
= new StringJoiner("\":\"|\"", "\"", "\":\"")
.add("value")
.add("rawId")
Expand All @@ -70,11 +73,11 @@ public class CallAutomationAutomatedLiveTestBase extends CallAutomationLiveTestB
.add("ivrContext")
.add("incomingCallContext")
.add("serverCallId");

protected static final Pattern JSON_PROPERTY_VALUE_REDACTION_PATTERN
= Pattern.compile(String.format("(?:%s)(.*?)(?:\",|\"})", JSON_PROPERTIES_TO_REDACT),
Pattern.CASE_INSENSITIVE);

protected static final String URL_REGEX = "(?<=http:\\/\\/|https:\\/\\/)([^\\/?]+)";

@Override
Expand Down Expand Up @@ -206,11 +209,12 @@ private void messageBodyHandler(String body) {
}

protected void errorHandler(ServiceBusErrorContext context, CountDownLatch countdownLatch) {
System.out.printf("Error when receiving messages from namespace: '%s'. Entity: '%s'%n",
context.getFullyQualifiedNamespace(), context.getEntityPath());
LOGGER.log(LogLevel.VERBOSE, () -> String.format(
"Error when receiving messages from namespace: '%s'. Entity: '%s'%n",
context.getFullyQualifiedNamespace(), context.getEntityPath()));

if (!(context.getException() instanceof ServiceBusException)) {
System.out.printf("Non-ServiceBusException occurred: %s%n", context.getException());
LOGGER.log(LogLevel.VERBOSE, () -> "Non-ServiceBusException occurred: " + context.getException());
return;
}

Expand All @@ -220,22 +224,20 @@ protected void errorHandler(ServiceBusErrorContext context, CountDownLatch count
if (reason == ServiceBusFailureReason.MESSAGING_ENTITY_DISABLED
|| reason == ServiceBusFailureReason.MESSAGING_ENTITY_NOT_FOUND
|| reason == ServiceBusFailureReason.UNAUTHORIZED) {
System.out.printf("An unrecoverable error occurred. Stopping processing with reason %s: %s%n",
reason, exception.getMessage());
LOGGER.log(LogLevel.VERBOSE, () -> String.format(
"An unrecoverable error occurred. Stopping processing with reason %s: %s%n",
reason, exception.getMessage()));

countdownLatch.countDown();
} else if (reason == ServiceBusFailureReason.MESSAGE_LOCK_LOST) {
System.out.printf("Message lock lost for message: %s%n", context.getException());
LOGGER.log(LogLevel.VERBOSE,
() -> String.format("Message lock lost for message: %s%n", context.getException()));
} else if (reason == ServiceBusFailureReason.SERVICE_BUSY) {
try {
// Choosing an arbitrary amount of time to wait until trying again.
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
System.err.println("Unable to sleep for period of time");
}
// Choosing an arbitrary amount of time to wait until trying again.
sleepIfRunningAgainstService(1000);
} else {
System.out.printf("Error source %s, reason %s, message: %s%n", context.getErrorSource(),
reason, context.getException());
LOGGER.log(LogLevel.VERBOSE, () -> String.format("Error source %s, reason %s, message: %s%n",
context.getErrorSource(), reason, context.getException()));
}
}

Expand All @@ -260,7 +262,7 @@ protected String waitForIncomingCallContext(String uniqueId, Duration timeOut) t
if (incomingCallContext != null) {
return incomingCallContext;
}
Thread.sleep(1000);
sleepIfRunningAgainstService(1000);
}
return null;
}
Expand All @@ -275,11 +277,11 @@ protected <T extends CallAutomationEventBase> T waitForEvent(Class<T> eventType,
return event;
}
}
Thread.sleep(1000);
sleepIfRunningAgainstService(1000);
}
return null;
}

protected String redact(String content, Matcher matcher) {
while (matcher.find()) {
String captureGroup = matcher.group(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public class CallAutomationLiveTestBase extends TestProxyTestBase {
protected static final String MEDIA_SOURCE = Configuration.getGlobalConfiguration()
.get("ACS_MEDIA_SOURCE", "https://contoso.com/music.wav");
protected static final String URL_REGEX = "(?<=http:\\/\\/|https:\\/\\/)([^\\/?]+)";

protected CommunicationIdentityClientBuilder getCommunicationIdentityClientUsingConnectionString(HttpClient httpClient) {
CommunicationIdentityClientBuilder builder = new CommunicationIdentityClientBuilder()
.connectionString(CONNECTION_STRING)
.httpClient(getHttpClientOrUsePlayback(httpClient));

if (getTestMode() == TestMode.RECORD) {
builder.addPolicy(interceptorManager.getRecordPolicy());
}
addTestProxyTestSanitizersAndMatchers(interceptorManager);

return builder;
}

Expand All @@ -88,12 +88,12 @@ protected CallAutomationClientBuilder getCallAutomationClientUsingConnectionStri
.connectionString(CONNECTION_STRING)
.httpClient(getHttpClientOrUsePlayback(httpClient));
}

if (getTestMode() == TestMode.RECORD) {
builder.addPolicy(interceptorManager.getRecordPolicy());
}
addTestProxyTestSanitizersAndMatchers(interceptorManager);

return builder;
}

Expand Down Expand Up @@ -137,12 +137,6 @@ protected Mono<HttpResponse> logHeaders(String testName, HttpPipelineNextPolicy
});
}

protected void waitForOperationCompletion(int milliSeconds) throws InterruptedException {
if (getTestMode() != TestMode.PLAYBACK) {
Thread.sleep(milliSeconds);
}
}

static class FakeCredentials implements TokenCredential {
@Override
public Mono<AccessToken> getToken(TokenRequestContext tokenRequestContext) {
Expand All @@ -159,15 +153,15 @@ protected String redact(String content, Matcher matcher) {
}
return content;
}

protected void addTestProxyTestSanitizersAndMatchers(InterceptorManager interceptorManager) {

if (interceptorManager.isLiveMode()) {
return;
}

List<TestProxySanitizer> customSanitizers = new ArrayList<>();

customSanitizers.add(new TestProxySanitizer("Authorization", null, "REDACTED", TestProxySanitizerType.HEADER));
customSanitizers.add(new TestProxySanitizer("x-ms-client-request-id", null, "REDACTED", TestProxySanitizerType.HEADER));
customSanitizers.add(new TestProxySanitizer("x-ms-content-sha256", null, "REDACTED", TestProxySanitizerType.HEADER));
Expand All @@ -187,7 +181,7 @@ protected void addTestProxyTestSanitizersAndMatchers(InterceptorManager intercep
customSanitizers.add(new TestProxySanitizer("$..mediaSubscriptionId", null, "REDACTED", TestProxySanitizerType.BODY_KEY));
customSanitizers.add(new TestProxySanitizer("$..dataSubscriptionId", null, "REDACTED", TestProxySanitizerType.BODY_KEY));
customSanitizers.add(new TestProxySanitizer(URL_REGEX, "REDACTED", TestProxySanitizerType.BODY_REGEX));

interceptorManager.addSanitizers(customSanitizers);

if (interceptorManager.isPlaybackMode()) {
Expand Down
Loading