diff --git a/sdk/core/azure-core-test/CHANGELOG.md b/sdk/core/azure-core-test/CHANGELOG.md index 759860839376d..a1e252626e2b6 100644 --- a/sdk/core/azure-core-test/CHANGELOG.md +++ b/sdk/core/azure-core-test/CHANGELOG.md @@ -6,6 +6,9 @@ - Updated `azure-core` to `1.10.0`. +### Bug Fixes +- Fixed a bug in test recording redaction for redacting empty values for json key-value pairs. + ## 1.5.0 (2020-10-01) ### New Features diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/RecordingRedactor.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/RecordingRedactor.java index b6e8b69cbcac9..faeaba677e07e 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/RecordingRedactor.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/RecordingRedactor.java @@ -3,6 +3,8 @@ package com.azure.core.test.models; +import com.azure.core.util.CoreUtils; + import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; @@ -40,11 +42,11 @@ public class RecordingRedactor { .add("url") .add("host") .add("password") - .add("password") .add("userName"); private static final Pattern JSON_PROPERTY_VALUE_REDACTION_PATTERN - = Pattern.compile(String.format("(?:%s)(.*?)(?:\",|\"})", JSON_PROPERTIES_TO_REDACT.toString())); + = Pattern.compile(String.format("(?:%s)(.*?)(?:\",|\"})", JSON_PROPERTIES_TO_REDACT.toString()), + Pattern.CASE_INSENSITIVE); /** * Redact the sensitive information. @@ -96,7 +98,10 @@ private static String redactUserDelegationKey(String content) { private static String redactionReplacement(String content, Matcher matcher, String replacement) { while (matcher.find()) { - content = content.replace(matcher.group(1), replacement); + String captureGroup = matcher.group(1); + if (!CoreUtils.isNullOrEmpty(captureGroup)) { + content = content.replace(matcher.group(1), replacement); + } } return content; diff --git a/sdk/core/azure-core-test/src/test/java/com/azure/core/test/RecordingRedactorTests.java b/sdk/core/azure-core-test/src/test/java/com/azure/core/test/RecordingRedactorTests.java index 8e5264ddf4bea..6d3cc41186941 100644 --- a/sdk/core/azure-core-test/src/test/java/com/azure/core/test/RecordingRedactorTests.java +++ b/sdk/core/azure-core-test/src/test/java/com/azure/core/test/RecordingRedactorTests.java @@ -116,11 +116,16 @@ public class RecordingRedactorTests { + "\":\"adsample\",\"accountKey\":\"REDACTED\"}"; private static final String AUTH_HEADER_RESPONSE_BODY = "\"dataSourceParameter\":" - + "{\"authHeader\":\"authHeaderXYZ\",\"port\":\"9200\""; + + "{\"authHeader\":\"XYZ\",\"port\":\"9200\""; private static final String REDACTED_AUTH_HEADER_RESPONSE_BODY = "\"dataSourceParameter\":" + "{\"authHeader\":\"REDACTED\",\"port\":\"9200\""; + private static final String EMPTY_KEY_RESPONSE_BODY = "\"dataSourceParameter\":" + + "{\"username\":\"\",\"port\":\"9200\""; + + private static final String REDACTED_EMPTY_KEY_RESPONSE_BODY = "\"dataSourceParameter\":" + + "{\"username\":\"\",\"port\":\"9200\""; /** * Verify if the given content is redacted successfully. */ @@ -162,6 +167,7 @@ private static Stream sensitiveDataSupplier() { Arguments.of(USER_DELEGATION_KEY_FOR_VALUE_RESPONSE, EXPECTED_USER_DELEGATION_KEY_FOR_VALUE_RESPONSE_REDACTED), Arguments.of(PASSWORD_RESPONSE_BODY, REDACTED_PASSWORD_RESPONSE_BODY), Arguments.of(USERNAME_RESPONSE_BODY, REDACTED_USERNAME_RESPONSE), + Arguments.of(REDACTED_EMPTY_KEY_RESPONSE_BODY, EMPTY_KEY_RESPONSE_BODY), Arguments.of(NON_SENSITIVE_DATA_CONTENT, NON_SENSITIVE_DATA_CONTENT) ); }