Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redactor to skip redaction for empty key-value pairs values #16943

Merged
merged 1 commit into from
Oct 29, 2020
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
3 changes: 3 additions & 0 deletions sdk/core/azure-core-test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -162,6 +167,7 @@ private static Stream<Arguments> 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)
);
}
Expand Down