InstanceZTSProvider implements InstanceProvider { boolean validateSanIp(final String[] sanIps, final String clientIp) { LOGGER.debug("Validating sanIps: {}, clientIp: {}", sanIps, clientIp); if (sanIps == null || sanIps.length == 0) { return true; } if (clientIp == null || clientIp.isEmpty()) { return false; } for (String sanIp: sanIps) { if (sanIp.equals(clientIp)) { return true; } } LOGGER.error("Unable to match sanIp: {} with clientIp:{}", sanIps, clientIp); return false; }  @Override Scheme getProviderScheme(); @Override void initialize(String provider, String providerEndpoint, SSLContext sslContext,
            KeyStore keyStore); @Override void setHostnameResolver(HostnameResolver hostnameResolver); @Override InstanceConfirmation confirmInstance(InstanceConfirmation confirmation); @Override InstanceConfirmation refreshInstance(InstanceConfirmation confirmation); boolean validatePublicKeys(final String athenzPublicKey, final String csrPublicKey);  }
@Test public void testValidateSanIp() { InstanceZTSProvider provider = new InstanceZTSProvider(); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceZTSProvider", null, null); assertTrue(provider.validateSanIp(new String[]{"10.1.1.1"}, "10.1.1.1")); assertTrue(provider.validateSanIp(null, "10.1.1.1")); assertTrue(provider.validateSanIp(new String[]{}, "10.1.1.1")); assertFalse(provider.validateSanIp(new String[]{""}, "10.1.1.1")); assertFalse(provider.validateSanIp(new String[]{"10.1.1.2"}, "10.1.1.1")); assertFalse(provider.validateSanIp(new String[]{"10.1.1.2"}, null)); assertFalse(provider.validateSanIp(new String[]{"10.1.1.2"}, "")); assertTrue(provider.validateSanIp(new String[]{"2001:db8:a0b:12f0:0:0:0:1"}, "2001:db8:a0b:12f0:0:0:0:1")); assertTrue(provider.validateSanIp(null, "2001:db8:a0b:12f0:0:0:0:1")); assertTrue(provider.validateSanIp(new String[]{}, "2001:db8:a0b:12f0:0:0:0:1")); assertFalse(provider.validateSanIp(new String[]{"2002:db9:a0b:12f0:0:0:0:1"}, "2001:db8:a0b:12f0:0:0:0:1")); assertFalse(provider.validateSanIp(new String[]{"2002:db9:a0b:12f0:0:0:0:1"}, "10.1.1.1")); assertFalse(provider.validateSanIp(new String[]{"2002:db9:a0b:12f0:0:0:0:1"}, null)); assertFalse(provider.validateSanIp(new String[]{"2002:db9:a0b:12f0:0:0:0:1"}, "")); assertTrue(provider.validateSanIp(new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}, "10.1.1.1")); assertTrue(provider.validateSanIp(new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}, "2001:db8:a0b:12f0:0:0:0:1")); assertFalse(provider.validateSanIp(new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}, "10.1.1.2")); assertFalse(provider.validateSanIp(new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}, null)); assertFalse(provider.validateSanIp(new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}, "")); provider.close(); }