Search in sources :

Example 1 with DefaultNHINDAgent

use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.

the class NHINDAgentTest method testOutgoingMessageIsWrappedCorrectly.

@SuppressWarnings("unchecked")
public void testOutgoingMessageIsWrappedCorrectly() throws Exception {
    DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "messaging.cernerdemos.com" }));
    String testMessage = TestUtils.readResource("raw2.txt");
    Message wrappedMessage = agent.wrapMessage(testMessage);
    assertNotNull(wrappedMessage);
    assertTrue(wrappedMessage.toString().length() > 0);
    assertEquals(MailStandard.MediaType.WrappedMessage, wrappedMessage.getContentType());
    List<String> headers = new ArrayList<String>();
    Enumeration<Header> allHeaders = wrappedMessage.getAllHeaders();
    while (allHeaders.hasMoreElements()) {
        Header header = (Header) allHeaders.nextElement();
        headers.add(header.getName());
    }
    // assert that the headers (according to the NHIND spec) are copied correctly from the 
    // original message into the wrapped message
    assertTrue(headers.contains(MimeStandard.VersionHeader));
    assertTrue(headers.contains("From"));
    assertTrue(headers.contains("To"));
    assertTrue(headers.contains("Message-ID"));
    // The wrapped message should not contain Subject header
    assertFalse(headers.contains("Subject"));
}
Also used : Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) Header(javax.mail.Header) ArrayList(java.util.ArrayList) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent)

Example 2 with DefaultNHINDAgent

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

Example 3 with DefaultNHINDAgent

use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.

the class NHINDAgentTest method testIncomingMDN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted.

public void testIncomingMDN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted() throws Exception {
    OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "true"));
    // 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 = agent.processIncoming(SMIMEenvMessage.getMessage());
    assertNotNull(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 4 with DefaultNHINDAgent

use of org.nhindirect.stagent.DefaultNHINDAgent 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();
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter) 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 5 with DefaultNHINDAgent

use of org.nhindirect.stagent.DefaultNHINDAgent in project nhin-d by DirectProject.

the class NHINDAgentTest method testIncomingDSN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted.

public void testIncomingDSN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted() throws Exception {
    OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "true"));
    // 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 = agent.processIncoming(SMIMEenvMessage.getMessage());
    assertNotNull(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