use of org.nhindirect.stagent.policy.PolicyResolver in project nhin-d by DirectProject.
the class DefaultNHINDAgent_bindAddressesOutgoingMessageTest method testBindAddresses_singlePublicCerts_policyFiltered_assertNoBoundPublicCerts.
public void testBindAddresses_singlePublicCerts_policyFiltered_assertNoBoundPublicCerts() throws Exception {
final X509Certificate cert = mock(X509Certificate.class);
final CertificateResolver publicCertResolver = mock(CertificateResolver.class);
when(publicCertResolver.getCertificates((InternetAddress) any())).thenReturn(Arrays.asList(cert));
final CertificateResolver privateCertResolver = mock(CertificateResolver.class);
when(privateCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
final DefaultNHINDAgent agent = new DefaultNHINDAgent("Cerner.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class)) {
@Override
protected Collection<X509Certificate> filterCertificatesByPolicy(InternetAddress sender, PolicyResolver resolver, Collection<X509Certificate> certsToFilter, boolean incoming) {
return Collections.emptyList();
}
};
final OutgoingMessage message = buildOutgoingMessage("MultipartMimeMessage.txt");
message.setAgent(agent);
agent.bindAddresses(message);
for (NHINDAddress recipient : message.getRecipients()) assertEquals(0, recipient.getCertificates().size());
}
use of org.nhindirect.stagent.policy.PolicyResolver in project nhin-d by DirectProject.
the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_noPolicyExpression_assertTrue.
public void testIsCertPolicyCompliant_noPolicyExpression_assertTrue() throws Exception {
final TrustModel model = new TrustModel();
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(new ArrayList<PolicyExpression>());
model.setTrustPolicyResolver(resolver);
final X509Certificate cert = mock(X509Certificate.class);
assertTrue(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
use of org.nhindirect.stagent.policy.PolicyResolver 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.stagent.policy.PolicyResolver 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.stagent.policy.PolicyResolver in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered() throws Exception {
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(new ArrayList<PolicyExpression>());
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(1, filteredCerts.size());
}
Aggregations