Search in sources :

Example 1 with MailetConfig

use of org.apache.mailet.MailetConfig in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_initialization_Test method testValidMailetConfiguration_AssertProperWSInitialization.

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

        private ConfigurationServiceProxy proxy;

        @Override
        protected MailetConfig getMailetConfig() throws Exception {
            ConfigServiceRunner.startConfigService();
            cleanConfig();
            addDomains();
            addTrustAnchors();
            Map<String, String> params = new HashMap<String, String>();
            params.put("ConfigURL", ConfigServiceRunner.getConfigServiceURL());
            return new MockMailetConfig(params, "NHINDSecurityAndTrustMailet");
        }

        protected void addDomains() throws Exception {
            Domain dom = new Domain();
            dom.setDomainName("cerner.com");
            dom.setPostMasterEmail("postmaster@cerner.com");
            proxy.addDomain(dom);
            dom = new Domain();
            dom.setDomainName("securehealthemail.com");
            dom.setPostMasterEmail("postmaster@securehealthemail.com");
            proxy.addDomain(dom);
        }

        protected void addTrustAnchors() throws Exception {
            Vector<Anchor> vec = new Vector<Anchor>();
            Anchor anchor = new Anchor();
            anchor.setData(getCertificateFileData("cacert.der"));
            anchor.setOwner("cerner.com");
            anchor.setIncoming(true);
            anchor.setOutgoing(true);
            vec.add(anchor);
            anchor = new Anchor();
            anchor.setData(getCertificateFileData("cacert.der"));
            anchor.setOwner("securehealthemail.com");
            anchor.setIncoming(true);
            anchor.setOutgoing(true);
            vec.add(anchor);
            proxy.addAnchor(vec.toArray(new Anchor[vec.size()]));
        }

        protected void cleanConfig() throws Exception {
            proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
            // clean domains
            int domainCount = proxy.getDomainCount();
            Domain[] doms = proxy.listDomains(null, domainCount);
            if (doms != null)
                for (Domain dom : doms) {
                    // clean anchors
                    proxy.removeAnchorsForOwner(dom.getDomainName());
                    proxy.removeDomain(dom.getDomainName());
                }
            // clean certificates
            Certificate[] certs = proxy.listCertificates(0, 0x8FFFF, null);
            if (certs != null)
                for (Certificate cert : certs) proxy.removeCertificatesForOwner(cert.getOwner());
            // clean settings
            Setting[] settings = proxy.getAllSettings();
            if (settings != null)
                for (Setting setting : settings) proxy.deleteSetting(new String[] { setting.getName() });
        }

        @Override
        protected void doAssertions(NHINDSecurityAndTrustMailet agent) throws Exception {
            assertNotNull(agent);
            assertNotNull(agent.getInitParameter("ConfigURL"));
            assertEquals(ConfigServiceRunner.getConfigServiceURL(), agent.getInitParameter("ConfigURL"));
        }
    }.perform();
}
Also used : BaseTestPlan(org.nhindirect.gateway.testutils.BaseTestPlan) Setting(org.nhind.config.Setting) MailetConfig(org.apache.mailet.MailetConfig) MessagingException(javax.mail.MessagingException) Anchor(org.nhind.config.Anchor) Domain(org.nhind.config.Domain) HashMap(java.util.HashMap) Map(java.util.Map) Vector(java.util.Vector) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy) Certificate(org.nhind.config.Certificate)

Example 2 with MailetConfig

use of org.apache.mailet.MailetConfig 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)

Example 3 with MailetConfig

use of org.apache.mailet.MailetConfig in project nhin-d by DirectProject.

the class RefreshSecurityAndTrustStateMailet_refreshStateTest method getMailet.

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);
    retVal = new NHINDSecurityAndTrustMailet();
    MailetConfig mailetConfig = new MockMailetConfig(params, "NHINDSecurityAndTrustMailet");
    retVal.init(mailetConfig);
    return retVal;
}
Also used : HashMap(java.util.HashMap) MailetConfig(org.apache.mailet.MailetConfig) Mailet(org.apache.mailet.Mailet)

