File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed 
main/java/org/springframework/security/web/util/matcher 
test/java/org/springframework/security/web/util/matcher Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -130,4 +130,25 @@ private InetAddress parseAddress(String address) {
130130		}
131131	}
132132
133+ 	/** 
134+ 	 * Returns the IP address this Matcher is matching for without mask bits. 
135+ 	 * @return a string representation of the IP address 
136+ 	 */ 
137+ 	public  String  getHostAddress () {
138+ 		return  this .requiredAddress .getHostAddress ();
139+ 	}
140+ 
141+ 	/** 
142+ 	 * Returns the mask bits of the IP address this Matcher is matching for 
143+ 	 * @return a string representation of the mask bits 
144+ 	 */ 
145+ 	public  String  getMaskBits () {
146+ 		return  String .valueOf (this .nMaskBits );
147+ 	}
148+ 
149+ 	@ Override 
150+ 	public  String  toString () {
151+ 		return  "IpAddressMatcher["  + getHostAddress () + "/"  + getMaskBits () + "]" ;
152+ 	}
153+ 
133154}
Original file line number Diff line number Diff line change 2121
2222import  org .springframework .mock .web .MockHttpServletRequest ;
2323
24- import  static  org .assertj .core .api .Assertions .assertThat ;
25- import  static  org .assertj .core .api .Assertions .assertThatException ;
26- import  static  org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
24+ import  static  org .assertj .core .api .Assertions .*;
2725
2826/** 
2927 * @author Luke Taylor 
@@ -153,4 +151,32 @@ public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentExcept
153151			.withMessage ("ipAddress cannot be empty" );
154152	}
155153
154+ 	// gh-16693 
155+ 	@ Test 
156+ 	public  void  getHostAddressReturnsCorrectIPv4String () {
157+ 		IpAddressMatcher  matcher  = new  IpAddressMatcher ("192.168.1.0/24" );
158+ 		assertThat (matcher .getHostAddress ()).isEqualTo ("192.168.1.0" );
159+ 	}
160+ 
161+ 	// gh-16693 
162+ 	@ Test 
163+ 	public  void  getMaskBitsIp4ReturnsCorrectString () {
164+ 		IpAddressMatcher  matcher  = new  IpAddressMatcher ("192.168.1.0/24" );
165+ 		assertThat (matcher .getMaskBits ()).isEqualTo ("24" );
166+ 	}
167+ 
168+ 	// gh-16693 
169+ 	@ Test 
170+ 	public  void  getHostAddressReturnsCorrectIPv6String () {
171+ 		IpAddressMatcher  matcher  = new  IpAddressMatcher ("fe80::21f:5bff:fe33:bd68" );
172+ 		assertThat (matcher .getHostAddress ()).isEqualTo ("fe80:0:0:0:21f:5bff:fe33:bd68" );
173+ 	}
174+ 
175+ 	// gh-16693 
176+ 	@ Test 
177+ 	public  void  getMaskBitsIp6ReturnsCorrectString () {
178+ 		IpAddressMatcher  matcher  = new  IpAddressMatcher ("2001:DB8::/48" );
179+ 		assertThat (matcher .getMaskBits ()).isEqualTo ("48" );
180+ 	}
181+ 
156182}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments