use of org.nhindirect.policy.PolicyFilter in project nhin-d by DirectProject.
the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyNotCompliant_assertFalse.
public void testIsCertPolicyCompliant_policyNotCompliant_assertFalse() throws Exception {
final TrustModel model = new TrustModel();
final PolicyFilter filter = mock(PolicyFilter.class);
when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(false);
final PolicyResolver resolver = mock(PolicyResolver.class);
final PolicyExpression expression = mock(PolicyExpression.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
model.setTrustPolicyResolver(resolver);
model.setPolicyFilter(filter);
final X509Certificate cert = mock(X509Certificate.class);
assertFalse(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
use of org.nhindirect.policy.PolicyFilter in project nhin-d by DirectProject.
the class ConfigServiceDNSStore_isCertCompliantWithPolicyTest method testisCertCompliantWithPolicy_exceptionInFilter_assertCompliant.
public void testisCertCompliantWithPolicy_exceptionInFilter_assertCompliant() throws Exception {
final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
final PolicyFilter filt = mock(PolicyFilter.class);
doThrow(new RuntimeException("Just Passing Through")).when(filt).isCompliant((X509Certificate) any(), (PolicyExpression) any());
store.polFilter = filt;
X509Certificate cert = DNSRecordUtil.loadCertificate("umesh.der");
assertTrue(store.isCertCompliantWithPolicy(cert));
}
use of org.nhindirect.policy.PolicyFilter in project nhin-d by DirectProject.
the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyCompliant_assertTrue.
public void testIsCertPolicyCompliant_policyCompliant_assertTrue() throws Exception {
final TrustModel model = new TrustModel();
final PolicyFilter filter = mock(PolicyFilter.class);
when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(true);
final PolicyResolver resolver = mock(PolicyResolver.class);
final PolicyExpression expression = mock(PolicyExpression.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
model.setTrustPolicyResolver(resolver);
model.setPolicyFilter(filter);
final X509Certificate cert = mock(X509Certificate.class);
assertTrue(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
use of org.nhindirect.policy.PolicyFilter in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_incomingPolicyCompliant_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_incomingPolicyCompliant_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(true);
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(1, filteredCerts.size());
}
use of org.nhindirect.policy.PolicyFilter in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_requiredFieldMissing_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_requiredFieldMissing_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
doThrow(new PolicyRequiredException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(0, filteredCerts.size());
}
Aggregations