1
0
mirror of synced 2026-08-24 02:57:08 +00:00

Check isAnyLocalAddress

This commit updates InternalInetAddressMatcher to check
InetAddress#isAnyLocalAddress in order to catch
additional IP addresses

Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
This commit is contained in:
Josh Cummings
2026-06-18 14:11:26 -06:00
parent 7cecfbb4db
commit 9fdcc6104d
2 changed files with 8 additions and 5 deletions
@@ -259,7 +259,9 @@ public final class InetAddressMatchers {
if (address.isLoopbackAddress() || address.isLinkLocalAddress() || address.isSiteLocalAddress()) {
return true;
}
if (address.isAnyLocalAddress()) {
return true;
}
byte[] rawAddress = address.getAddress();
if (rawAddress.length == 16) {
@@ -276,16 +276,17 @@ class InetAddressMatchersTests {
}
@ParameterizedTest
@ValueSource(strings = { "127.0.0.1", "127.0.0.255" })
@ValueSource(strings = { "127.0.0.1", "127.0.0.255", "0.0.0.0" })
void matchesWhenIpv4LoopbackThenReturnsTrue(String address) throws Exception {
InetAddressMatcher matcher = InetAddressMatchers.matchInternal().build();
assertThat(matcher.matches(InetAddress.getByName(address))).isTrue();
}
@Test
void matchesWhenIpv6LoopbackThenReturnsTrue() throws Exception {
@ParameterizedTest
@ValueSource(strings = { "::1", "::" })
void matchesWhenIpv6LoopbackThenReturnsTrue(String address) throws Exception {
InetAddressMatcher matcher = InetAddressMatchers.matchInternal().build();
assertThat(matcher.matches(InetAddress.getByName("::1"))).isTrue();
assertThat(matcher.matches(InetAddress.getByName(address))).isTrue();
}
@ParameterizedTest