use of org.nhindirect.stagent.DefaultNHINDAgent 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 org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.
the class NHINDAgentTest method testIncomingDSN_incomingNotTrusted_outgoingTrusted_useIncomingSettingFalse_assertMDNMessageNotTrusted.
public void testIncomingDSN_incomingNotTrusted_outgoingTrusted_useIncomingSettingFalse_assertMDNMessageNotTrusted() throws Exception {
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "false"));
// first create the encyrpted message
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
String testMessage = TestUtils.readResource("DSNMessage.txt");
final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
;
assertNotNull(SMIMEenvMessage);
// now send received the MDN
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "Cerner.com" }));
DefaultTrustAnchorResolver resolver = (DefaultTrustAnchorResolver) agent.getTrustAnchors();
CertificateResolver mockResolver = mock(CertificateResolver.class);
DefaultTrustAnchorResolver newResolver = new DefaultTrustAnchorResolver(resolver.getOutgoingAnchors(), mockResolver);
agent.setTrustAnchorResolver(newResolver);
IncomingMessage incomingMessage = null;
try {
incomingMessage = agent.processIncoming(SMIMEenvMessage.getMessage());
} catch (NHINDException e) {
assertEquals(TrustError.NoTrustedRecipients, e.getError());
}
assertNull(incomingMessage);
}
use of org.nhindirect.stagent.DefaultNHINDAgent 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);
}
use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.
the class NHINDAgentTest method testEndToEndMessageBase64AttachmentOnly.
public void testEndToEndMessageBase64AttachmentOnly() throws Exception {
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "messaging.cernerdemos.com" }));
String testMessage = TestUtils.readResource("raw2.txt");
MimeMessage originalMsg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
assertNotNull(SMIMEenvMessage);
assertTrue(SMIMEenvMessage.getMessage().toString().length() > 0);
// 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);
// can't do a direct compare on headers because the processing may strip some of the recipients
assertTrue(processedMsg.getContentType().compareTo(originalMsg.getContentType()) == 0);
assertTrue(originalMsg.getSubject().compareTo(processedMsg.getSubject()) == 0);
// get the message data and compare
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
InputStream inStream = originalMsg.getInputStream();
while ((count = inStream.read(buffer)) > -1) oStream.write(buffer, 0, count);
oStream = new ByteArrayOutputStream();
count = 0;
inStream = processedMsg.getInputStream();
while ((count = inStream.read(buffer)) > -1) oStream.write(buffer, 0, count);
}
use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.
the class NHINDAgentTest method testIncomingMDN_incomingNotTrusted_outgoingTrusted_useIncomingSettingFalse_assertMDNMessageNotTrusted.
public void testIncomingMDN_incomingNotTrusted_outgoingTrusted_useIncomingSettingFalse_assertMDNMessageNotTrusted() throws Exception {
OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "false"));
// first create the encyrpted message
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
String testMessage = TestUtils.readResource("MDNMessage.txt");
final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
;
assertNotNull(SMIMEenvMessage);
// now send received the MDN
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "Cerner.com" }));
DefaultTrustAnchorResolver resolver = (DefaultTrustAnchorResolver) agent.getTrustAnchors();
CertificateResolver mockResolver = mock(CertificateResolver.class);
DefaultTrustAnchorResolver newResolver = new DefaultTrustAnchorResolver(resolver.getOutgoingAnchors(), mockResolver);
agent.setTrustAnchorResolver(newResolver);
IncomingMessage incomingMessage = null;
try {
incomingMessage = agent.processIncoming(SMIMEenvMessage.getMessage());
} catch (NHINDException e) {
assertEquals(TrustError.NoTrustedRecipients, e.getError());
}
assertNull(incomingMessage);
}
Aggregations