use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class DefaultNHINDAgent_ProcessOutgoingMessage_Test method testMessageIsWrapped_WrapMessageIsNotCalled.
/**
*
* @throws Exception
*/
public void testMessageIsWrapped_WrapMessageIsNotCalled() throws Exception {
new TestPlan() {
protected OutgoingMessage createMessage() throws Exception {
MimeMessage mimeMsg = new SecondaryMimeMessage();
mimeMsg.setText("");
Message msg = new Message(mimeMsg) {
@Override
public String getContentType() throws MessagingException {
return MailStandard.MediaType.WrappedMessage;
}
};
NHINDAddressCollection recipients = new NHINDAddressCollection();
recipients.add(new NHINDAddress(""));
NHINDAddress sender = new NHINDAddress("");
theCreateMessage = new OutgoingMessage(msg, recipients, sender) {
@Override
protected void categorizeRecipients(TrustEnforcementStatus minTrustStatus) {
categorizeRecipientsCalls++;
categorizeRecipients_Internal(minTrustStatus);
}
};
return theCreateMessage;
}
protected void doAssertions() throws Exception {
assertEquals(0, wrapMessageCalls);
}
}.perform();
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NHINDAgentTest method testDecryptAttachmentMessage.
public void testDecryptAttachmentMessage() throws Exception {
// get the keystore file
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
String testMessage = TestUtils.readResource("EncAttachment.txt");
MimeMessage originalMsg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
// verify the message
// need a new agent because this is a different domain);
IncomingMessage strippedAndVerifiesMessage = agent.processIncoming(originalMsg);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NHINDAgentTest method testRejectMessageOnRoutingTamper_policyTrue_assertMessageRejected.
public void testRejectMessageOnRoutingTamper_policyTrue_assertMessageRejected() throws Exception {
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.REJECT_ON_ROUTING_TAMPER, "true"));
/*
* EncryptedMessage2
*/
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
String testMessage = TestUtils.readResource("EncryptedMessage2.txt");
Message originalMsg = new Message(new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII"))));
// add an extra recipient that should not receive this message
final NHINDAddressCollection tamperedRecips = new NHINDAddressCollection();
tamperedRecips.add(new NHINDAddress("ryan@securehealthemail.com"));
tamperedRecips.add(new NHINDAddress("john@securehealthemail.com"));
final IncomingMessage inMessage = new IncomingMessage(originalMsg, tamperedRecips, new NHINDAddress(originalMsg.getFrom()[0].toString()));
boolean exceptionOccured = false;
try {
agent.processIncoming(inMessage);
} catch (AgentException e) {
assertEquals(AgentError.MessageTamperDectection, e.getError());
exceptionOccured = true;
}
assertTrue(exceptionOccured);
OptionsManager.destroyInstance();
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NHINDAgentTest method testDecryptProvidedMessage.
public void testDecryptProvidedMessage() throws Exception {
/*
* EncryptedMessage2
*/
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
String testMessage = TestUtils.readResource("EncryptedMessage2.txt");
MimeMessage originalMsg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
// verify the message
// need a new agent because this is a different domain);
IncomingMessage strippedAndVerifiesMessage = agent.processIncoming(originalMsg);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NHINDAgentTest method testMessageWithUntrustedRecipient_OutboundMessageHasRejectedRecips.
public void testMessageWithUntrustedRecipient_OutboundMessageHasRejectedRecips() throws Exception {
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "messaging.cernerdemos.com" }));
String testMessage = TestUtils.readResource("MessageWithAUntrustedRecipient.txt");
OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
assertNotNull(SMIMEenvMessage);
assertTrue(SMIMEenvMessage.getMessage().toString().length() > 0);
assertTrue(SMIMEenvMessage.hasRejectedRecipients());
assertNull(SMIMEenvMessage.getMessage().getCCHeader());
// verify the message
// need a new agent because this is a different domain
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
IncomingMessage strippedAndVerifiesMessage = agent.processIncoming(SMIMEenvMessage);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
MimeMessage processedMsg = new MimeMessage(null, new ByteArrayInputStream(strippedAndVerifiesMessage.getMessage().toString().getBytes("ASCII")));
assertNotNull(processedMsg);
}
Aggregations