use of org.nhindirect.stagent.mail.Message in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_service_Test method testService_RejectRecipients_AssertRejectedList.
@SuppressWarnings("unused")
public void testService_RejectRecipients_AssertRejectedList() throws Exception {
final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
final SmtpAgent mockAgent = mock(SmtpAgent.class);
when(mockAgent.processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any())).thenAnswer(new Answer<MessageProcessResult>() {
public MessageProcessResult answer(InvocationOnMock invocation) throws Throwable {
usedRecipients = (NHINDAddressCollection) invocation.getArguments()[1];
usedRecipients.get(0).setStatus(TrustEnforcementStatus.Failed);
usedRecipients.get(1).setStatus(TrustEnforcementStatus.Success);
usedSender = (NHINDAddress) invocation.getArguments()[2];
MyMessageEnvelope env = new MyMessageEnvelope(new Message(mimeMsg), usedRecipients, usedSender);
env.setAgent(new MockNHINDAgent(Arrays.asList("cerner.com")));
env.categorizeRecipients(TrustEnforcementStatus.Success);
NHINDAddressCollection rejectedRecips = env.getRejectedRecipients();
return new MessageProcessResult(env, null);
}
});
final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
mockMail.setRecipients(Arrays.asList(new MailAddress("you@cerner.com"), new MailAddress("they@cerner.com")));
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
mockMail.setMessage(mimeMsg);
NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
mailet.agent = mockAgent;
mailet.service(mockMail);
assertEquals(1, mockMail.getRecipients().size());
}
use of org.nhindirect.stagent.mail.Message in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_service_Test method testService_UseToHeader_AssertRecipientsUsed.
public void testService_UseToHeader_AssertRecipientsUsed() throws Exception {
final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
final SmtpAgent mockAgent = mock(SmtpAgent.class);
when(mockAgent.processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any())).thenAnswer(new Answer<MessageProcessResult>() {
public MessageProcessResult answer(InvocationOnMock invocation) throws Throwable {
usedRecipients = (NHINDAddressCollection) invocation.getArguments()[1];
return new MessageProcessResult(new DefaultMessageEnvelope(new Message(mimeMsg)), null);
}
});
final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
when(mockMail.getRecipients()).thenReturn(null);
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
mockMail.setMessage(mimeMsg);
NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
mailet.agent = mockAgent;
mailet.service(mockMail);
assertNotNull(usedRecipients);
assertEquals(1, usedRecipients.size());
assertEquals("externUser1@starugh-stateline.com", usedRecipients.iterator().next().toString());
}
use of org.nhindirect.stagent.mail.Message in project nhin-d by DirectProject.
the class DefaultNHINDAgent_bindAddressesIncomingMessageTest method buildIncomingMessage.
protected IncomingMessage buildIncomingMessage(String fileName) throws Exception {
final String testMessage = TestUtils.readResource(fileName);
final Message incoming = new Message(new ByteArrayInputStream(testMessage.getBytes("ASCII")));
return new IncomingMessage(incoming);
}
use of org.nhindirect.stagent.mail.Message in project nhin-d by DirectProject.
the class DefaultNHINDAgent_bindAddressesOutgoingMessageTest method buildOutgoingMessage.
protected OutgoingMessage buildOutgoingMessage(String fileName) throws Exception {
final String testMessage = TestUtils.readResource(fileName);
final Message incoming = new Message(new ByteArrayInputStream(testMessage.getBytes("ASCII")));
return new OutgoingMessage(incoming);
}
use of org.nhindirect.stagent.mail.Message in project nhin-d by DirectProject.
the class DefaultNHINDAgent method signAndEncryptMessage.
//
// First sign, THEN encrypt the message
//
@SuppressWarnings("unchecked")
protected void signAndEncryptMessage(OutgoingMessage message) {
SignedEntity signedEntity = cryptographer.sign(message.getMessage(), message.getSender().getCertificates());
try {
if (encryptionEnabled) {
MimeEntity encryptedEntity = cryptographer.encrypt(signedEntity.getMimeMultipart(), message.getRecipients().getCertificates());
//
// Alter message content to contain encrypted data
//
InternetHeaders headers = new InternetHeaders();
Enumeration<Header> eHeaders = message.getMessage().getAllHeaders();
while (eHeaders.hasMoreElements()) {
Header hdr = eHeaders.nextElement();
headers.setHeader(hdr.getName(), hdr.getValue());
}
eHeaders = encryptedEntity.getAllHeaders();
while (eHeaders.hasMoreElements()) {
Header hdr = (Header) eHeaders.nextElement();
headers.setHeader(hdr.getName(), hdr.getValue());
}
Message msg = new Message(headers, encryptedEntity.getContentAsBytes());
message.setMessage(msg);
} else {
InternetHeaders headers = new InternetHeaders();
Enumeration<Header> eHeaders = message.getMessage().getAllHeaders();
while (eHeaders.hasMoreElements()) {
Header hdr = eHeaders.nextElement();
headers.setHeader(hdr.getName(), hdr.getValue());
}
headers.setHeader(MimeStandard.ContentTypeHeader, signedEntity.getMimeMultipart().getContentType());
Message msg = new Message(headers, signedEntity.getEntityBodyAsBytes());
message.setMessage(msg);
}
} catch (Exception e) {
throw new MimeException(MimeError.InvalidMimeEntity, e);
}
}
Aggregations