mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
Add toString() to IpAddressMatcher.java
Closes gh-16795 Signed-off-by: wtigerhyunsu <jack951@naver.com>
This commit is contained in:
parent
40b84d3e44
commit
bdbf6a2be3
@ -130,4 +130,11 @@ public final class IpAddressMatcher implements RequestMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String hostAddress = this.requiredAddress.getHostAddress();
|
||||
return (this.nMaskBits < 0) ? "IpAddress [" + hostAddress + "]"
|
||||
: "IpAddress [" + hostAddress + "/" + this.nMaskBits + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -153,4 +153,18 @@ public class IpAddressMatcherTests {
|
||||
.withMessage("ipAddress cannot be empty");
|
||||
}
|
||||
|
||||
// gh-16795
|
||||
@Test
|
||||
public void toStringWhenCidrIsProvidedThenReturnsIpAddressWithCidr() {
|
||||
IpAddressMatcher matcher = new IpAddressMatcher("192.168.1.0/24");
|
||||
assertThat(matcher.toString()).hasToString("IpAddress [192.168.1.0/24]");
|
||||
}
|
||||
|
||||
// gh-16795
|
||||
@Test
|
||||
public void toStringWhenOnlyIpIsProvidedThenReturnsIpAddressOnly() {
|
||||
IpAddressMatcher matcher = new IpAddressMatcher("127.0.0.1");
|
||||
assertThat(matcher.toString()).hasToString("IpAddress [127.0.0.1]");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user