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

Improve error sender #513 #514

Merged
merged 1 commit into from
Jun 13, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> collect(ErrorReportCollectingContext context) {
Expand All @@ -17,14 +16,13 @@ public Map<String, String> collect(ErrorReportCollectingContext context) {
return r;
}

protected void fillValues(Map<String, String> map, Properties properties) {
void fillValues(Map<String, String> 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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,30 +25,31 @@ public void before(){
System.setProperty(KEY1,"value1");
System.setProperty(KEY2,"value2");
System.setProperty(KEY3,"some password");
System.setProperty(KEY4,"John Doe");
}

@AfterTest
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<String, String> collect = erdc.collect(null);

//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");
Expand Down