ExtensibleTrustManagerImpl extends X509ExtendedTrustManager implements ExtensibleTrustManager { @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { checkServerTrusted(chain, authType, (Socket) null); }  @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers(); @Override void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket); @Override void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine sslEngine); @Override void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket); @Override void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine sslEngine); @Override @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void addTlsCertificateProvider(TlsCertificateProvider tlsCertificateProvider); @Override void removeTlsCertificateProvider(TlsCertificateProvider tlsCertificateProvider); @Override @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void addTlsTrustManagerProvider(TlsTrustManagerProvider tlsTrustManagerProvider); @Override void removeTlsTrustManagerProvider(TlsTrustManagerProvider tlsTrustManagerProvider);  }
@Test public void shouldForwardCallsToMockForMatchingCN() throws CertificateException { when(topOfChain.getSubjectX500Principal()) .thenReturn(new X500Principal("CN=example.org, OU=Smarthome, O=Eclipse, C=DE")); subject.checkServerTrusted(chain, "just"); verify(trustmanager).checkServerTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager, trustmanager2); }
@Test public void shouldForwardCallsToMockForMatchingHost() throws CertificateException { when(sslEngine.getPeerHost()).thenReturn("example.org"); when(sslEngine.getPeerPort()).thenReturn(443); subject.checkServerTrusted(chain, "just", sslEngine); verify(trustmanager2).checkServerTrusted(chain, "just", sslEngine); verifyNoMoreInteractions(trustmanager, trustmanager2); }
@Test public void shouldNotForwardCallsToMockForDifferentCN() throws CertificateException, IllegalAccessException, NoSuchFieldException, SecurityException, IllegalArgumentException { writeField(subject, "defaultTrustManager", defaultTrustManager, true); mockSubjectForCertificate(topOfChain, "CN=example.com, OU=Smarthome, O=Eclipse, C=DE"); mockIssuerForCertificate(topOfChain, "CN=Eclipse, OU=Smarthome, O=Eclipse, C=DE"); mockSubjectForCertificate(bottomOfChain, "CN=Eclipse, OU=Smarthome, O=Eclipse, C=DE"); mockIssuerForCertificate(bottomOfChain, ""); when(topOfChain.getEncoded()).thenReturn(new byte[0]); subject.checkServerTrusted(chain, "just"); verify(defaultTrustManager).checkServerTrusted(chain, "just", (Socket) null); verifyNoInteractions(trustmanager); }