Search in sources :

Example 1 with TrustChainValidatorWrapper

use of org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper in project nhin-d by DirectProject.

the class TrustChainValidator_resolveIssuersTest method testResolveIssuers_AIAExists_validateResolved.

public void testResolveIssuers_AIAExists_validateResolved() throws Exception {
    final TrustChainValidatorWrapper validator = new TrustChainValidatorWrapper() {

        @Override
        protected Collection<X509Certificate> downloadCertsFromAIA(String url) throws NHINDException {
            try {
                retrievedURL = url;
                return Arrays.asList(TestUtils.loadCertificate("CernerDirect Cert Professional Community CA.der"));
            } catch (Exception e) {
                throw new NHINDException(e);
            }
        }
    };
    final Collection<X509Certificate> resolvedIssuers = new ArrayList<X509Certificate>();
    final Collection<X509Certificate> anchors = new ArrayList<X509Certificate>();
    final TrustChainValidatorWrapper spyValidator = spy(validator);
    spyValidator.resolveIssuers(TestUtils.loadCertificate("demo.sandboxcernerdirect.com.der"), resolvedIssuers, 0, anchors);
    assertEquals(1, resolvedIssuers.size());
    assertEquals(TestUtils.loadCertificate("CernerDirect Cert Professional Community CA.der"), resolvedIssuers.iterator().next());
    verify(spyValidator, times(2)).downloadCertsFromAIA((String) any());
}
Also used : TrustChainValidatorWrapper(org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper) ArrayList(java.util.ArrayList) NHINDException(org.nhindirect.stagent.NHINDException) X509Certificate(java.security.cert.X509Certificate) NHINDException(org.nhindirect.stagent.NHINDException)

Example 2 with TrustChainValidatorWrapper

use of org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper in project nhin-d by DirectProject.

the class TrustChainValidator_resolveIssuersTest method testResolveIssuers_AIAExists_resolveToRoot_validateResolved.

public void testResolveIssuers_AIAExists_resolveToRoot_validateResolved() throws Exception {
    final TrustChainValidatorWrapper validator = new TrustChainValidatorWrapper() {

        protected Collection<X509Certificate> downloadCertsFromAIA(String url) throws NHINDException {
            try {
                if (url.contains("sandbox"))
                    return Arrays.asList(TestUtils.loadCertificate("CernerDirect Cert Professional Community CA.der"));
                else
                    return Arrays.asList(TestUtils.loadCertificate("CernerRoot.der"));
            } catch (Exception e) {
                throw new NHINDException(e);
            }
        }
    };
    final Collection<X509Certificate> resolvedIssuers = new ArrayList<X509Certificate>();
    final Collection<X509Certificate> anchors = new ArrayList<X509Certificate>();
    final TrustChainValidatorWrapper spyValidator = spy(validator);
    spyValidator.resolveIssuers(TestUtils.loadCertificate("demo.sandboxcernerdirect.com.der"), resolvedIssuers, 0, anchors);
    assertEquals(2, resolvedIssuers.size());
    Iterator<X509Certificate> iter = resolvedIssuers.iterator();
    assertEquals(TestUtils.loadCertificate("CernerDirect Cert Professional Community CA.der"), iter.next());
    assertEquals(TestUtils.loadCertificate("CernerRoot.der"), iter.next());
    verify(spyValidator, times(2)).downloadCertsFromAIA((String) any());
}
Also used : TrustChainValidatorWrapper(org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper) ArrayList(java.util.ArrayList) NHINDException(org.nhindirect.stagent.NHINDException) X509Certificate(java.security.cert.X509Certificate) NHINDException(org.nhindirect.stagent.NHINDException)

Example 3 with TrustChainValidatorWrapper

use of org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper in project nhin-d by DirectProject.

the class TrustChainValidator_resolveIssuersTest method testResolveIssuers_noAIAExists_notAvailViaResolver_validateNotResolved.

public void testResolveIssuers_noAIAExists_notAvailViaResolver_validateNotResolved() throws Exception {
    final TrustChainValidatorWrapper validator = new TrustChainValidatorWrapper() {

        protected Collection<X509Certificate> downloadCertsFromAIA(String url) throws NHINDException {
            throw new NHINDException();
        }
    };
    validator.setCertificateResolver(new ArrayList<CertificateResolver>());
    final Collection<X509Certificate> resolvedIssuers = new ArrayList<X509Certificate>();
    final Collection<X509Certificate> anchors = new ArrayList<X509Certificate>();
    final TrustChainValidatorWrapper spyValidator = spy(validator);
    spyValidator.resolveIssuers(TestUtils.loadCertificate("altNameOnly.der"), resolvedIssuers, 0, anchors);
    assertEquals(0, resolvedIssuers.size());
    verify(spyValidator, times(0)).downloadCertsFromAIA((String) any());
}
Also used : TrustChainValidatorWrapper(org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper) ArrayList(java.util.ArrayList) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) NHINDException(org.nhindirect.stagent.NHINDException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509Certificate (java.security.cert.X509Certificate)3 ArrayList (java.util.ArrayList)3 NHINDException (org.nhindirect.stagent.NHINDException)3 TrustChainValidatorWrapper (org.nhindirect.stagent.trust.TrustChainValidator_getIntermediateCertsByAIATest.TrustChainValidatorWrapper)3 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)1