Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Oct 29, 2020
1 parent 1de0f26 commit ab344e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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 @@ -121,6 +121,11 @@ public class RecordingRedactorTests {
private static final String REDACTED_AUTH_HEADER_RESPONSE_BODY = "\"dataSourceParameter\":"
+ "{\"authHeader\":\"REDACTED\",\"port\":\"9200\"";

private static final String EMPTY_KEY_RESPONSE_BODY = "\"dataSourceParameter\":"
+ "{\"username\":\"authHeaderXYZ\",\"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

0 comments on commit ab344e9

Please sign in to comment.