Search in sources :

Example 1 with NHINDSecurityAndTrustMailet

use of org.nhindirect.gateway.smtp.james.mailet.NHINDSecurityAndTrustMailet in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_functionalTest method testProcessOutgoingMessageEndToEnd_tamperedRoutingHeaders_rejectPolicyOn_assertRejected.

public void testProcessOutgoingMessageEndToEnd_tamperedRoutingHeaders_rejectPolicyOn_assertRejected() throws Exception {
    new TestPlan() {

        protected String getMessageToProcess() throws Exception {
            return TestUtils.readMessageResource("PlainOutgoingMessage.txt");
        }

        @Override
        protected Mailet getMailet(String configurationFileName) throws Exception {
            Mailet retVal = null;
            String configfile = TestUtils.getTestConfigFile(configurationFileName);
            Map<String, String> params = new HashMap<String, String>();
            if (configurationFileName.startsWith("http"))
                params.put("ConfigURL", ConfigServiceRunner.getConfigServiceURL());
            else
                params.put("ConfigURL", "file://" + configfile);
            params.put(SecurityAndTrustMailetOptions.REJECT_ON_ROUTING_TAMPER, "true");
            retVal = new NHINDSecurityAndTrustMailet();
            MailetConfig mailetConfig = new MockMailetConfig(params, "NHINDSecurityAndTrustMailet");
            retVal.init(mailetConfig);
            return retVal;
        }

        protected void performInner() throws Exception {
            // encrypt
            String originalMessage = getMessageToProcess();
            MimeMessage msg = EntitySerializer.Default.deserialize(originalMessage);
            // add an MDN request
            msg.setHeader(MDNStandard.Headers.DispositionNotificationTo, msg.getHeader(MailStandard.Headers.From, ","));
            MockMail theMessage = new MockMail(msg);
            Mailet theMailet = getMailet("ValidConfig.xml");
            theMailet.service(theMessage);
            assertNotNull(theMessage);
            assertNotNull(theMessage.getMessage());
            msg = theMessage.getMessage();
            assertTrue(SMIMEStandard.isEncrypted(msg));
            assertEquals(theMessage.getState(), Mail.TRANSPORT);
            // decrypt
            theMailet = getMailet("ValidConfigStateLine.txt");
            theMessage = new MockMail(msg);
            final MailAddress validAddress = new MailAddress(msg.getRecipients(RecipientType.TO)[0].toString());
            final MailAddress injectedAttackAddress = new MailAddress("externUser2@starugh-stateline.com");
            theMessage.setRecipients(Arrays.asList(validAddress, injectedAttackAddress));
            theMailet.service(theMessage);
            // rejected and ghosted
            assertEquals(Mail.GHOST, theMessage.getState());
        }
    }.perform();
}
Also used : MailAddress(org.apache.mailet.MailAddress) BaseTestPlan(org.nhindirect.gateway.testutils.BaseTestPlan) NHINDSecurityAndTrustMailet(org.nhindirect.gateway.smtp.james.mailet.NHINDSecurityAndTrustMailet) MailetConfig(org.apache.mailet.MailetConfig) NHINDSecurityAndTrustMailet(org.nhindirect.gateway.smtp.james.mailet.NHINDSecurityAndTrustMailet) Mailet(org.apache.mailet.Mailet) MimeMessage(javax.mail.internet.MimeMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 MimeMessage (javax.mail.internet.MimeMessage)1 MailAddress (org.apache.mailet.MailAddress)1 Mailet (org.apache.mailet.Mailet)1 MailetConfig (org.apache.mailet.MailetConfig)1 NHINDSecurityAndTrustMailet (org.nhindirect.gateway.smtp.james.mailet.NHINDSecurityAndTrustMailet)1 BaseTestPlan (org.nhindirect.gateway.testutils.BaseTestPlan)1