-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support ignoring "ipv4" and "ipv6" (#49)
- Loading branch information
Showing
10 changed files
with
124 additions
and
2 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
55 changes: 55 additions & 0 deletions
55
arex-compare-core/src/main/java/com/arextest/diff/handler/log/filterrules/IPFilter.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.arextest.diff.handler.log.filterrules; | ||
|
||
import com.arextest.diff.model.enumeration.UnmatchedType; | ||
import com.arextest.diff.model.log.LogEntity; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class IPFilter implements Predicate<LogEntity> { | ||
|
||
public static boolean isIp(String baseStr, String testStr) { | ||
|
||
if (baseStr.length() >= 7 && baseStr.length() <= 15 | ||
&& testStr.length() >= 7 && testStr.length() <= 15) { | ||
return isIPv4(baseStr) && isIPv4(testStr); | ||
} | ||
|
||
if (baseStr.length() >= 15 && baseStr.length() <= 39 | ||
&& testStr.length() >= 15 && testStr.length() <= 39) { | ||
return isIPv6(baseStr) && isIPv6(testStr); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static boolean isIPv4(String ipAddress) { | ||
String ipv4Regex = "^((25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$"; | ||
Pattern pattern = Pattern.compile(ipv4Regex); | ||
Matcher matcher = pattern.matcher(ipAddress); | ||
return matcher.matches(); | ||
} | ||
|
||
|
||
private static boolean isIPv6(String ipAddress) { | ||
String ipv6Regex = "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"; | ||
Pattern pattern = Pattern.compile(ipv6Regex); | ||
Matcher matcher = pattern.matcher(ipAddress); | ||
return matcher.matches(); | ||
} | ||
|
||
|
||
@Override | ||
public boolean test(LogEntity logEntity) { | ||
int unmatchedType = logEntity.getPathPair().getUnmatchedType(); | ||
if (unmatchedType == UnmatchedType.UNMATCHED) { | ||
Object baseValue = logEntity.getBaseValue(); | ||
Object testValue = logEntity.getTestValue(); | ||
if (baseValue != null && testValue != null) { | ||
return !isIp((String) baseValue, (String) testValue); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
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
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
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
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
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
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
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
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