-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
18 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 16 additions & 7 deletions
23
framework/src/test/java/org/tron/common/logsfilter/DesensitizedConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
package org.tron.common.logsfilter; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class DesensitizedConverterTest { | ||
|
||
@Test | ||
public void testReplace() { | ||
public void testReplace() | ||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
DesensitizedConverter converter = new DesensitizedConverter(); | ||
DesensitizedConverter.addSensitive("/192.168.1.10", "address1"); | ||
DesensitizedConverter.addSensitive("/197.168.1.10", "address2"); | ||
DesensitizedConverter.addSensitive("192.168.1.10", "address1"); | ||
DesensitizedConverter.addSensitive("197.168.1.10", "address2"); | ||
|
||
Method method = converter.getClass().getDeclaredMethod( | ||
"desensitization", String.class); | ||
method.setAccessible(true); | ||
|
||
String logStr1 = "This is test log /192.168.1.10:100, /197.168.1.10:200, /197.168.1.10:100"; | ||
Assert.assertEquals("This is test log address1:100, address2:200, address2:100", | ||
converter.desensitization(logStr1)); | ||
String result1 = (String) method.invoke(converter, logStr1); | ||
Assert.assertEquals("This is test log /address1:100, /address2:200, /address2:100", | ||
result1); | ||
|
||
String logStr2 = "This is test log /192.168.1.100:100, /197.168.1.10:200, /197.168.1.10:100"; | ||
Assert.assertEquals("This is test log unknown:100, address2:200, address2:100", | ||
converter.desensitization(logStr2)); | ||
String result2 = (String) method.invoke(converter, logStr2); | ||
Assert.assertEquals("This is test log /IP:100, /address2:200, /address2:100", | ||
result2); | ||
} | ||
} |