From 51ea9da6fa7d5457ce83fa614f56c63699620368 Mon Sep 17 00:00:00 2001 From: krzysztof Date: Thu, 14 Jun 2018 01:02:02 +0200 Subject: [PATCH] Improve error sender #513 --- .../errrorreport/SystemPropertiesERDC.java | 10 ++++------ .../errrorreport/SystemPropertiesERDCTest.java | 15 ++++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/OtrosLogViewer-app/src/main/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDC.java b/OtrosLogViewer-app/src/main/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDC.java index 489192e1..c15b295b 100644 --- a/OtrosLogViewer-app/src/main/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDC.java +++ b/OtrosLogViewer-app/src/main/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDC.java @@ -6,8 +6,7 @@ public class SystemPropertiesERDC implements ErrorReportDataCollector { - public static final String PREFIX = "SYSTEM_PROPERTIES:"; - public static final String MASKED_PASSOWRD = "*****"; + static final String PREFIX = "SYSTEM_PROPERTIES:"; @Override public Map collect(ErrorReportCollectingContext context) { @@ -17,14 +16,13 @@ public Map collect(ErrorReportCollectingContext context) { return r; } - protected void fillValues(Map map, Properties properties) { + void fillValues(Map map, Properties properties) { for (Object keyObject : properties.keySet()) { String key = keyObject.toString(); String property = properties.getProperty(key); - if (key.contains("pass")) { - property = MASKED_PASSOWRD; + if (!key.toLowerCase().matches(".*(user\\.|password).*")) { + map.put(PREFIX + key, property); } - map.put(PREFIX + key, property); } } diff --git a/OtrosLogViewer-app/src/test/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDCTest.java b/OtrosLogViewer-app/src/test/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDCTest.java index 91ae218e..6a383db4 100644 --- a/OtrosLogViewer-app/src/test/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDCTest.java +++ b/OtrosLogViewer-app/src/test/java/pl/otros/logview/exceptionshandler/errrorreport/SystemPropertiesERDCTest.java @@ -9,14 +9,14 @@ import java.util.Properties; import static org.testng.Assert.assertEquals; -import static pl.otros.logview.exceptionshandler.errrorreport.SystemPropertiesERDC.MASKED_PASSOWRD; import static pl.otros.logview.exceptionshandler.errrorreport.SystemPropertiesERDC.PREFIX; public class SystemPropertiesERDCTest { - public static final String KEY1 = "testProp1"; - public static final String KEY2 = "testProp2"; - public static final String KEY3 = "testProp3-password"; + private static final String KEY1 = "testProp1"; + private static final String KEY2 = "testProp2"; + private static final String KEY3 = "testProp3-password"; + private static final String KEY4 = "user.name"; private SystemPropertiesERDC erdc; @BeforeTest @@ -25,6 +25,7 @@ public void before(){ System.setProperty(KEY1,"value1"); System.setProperty(KEY2,"value2"); System.setProperty(KEY3,"some password"); + System.setProperty(KEY4,"John Doe"); } @AfterTest @@ -32,11 +33,12 @@ public void after(){ System.clearProperty(KEY1); System.clearProperty(KEY2); System.clearProperty(KEY3); + System.clearProperty(KEY4); } @Test - public void testCollect() throws Exception { + public void testCollect() { //given //when Map collect = erdc.collect(null); @@ -44,11 +46,10 @@ public void testCollect() throws Exception { //then assertEquals(collect.get(PREFIX+KEY1), "value1"); assertEquals(collect.get(PREFIX+KEY2), "value2"); - assertEquals(collect.get(PREFIX+KEY3), MASKED_PASSOWRD); } @Test - public void testFillValues() throws Exception { + public void testFillValues() { //given Properties p = new Properties(); p.setProperty("a","b");