You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/06/08 22:27:18 UTC
[1/2] brooklyn-server git commit: Sanitizer: avoid NPE if sanitize
null key
Repository: brooklyn-server
Updated Branches:
refs/heads/master 8dc292b94 -> 88df98d5a
Sanitizer: avoid NPE if sanitize null key
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7fc4c7e6
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7fc4c7e6
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7fc4c7e6
Branch: refs/heads/master
Commit: 7fc4c7e64b56d7d1d4af8a88f69044352bfa4de4
Parents: 4224963
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jun 8 22:07:56 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Jun 8 22:07:56 2016 +0100
----------------------------------------------------------------------
.../apache/brooklyn/core/config/Sanitizer.java | 4 ++-
.../brooklyn/core/entity/SanitizerTest.java | 33 ++++++++++++++++++--
2 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7fc4c7e6/core/src/main/java/org/apache/brooklyn/core/config/Sanitizer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/Sanitizer.java b/core/src/main/java/org/apache/brooklyn/core/config/Sanitizer.java
index 59ca6af..99cba90 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/Sanitizer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/Sanitizer.java
@@ -50,6 +50,7 @@ public final class Sanitizer {
private static class IsSecretPredicate implements Predicate<Object> {
@Override
public boolean apply(Object name) {
+ if (name == null) return false;
String lowerName = name.toString().toLowerCase();
for (String secretName : SECRET_NAMES) {
if (lowerName.contains(secretName))
@@ -69,6 +70,7 @@ public final class Sanitizer {
private static final Predicate<Object> IS_SECRET_PREDICATE_DEPRECATED = new Predicate<Object>() {
@Override
public boolean apply(Object name) {
+ if (name == null) return false;
String lowerName = name.toString().toLowerCase();
for (String secretName : SECRET_NAMES) {
if (lowerName.contains(secretName))
@@ -111,7 +113,7 @@ public final class Sanitizer {
private <K> Map<K, Object> apply(Map<K, ?> input, Set<Object> visited) {
Map<K, Object> result = Maps.newLinkedHashMap();
for (Map.Entry<K, ?> e : input.entrySet()) {
- if (predicate.apply(e.getKey())){
+ if (e.getKey() != null && predicate.apply(e.getKey())){
result.put(e.getKey(), "xxxxxxxx");
continue;
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7fc4c7e6/core/src/test/java/org/apache/brooklyn/core/entity/SanitizerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/SanitizerTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/SanitizerTest.java
index 79161d4..f63b40d 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/SanitizerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/SanitizerTest.java
@@ -23,16 +23,45 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.apache.brooklyn.core.config.Sanitizer;
+import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.testng.annotations.Test;
+import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
public class SanitizerTest {
@Test
public void testSanitize() throws Exception {
- Map<String, Object> sanitized = Sanitizer.sanitize(ConfigBag.newInstance(ImmutableMap.of("password", "pa55w0rd", "mykey", "myval")));
- assertEquals(sanitized, ImmutableMap.of("password", "xxxxxxxx", "mykey", "myval"));
+ Map<String, Object> map = ImmutableMap.<String, Object>builder()
+ .put("PREFIX_password_SUFFIX", "pa55w0rd")
+ .put("PREFIX_PASSWORD_SUFFIX", "pa55w0rd")
+ .put("PREFIX_passwd_SUFFIX", "pa55w0rd")
+ .put("PREFIX_credential_SUFFIX", "pa55w0rd")
+ .put("PREFIX_secret_SUFFIX", "pa55w0rd")
+ .put("PREFIX_private_SUFFIX", "pa55w0rd")
+ .put("PREFIX_access.cert_SUFFIX", "myval")
+ .put("PREFIX_access.key_SUFFIX", "myval")
+ .put("mykey", "myval")
+ .build();
+ Map<String, Object> expected = MutableMap.<String, Object>builder()
+ .putAll(Maps.transformValues(map, Functions.constant("xxxxxxxx")))
+ .put("mykey", "myval")
+ .build();
+
+ Map<String, Object> sanitized = Sanitizer.sanitize(ConfigBag.newInstance(map));
+ assertEquals(sanitized, expected);
+
+ Map<String, Object> sanitized2 = Sanitizer.sanitize(map);
+ assertEquals(sanitized2, expected);
+ }
+
+ @Test
+ public void testSanitizeWithNullKey() throws Exception {
+ MutableMap<?, ?> map = MutableMap.of(null, null);
+ Map<?, ?> sanitized = Sanitizer.sanitize(map);
+ assertEquals(sanitized, map);
}
}
[2/2] brooklyn-server git commit: This closes #190
Posted by al...@apache.org.
This closes #190
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/88df98d5
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/88df98d5
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/88df98d5
Branch: refs/heads/master
Commit: 88df98d5a5da413954dd552449789d82ae8400fa
Parents: 8dc292b 7fc4c7e
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jun 8 23:27:07 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Jun 8 23:27:07 2016 +0100
----------------------------------------------------------------------
.../apache/brooklyn/core/config/Sanitizer.java | 4 ++-
.../brooklyn/core/entity/SanitizerTest.java | 33 ++++++++++++++++++--
2 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------