Example 4 with MailetConfig

use of org.apache.mailet.MailetConfig in project nhin-d by DirectProject.

the class TimelyAndReliableLocalDelivery_serviceTest method testService_failedDelivery_assertDSNCreated.

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

        @Override
        protected void setupMocks() {
            theMailet = new TimelyAndReliableLocalDelivery() {

                protected Object createLocalDeliveryClass() throws Exception {
                    Mailet mailet = mock(Mailet.class);
                    doThrow(new RuntimeException()).when(mailet).service((Mail) any());
                    return mailet;
                }
            };
            try {
                MailetConfig config = getMailetConfig();
                theMailet.init(config);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        protected void doAssertions(MockMailetContext context) throws Exception {
            assertEquals(1, context.getSentMessages().size());
            MimeMessage dsnMessage = context.getSentMessages().iterator().next().getMessage();
            assertEquals(TxMessageType.DSN, TxUtil.getMessageType(dsnMessage));
            String originalMessageString = TestUtils.readMessageResource(getMessageToSend());
            MimeMessage originalMsg = EntitySerializer.Default.deserialize(originalMessageString);
            NHINDAddress originalRecipAddress = new NHINDAddress(MailStandard.getHeader(originalMsg, MailStandard.Headers.To));
            NHINDAddress dsnFromAddress = new NHINDAddress(MailStandard.getHeader(dsnMessage, MailStandard.Headers.From));
            assertTrue(dsnFromAddress.getHost().toLowerCase(Locale.getDefault()).contains(originalRecipAddress.getHost().toLowerCase(Locale.getDefault())));
        }
    }.perform();
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) BaseTestPlan(org.nhindirect.gateway.testutils.BaseTestPlan) MimeMessage(javax.mail.internet.MimeMessage) MailetConfig(org.apache.mailet.MailetConfig) Mailet(org.apache.mailet.Mailet)

Example 5 with MailetConfig

use of org.apache.mailet.MailetConfig in project nhin-d by DirectProject.

the class TimelyAndReliableLocalDelivery_serviceTest method testService_failedDelivery_nonIMF_assertDSNNotCreated.

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

        @Override
        protected void setupMocks() {
            theMailet = new TimelyAndReliableLocalDelivery() {

                protected Object createLocalDeliveryClass() throws Exception {
                    Mailet mailet = mock(Mailet.class);
                    doThrow(new RuntimeException()).when(mailet).service((Mail) any());
                    return mailet;
                }
            };
            try {
                MailetConfig config = getMailetConfig();
                theMailet.init(config);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        protected String getMessageToSend() {
            return "MDNMessage.txt";
        }

        @Override
        protected void doAssertions(MockMailetContext context) throws Exception {
            assertEquals(0, context.getSentMessages().size());
        }
    }.perform();
}
Also used : BaseTestPlan(org.nhindirect.gateway.testutils.BaseTestPlan) MailetConfig(org.apache.mailet.MailetConfig) Mailet(org.apache.mailet.Mailet)

Aggregations

MailetConfig (org.apache.mailet.MailetConfig)6 HashMap (java.util.HashMap)4 Mailet (org.apache.mailet.Mailet)4 BaseTestPlan (org.nhindirect.gateway.testutils.BaseTestPlan)4 Map (java.util.Map)2 MessagingException (javax.mail.MessagingException)2 MimeMessage (javax.mail.internet.MimeMessage)2 Vector (java.util.Vector)1 MailAddress (org.apache.mailet.MailAddress)1 Anchor (org.nhind.config.Anchor)1 Certificate (org.nhind.config.Certificate)1 ConfigurationServiceProxy (org.nhind.config.ConfigurationServiceProxy)1 Domain (org.nhind.config.Domain)1 Setting (org.nhind.config.Setting)1 MockMailetConfig (org.nhind.testutils.MockMailetConfig)1 NHINDSecurityAndTrustMailet (org.nhindirect.gateway.smtp.james.mailet.NHINDSecurityAndTrustMailet)1 NHINDAddress (org.nhindirect.stagent.NHINDAddress)1