Search in sources :

Example 6 with DefaultNHINDAgent

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

Example 7 with DefaultNHINDAgent

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

Example 8 with DefaultNHINDAgent

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

Example 9 with DefaultNHINDAgent

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);
}
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 10 with DefaultNHINDAgent

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

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