Search in sources :

Example 11 with DefaultNHINDAgent

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);
}
Also used : DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent)

Example 12 with DefaultNHINDAgent

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);
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent)

Example 13 with DefaultNHINDAgent

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);
}
Also used : Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent)

Example 14 with DefaultNHINDAgent

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);
}
Also used : CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent) DefaultTrustAnchorResolver(org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)

Example 15 with DefaultNHINDAgent

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);
}
Also used : OutgoingMessage(org.nhindirect.stagent.OutgoingMessage) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent)

Aggregations

DefaultNHINDAgent (org.nhindirect.stagent.DefaultNHINDAgent)15 MimeMessage (javax.mail.internet.MimeMessage)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)5 OptionsParameter (org.nhindirect.stagent.options.OptionsParameter)5 DefaultTrustAnchorResolver (org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)5 Message (org.nhindirect.stagent.mail.Message)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)1 Header (javax.mail.Header)1 OutgoingMessage (org.nhindirect.stagent.OutgoingMessage)1