RateLimitingProcessor implements Processor { protected List<SubnetUtils.SubnetInfo> getIpSet(String ipSetId, int retryCount) { List<SubnetUtils.SubnetInfo> ips = new LinkedList<>(); GetIPSetResult result = null; try { result = awsWaf.getIPSet(new GetIPSetRequest().withIPSetId(ipSetId)); } catch (AWSWAFException e) { if (retryCount < 10) { sleep(1, TimeUnit.SECONDS); return getIpSet(ipSetId, retryCount + 1); } throw e; } result.getIPSet().getIPSetDescriptors().forEach(ipSetDescriptor -> { if (IPSetDescriptorType.IPV4.toString().equals(ipSetDescriptor.getType())) { SubnetUtils subnetUtils = new SubnetUtils(ipSetDescriptor.getValue()); subnetUtils.setInclusiveHostCount(true); ips.add(subnetUtils.getInfo()); } }); return ips; } RateLimitingProcessor(ObjectMapper objectMapper, AWSWAFRegional awsWaf, AmazonS3 amazonS3); void setCidrLimitForIpSetOverride(int limitOverride); @Override void processLogEvents(List<ALBAccessLogEvent> events, LogProcessorLambdaConfig config, String bucketName);  }
@Test public void testThatGetIpSetReturnsAListOfSubNetInfoObjects() { GetIPSetResult result = mock(GetIPSetResult.class); IPSet ipSet = mock(IPSet.class); when(result.getIPSet()).thenReturn(ipSet); List<IPSetDescriptor> descriptors = new LinkedList<>(); descriptors.add(new IPSetDescriptor().withType(IPSetDescriptorType.IPV4).withValue("192.168.0.1/32")); descriptors.add(new IPSetDescriptor().withType(IPSetDescriptorType.IPV4).withValue("192.168.0.2/32")); descriptors.add(new IPSetDescriptor().withType(IPSetDescriptorType.IPV4).withValue("192.168.0.3/32")); when(ipSet.getIPSetDescriptors()).thenReturn(descriptors); when(awswaf.getIPSet(isA(GetIPSetRequest.class))).thenReturn(result); List<SubnetUtils.SubnetInfo> list = processor.getIpSet("DOES NOT MATTER", 0); assertTrue("The list should contain 3 items", list.size() == 3); }