showuon commented on a change in pull request #10714:
URL: https://github.com/apache/kafka/pull/10714#discussion_r634877755



##########
File path: 
clients/src/test/java/org/apache/kafka/common/utils/ConfigUtilsTest.java
##########
@@ -140,4 +144,28 @@ public void testMultipleDeprecations() {
         assertNull(newConfig.get("foo.bar.deprecated"));
         assertNull(newConfig.get("foo.bar.even.more.deprecated"));
     }
+
+    private static final ConfigDef CONFIG = new ConfigDef().
+        define("foo", Type.PASSWORD, Importance.HIGH, "").
+        define("bar", Type.STRING, Importance.HIGH, "").
+        define("quux", Type.INT, Importance.HIGH, "").
+        define("blah", Type.STRING, Importance.HIGH, "");
+
+    @Test
+    public void testConfigMapToRedactedStringForEmptyMap() {
+        assertEquals("{}", ConfigUtils.
+            configMapToRedactedString(Collections.emptyMap(), CONFIG));
+    }
+
+    @Test
+    public void testConfigMapToRedactedStringWithSecrets() {
+        Map<String, Object> testMap1 = new HashMap<>();
+        testMap1.put("bar", "whatever");
+        testMap1.put("quux", Integer.valueOf(123));
+        testMap1.put("foo", "foosecret");
+        testMap1.put("blah", null);
+        testMap1.put("quuux", Integer.valueOf(456));
+        assertEquals("{bar=\"whatever\", blah=null, foo=(redacted), 
quuux=(redacted), quux=123}",

Review comment:
       `nit`: could we rename the config name into a "meaningful" name? So that 
we can read the name and know which type it is, and what expected result it is. 
ex:
   ```
   define("passwordConfig", Type.PASSWORD, Importance.HIGH, "").
   define("stringConfig", Type.STRING, Importance.HIGH, "")
   ...
   testMap1.put("stringConfig", "whatever");
   testMap1.put("passwordConfig", "foosecret");
   testMap1.put("undefinedConfig", Integer.valueOf(456));
   ```
   So, in assert we can have this result:
   ```
   assertEquals("{stringConfig=\"whatever\", ..., passwordConfig=(redacted), 
undefinedConfig=(redacted), ...}",
   ``` 
   
   What do you think?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to