use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.
the class NHINDAgentTest method testMessageWithAllUntrustedRecipients_AgentRejectsTheMessageCompletely.
public void testMessageWithAllUntrustedRecipients_AgentRejectsTheMessageCompletely() throws Exception {
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "messaging.cernerdemos.com" }));
String testMessage = TestUtils.readResource("MessageWithAllUntrustedRecipients.txt");
OutgoingMessage SMIMEenvMessage = null;
try {
SMIMEenvMessage = agent.processOutgoing(testMessage);
} catch (NHINDException e) {
AgentError agentError = (AgentError) e.m_error;
assertEquals(AgentError.Unexpected, agentError);
}
assertNull(SMIMEenvMessage);
}
use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.
the class NHINDAgentTest method testEndToEndMessageWithCertKeyStore.
public void testEndToEndMessageWithCertKeyStore() throws Exception {
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "cerner.com" }));
String testMessage = TestUtils.readResource("MultipartMimeMessage.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[] { "starugh-stateline.com" }));
IncomingMessage strippedAndVerifiesMessage = agent.processIncoming(SMIMEenvMessage.getMessage().toString());
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);
// now do a large message with some attachments
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
testMessage = TestUtils.readResource("LargeMsgWithAttachments.txt");
originalMsg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
SMIMEenvMessage = agent.processOutgoing(testMessage);
assertNotNull(SMIMEenvMessage);
assertTrue(SMIMEenvMessage.getMessage().toString().length() > 0);
// verify the message
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
strippedAndVerifiesMessage = agent.processIncoming(SMIMEenvMessage);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
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
oStream = new ByteArrayOutputStream();
buffer = new byte[1024];
count = 0;
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);
// do an MDN response message
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "cerner.com" }));
testMessage = TestUtils.readResource("MDNResponse.txt");
originalMsg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
SMIMEenvMessage = agent.processOutgoing(testMessage);
assertNotNull(SMIMEenvMessage);
assertTrue(SMIMEenvMessage.getMessage().toString().length() > 0);
// verify the message
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
strippedAndVerifiesMessage = agent.processIncoming(SMIMEenvMessage);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
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);
// get the message data and compare
oStream = new ByteArrayOutputStream();
buffer = new byte[1024];
count = 0;
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 testRejectMessageOnRoutingTamper_policyFalse_assertDecrtyped.
public void testRejectMessageOnRoutingTamper_policyFalse_assertDecrtyped() throws Exception {
/*
* 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()));
IncomingMessage strippedAndVerifiesMessage = agent.processIncoming(inMessage);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
}
use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.
the class NHINDAgentTest method testIncomingNormalMessage_incomingNotTrusted_outgoingTrusted_assertMessageNotTrusted.
public void testIncomingNormalMessage_incomingNotTrusted_outgoingTrusted_assertMessageNotTrusted() throws Exception {
// first create the encyrpted message
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "cerner.com" }));
String testMessage = TestUtils.readResource("MultipartMimeMessage.txt");
final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
;
assertNotNull(SMIMEenvMessage);
// now send received the MDN
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.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 WrappedMessageTest method testCopyNHINDStandard_encyrptMessage_assertPromotedInvalidCCHeaders.
public void testCopyNHINDStandard_encyrptMessage_assertPromotedInvalidCCHeaders() throws Exception {
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "cerner.com" }));
String testMessage = TestUtils.readResource("CCTestMessage.txt");
OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
String ccHeader = SMIMEenvMessage.getMessage().getHeader(MailStandard.Headers.CC, ",");
assertNotNull(ccHeader);
assertEquals("User1@Cerner.com", ccHeader);
}
Aggregations