Search in sources :

Example 61 with MimeMessage

use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.

the class DefaultNHINDAgent_ProcessOutgoingMessage_Test method testMessageIsWrapped_WrapMessageIsNotCalled.

/**
	 * 
	 * @throws Exception
	 */
public void testMessageIsWrapped_WrapMessageIsNotCalled() throws Exception {
    new TestPlan() {

        protected OutgoingMessage createMessage() throws Exception {
            MimeMessage mimeMsg = new SecondaryMimeMessage();
            mimeMsg.setText("");
            Message msg = new Message(mimeMsg) {

                @Override
                public String getContentType() throws MessagingException {
                    return MailStandard.MediaType.WrappedMessage;
                }
            };
            NHINDAddressCollection recipients = new NHINDAddressCollection();
            recipients.add(new NHINDAddress(""));
            NHINDAddress sender = new NHINDAddress("");
            theCreateMessage = new OutgoingMessage(msg, recipients, sender) {

                @Override
                protected void categorizeRecipients(TrustEnforcementStatus minTrustStatus) {
                    categorizeRecipientsCalls++;
                    categorizeRecipients_Internal(minTrustStatus);
                }
            };
            return theCreateMessage;
        }

        protected void doAssertions() throws Exception {
            assertEquals(0, wrapMessageCalls);
        }
    }.perform();
}
Also used : TrustEnforcementStatus(org.nhindirect.stagent.trust.TrustEnforcementStatus) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) BaseTestPlan(org.nhindirect.stagent.utils.BaseTestPlan) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) MessagingException(javax.mail.MessagingException)

Example 62 with MimeMessage

use of javax.mail.internet.MimeMessage 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 63 with MimeMessage

use of javax.mail.internet.MimeMessage 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 64 with MimeMessage

use of javax.mail.internet.MimeMessage 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 65 with MimeMessage

use of javax.mail.internet.MimeMessage 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)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)1146 Test (org.junit.Test)374 InternetAddress (javax.mail.internet.InternetAddress)334 MessagingException (javax.mail.MessagingException)299 Session (javax.mail.Session)222 Properties (java.util.Properties)219 MimeMultipart (javax.mail.internet.MimeMultipart)208 MimeBodyPart (javax.mail.internet.MimeBodyPart)178 Date (java.util.Date)153 IOException (java.io.IOException)137 Message (javax.mail.Message)120 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)107 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)97 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)83 InputStream (java.io.InputStream)82 ArrayList (java.util.ArrayList)81 Multipart (javax.mail.Multipart)75 DataHandler (javax.activation.DataHandler)73 ByteArrayOutputStream (java.io.ByteArrayOutputStream)72 BodyPart (javax.mail.BodyPart)70