use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_bindAddressesIncomingMessageTest method testBindAddresses_singlePrivateCerts_plicyFiltered_assertNoBoundPrivateCerts.
public void testBindAddresses_singlePrivateCerts_plicyFiltered_assertNoBoundPrivateCerts() throws Exception {
final X509Certificate cert = mock(X509Certificate.class);
final CertificateResolver publicCertResolver = mock(CertificateResolver.class);
when(publicCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
final CertificateResolver privateCertResolver = mock(CertificateResolver.class);
when(privateCertResolver.getCertificates((InternetAddress) any())).thenReturn(Arrays.asList(cert));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("starugh-stateline.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class)) {
@Override
protected Collection<X509Certificate> filterCertificatesByPolicy(InternetAddress sender, PolicyResolver resolver, Collection<X509Certificate> certsToFilter, boolean incoming) {
return Collections.emptyList();
}
};
final IncomingMessage message = buildIncomingMessage("MultipartMimeMessage.txt");
message.setAgent(agent);
agent.bindAddresses(message);
for (NHINDAddress recipient : message.getRecipients()) assertEquals(0, recipient.getCertificates().size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
doThrow(new PolicyProcessException("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);
boolean exceptionOccured = false;
try {
agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
} catch (AgentException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_nullResolver_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_nullResolver_assertNoCertsFiltered() throws Exception {
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), null, certs, true);
assertEquals(1, filteredCerts.size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class LdapCertificateStoreTest method testPublicLdapSearch_requestUserLevelCert_fallbackToOrgLevelCert_assertCertExists.
public void testPublicLdapSearch_requestUserLevelCert_fallbackToOrgLevelCert_assertCertExists() throws Exception {
addStockPublicLDAPCertificats();
PublicLdapCertificateStoreProvider provider = new PublicLdapCertificateStoreProvider(null, null);
CertificateResolver resolver = provider.get();
Collection<X509Certificate> certs = resolver.getCertificates(new InternetAddress("bogus_user@testdomain.com"));
assertEquals(1, certs.size());
X509Certificate cert = certs.iterator().next();
assertTrue(cert.getSubjectX500Principal().toString().contains("direct.fnhubapp01.qa.medplus.com"));
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class CertificateStore_getUsableCertsTest method testGetUsableCerts_inValidUserCert_noCertsRetrieved.
public void testGetUsableCerts_inValidUserCert_noCertsRetrieved() throws Exception {
final X509CertificateEx userCert = TestUtils.getInternalCert("user1");
final X509CertificateEx domainCert = TestUtils.getInternalCert("gm2552");
CertificateStore store = new CertificateStoreAdapter() {
protected Collection<X509Certificate> filterUsable(Collection<X509Certificate> certs) {
if (certs.iterator().next().getSubjectDN().getName().contains("user1"))
return null;
else
return certs;
}
public Collection<X509Certificate> getCertificates(String subjectName) {
if (subjectName.contains("user1@domain.com"))
return Arrays.asList((X509Certificate) userCert);
else
return Arrays.asList((X509Certificate) domainCert);
}
};
boolean exceptionOccured = false;
try {
store.getCertificates(new InternetAddress("user1@domain.com"));
} catch (NHINDException e) {
assertEquals(e.getError(), AgentError.AllCertsInResolverInvalid);
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations