diuis commented on issue #3: Accepted hosts starts with match
URL: https://github.com/apache/geronimo-metrics/pull/3#issuecomment-591921769
 
 
   Hi @rmannibucau,
   I don't know how to disable the security validator, but I like that the 
/metrics api is protected end not exposed to everyone.
   What do you think if the acceptedhosts parameter value is something like an 
ip range?
   For example, we could accept a string as [10.10.10.0..10.10.10.255] and 
write a range validator like this one:
   
   `  @ParameterizedTest
     @CsvSource({ "[10.10.10.0..10.10.10.255],10.10.10.9,true", 
"[10.10.10.0..10.10.10.255],10.10.11.0,false" })
     void testIpRange(String ipRange, String ip, boolean expected) throws 
UnknownHostException {
       Optional<String[]> optionalRange = Optional.ofNullable(ipRange)
                                                  .filter(range -> 
range.startsWith("["))
                                                  .filter(range -> 
range.endsWith("]"))
                                                  .map(range -> 
range.subSequence(1, range.length() - 1)
                                                                     
.toString())
                                                  .map(range -> 
range.split("\\.\\."))
                                                  .filter(values -> 
values.length == 2);
   
       var addressMin = new 
BigInteger(InetAddress.getByName(optionalRange.get()[0])
                                                  .getAddress()).longValue();
       var addressMax = new 
BigInteger(InetAddress.getByName(optionalRange.get()[1])
                                                  .getAddress()).longValue();
   
       var addressBetween = new BigInteger(InetAddress.getByName(ip)
                                                      
.getAddress()).longValue();
   
       var actual = Math.max(addressMin, addressBetween) == 
Math.min(addressBetween, addressMax);
   
       assertThat(actual).isEqualTo(expected);
     }`
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to