### Question:
AmbariProxiedUserDetailsService implements UserDetailsService { boolean isInIpAddressRange(String cidr, String ipAddress) { Matcher matcher = IP_ADDRESS_RANGE_PATTERN.matcher(cidr); if (matcher.matches() && matcher.groupCount() == 2) { try { String hostSpecIPAddress = matcher.group(1); String hostSpecBits = matcher.group(2); int hostSpecIPAddressInt = ipAddressToInt(hostSpecIPAddress); int remoteAddressInt = ipAddressToInt(ipAddress); int mask = -1 << (32 - Integer.valueOf(hostSpecBits)); return ((hostSpecIPAddressInt & mask) == (remoteAddressInt & mask)); } catch (Throwable t) { LOG.warn("Invalid CIDR in host specification, skipping: " + cidr, t); } } return false; } AmbariProxiedUserDetailsService(Configuration configuration, Users users); @Override UserDetails loadUserByUsername(String proxiedUserName); UserDetails loadProxiedUser(String proxiedUserName,
                                     String proxyUserName,
                                     TrustedProxyAuthenticationDetails trustedProxyAuthenticationDetails);  }### Answer:
@Test public void testIsInIpAddressRange() { AmbariProxiedUserDetailsService service = new AmbariProxiedUserDetailsService(createNiceMock(Configuration.class), createNiceMock(Users.class)); Assert.assertTrue(service.isInIpAddressRange("192.168.74.10/32", "192.168.74.10")); Assert.assertFalse(service.isInIpAddressRange("192.168.74.10/32", "192.168.74.11")); for (int i = 0; i <= 255; i++) { Assert.assertTrue(service.isInIpAddressRange("192.168.1.0/24", String.format("192.168.1.%d", i))); } Assert.assertFalse(service.isInIpAddressRange("192.168.1.0/24", "192.168.2.100")); }