Esempio n. 1
0
        public void Test()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentAuditConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            m_agent = SmtpAgentFactory.Create(settings);
            Assert.Null(Record.Exception(() => m_agent.ProcessMessage(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid())))));
            Assert.Throws <OutgoingAgentException>(() => m_agent.ProcessMessage(this.LoadMessage(BadMessage)));
        }
Esempio n. 2
0
        public void TestBasic()
        {
            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse  = true;

            Message msg = Message.Load(string.Format(TestMessage, Guid.NewGuid()));

            msg.RequestNotification();

            OutgoingMessage outgoing = null;
            IncomingMessage incoming = null;

            base.ProcessEndToEnd(m_agent, msg, out outgoing, out incoming);

            int i = 0;

            foreach (NotificationMessage notification in m_producer.Produce(incoming))
            {
                DirectAddress sender = incoming.DomainRecipients[i++];
                Assert.Equal(sender.Address, notification.FromValue, MailStandard.Comparer);
            }

            m_agent.Settings.InternalMessage.PickupFolder = Path.GetTempPath();
            Assert.Null(Record.Exception(() => m_agent.ProcessMessage(this.LoadMessage(outgoing.SerializeMessage()))));
        }
Esempio n. 3
0
        //
        // Processing message like smtp gateway would
        //
        CDO.Message RunEndToEndTest(CDO.Message message, SmtpAgent agent)
        {
            agent.ProcessMessage(message);
            message = LoadMessage(message);
            VerifyOutgoingMessage(message);

            agent.ProcessMessage(message);
            message = LoadMessage(message);

            if (agent.Settings.InternalMessage.EnableRelay)
            {
                VerifyIncomingMessage(message);
            }
            else
            {
                VerifyOutgoingMessage(message);
            }
            return(message);
        }
Esempio n. 4
0
        CDO.Message RunEndToEndTest(CDO.Message message)
        {
            m_agent.ProcessMessage(message);
            message = this.LoadMessage(message);
            base.VerifyOutgoingMessage(message);

            m_agent.ProcessMessage(message);
            message = this.LoadMessage(message);

            if (m_agent.Settings.InternalMessage.EnableRelay)
            {
                base.VerifyIncomingMessage(message);
            }
            else
            {
                base.VerifyOutgoingMessage(message);
            }
            return(message);
        }
Esempio n. 5
0
        public void Test_PluginRouter_Under_Parallel_Load()
        {
            string configPath = GetSettingsPath("TestReceiverPlugin.xml");
            var    settings   = SmtpAgentSettings.LoadSettings(configPath);

            settings.InternalMessage.PickupFolder = TestPickupFolder;

            //
            // Create the SmtpAgent.  This is the adapter between IIS SMTP and the DirectAgent (security and trust code)
            //
            m_agent = SmtpAgentFactory.Create(settings);
            CleanMessages(m_agent.Settings);

            //
            // Mocks use the AddressMemoryStore
            //
            AddressMemoryStore.Clear();
            AddressMemoryStore.AddRange(new Address[]
            {
                new Address {
                    EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled, Type = "STUB"
                }
            });

            var mockAddressClientSettings = MockAddressClientSettings();

            m_agent.Settings.AddressManager = mockAddressClientSettings.Object;


            DirectAgent agentA = new DirectAgent("redmond.hsgincubator.com");

            Parallel.For(0, 50, new ParallelOptions {
                MaxDegreeOfParallelism = 10
            }, i =>
            {
                var message = string.Format(TestMessageLoad, Guid.NewGuid().ToString("N"), i);

                //
                // Prep and encrypted message.
                //
                var outMessage = agentA.ProcessOutgoing(message).SerializeMessage();
                var cdoMessage = new CDOSmtpMessage(base.LoadMessage(outMessage));

                m_agent.ProcessMessage(cdoMessage);
            });


            Assert.Equal(49, Directory.GetFiles(TestIncomingFolder).Length);
            Assert.Equal(1, Directory.GetFiles(TestPickupFolder).Length);
        }
Esempio n. 6
0
 void RunMdnOutBoundProcessingTest(CDO.Message message, SmtpAgent agent)
 {
     VerifyMdnIncomingMessage(message);  //Plain Text
     agent.ProcessMessage(message);      //Encrypts
     VerifyOutgoingMessage(message);     //Mdn looped back
 }
Esempio n. 7
0
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_AlwaysGenerate_AllRecipientsRejected(
            string untrustedRecipientMessage
            , List <DSNPerRecipient> perRecipientExpected)
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay          = true;
            m_agent.Settings.Notifications.AutoResponse           = false; //don't care.  This is MDN specific
            m_agent.Settings.Notifications.AlwaysAck              = false; //don't care.  This is MDN specific
            m_agent.Settings.Notifications.AutoDsnFailureCreation =
                NotificationSettings.AutoDsnOption.Always.ToString();

            MdnMemoryStore.Clear();
            Mock <ClientSettings> mockClientSettings = MockMdnClientSettings();

            m_agent.Settings.MdnMonitor = mockClientSettings.Object;

            //
            // Process loopback messages.  Leaves un-encrypted mdns in pickup folder
            // Go ahead and pick them up and Process them as if they where being handled
            // by the SmtpAgent by way of (IIS)SMTP hand off.
            //
            var sendingMessage = LoadMessage(untrustedRecipientMessage);

            Assert.Equal(
                string.Format("Error={0}", AgentError.NoTrustedRecipients),
                Assert.Throws <OutgoingAgentException>(() => m_agent.ProcessMessage(sendingMessage)).Message
                );

            //No trusted recipients so not encrypted.
            ContentType contentType = new ContentType(sendingMessage.GetContentType());

            Assert.False(SMIMEStandard.IsContentEncrypted(contentType));


            //
            // grab the clear text dsn and delete others.
            // Process them as outgoing messages
            //
            bool foundDsn = false;

            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("message/delivery-status"))
                {
                    foundDsn = true;
                    Assert.DoesNotThrow(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText)));

                    //
                    // assert not in the monitor store.
                    // DSN messages are not monitored.
                    //
                    var queryMdn = BuildQueryFromDSN(LoadMessage(messageText));
                    var mdn      = MdnMemoryStore.FirstOrDefault(m => m.MdnIdentifier == queryMdn.MdnIdentifier);
                    Assert.Null(mdn);
                }
            }
            Assert.True(foundDsn);

            //
            // Now the messages are encrypted and can be handled as inbound messages.
            //
            foundDsn = false;
            foreach (var pickupMessage in PickupMessages())
            {
                foundDsn = true;
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message message     = LoadMessage(messageText);
                Assert.DoesNotThrow(() => RunMdnInBoundProcessingTest(message));
                var dsnMessage = new CDOSmtpMessage(message).GetEnvelope();
                Assert.True(dsnMessage.Message.IsDSN());
                Assert.False(dsnMessage.Message.IsMDN());

                var dsn = DSNParser.Parse(dsnMessage.Message);
                foreach (var perRecipient in dsn.PerRecipient)
                {
                    Assert.Equal(perRecipientExpected.Count, dsn.PerRecipient.Count());
                    string finalRecipient       = perRecipient.FinalRecipient.Address;
                    var    expectedPerRecipient = perRecipientExpected.Find(d => d.FinalRecipient.Address == finalRecipient);
                    Assert.Equal(expectedPerRecipient.Action, perRecipient.Action);
                    Assert.Equal(expectedPerRecipient.Status, perRecipient.Status);
                }
            }
            Assert.True(foundDsn);

            //Ensure no MDNs where created by the DSN.
            Assert.True(!PickupMessages().Any());

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Esempio n. 8
0
        public void TestEndToEndStartMdnMonitor()
        {
            CleanMessages(m_agent.Settings);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse  = true;
            m_agent.Settings.Notifications.AlwaysAck     = true;
            m_agent.Settings.MdnMonitor     = new ClientSettings();
            m_agent.Settings.MdnMonitor.Url = "http://localhost/ConfigService/MonitorService.svc/Dispositions";

            //
            // Process loopback messages.  Leaves un-encrypted mdns in pickup folder
            // Go ahead and pick them up and Process them as if they where being handled
            // by the SmtpAgent by way of (IIS)SMTP hand off.
            //
            var sendingMessage = LoadMessage(string.Format(TestMessage, Guid.NewGuid()));

            Assert.Null(Record.Exception(() => RunEndToEndTest(sendingMessage)));

            //
            // grab the clear text mdns and delete others.
            //
            bool foundMdns = false;

            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    foundMdns = true;
                    Assert.Null(Record.Exception(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText))));
                }
            }
            Assert.True(foundMdns);

            //
            // Now the messages are encrypted and can be handled
            // Processed Mdn's will be recorded by the MdnMonitorService
            //
            foundMdns = false;
            foreach (var pickupMessage in PickupMessages())
            {
                foundMdns = true;
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message message     = LoadMessage(messageText);
                Assert.Null(Record.Exception(() => RunMdnInBoundProcessingTest(message)));

                //
                // Prove we cannot send duplicate MDNs.
                //
                var duplicateMessage = LoadMessage(messageText);
                VerifyOutgoingMessage(duplicateMessage);         //Encryted Message
                m_agent.ProcessMessage(duplicateMessage);        //Decrypts Message
                //This proves we could not process the message because it is still encrypted
                //Could possibly check to see if it was dropped.  This integration test is getting ugly...
                VerifyOutgoingMessage(duplicateMessage);         //Encryted Message

                TestMdnsInProcessedStatus(message, false);
            }
            Assert.True(foundMdns);
            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Esempio n. 9
0
 void RunMdnOutBoundProcessingTest(CDO.Message message, SmtpAgent agent)
 {
     VerifyMdnIncomingMessage(message);      //Plain Text
     agent.ProcessMessage(message);        //Encrypts
     VerifyOutgoingMessage(message);    //Mdn looped back
 }
Esempio n. 10
0
        //
        // Processing message like smtp gateway would
        //
        CDO.Message RunEndToEndTest(CDO.Message message, SmtpAgent agent)
        {
            agent.ProcessMessage(message);
            message = LoadMessage(message);
            VerifyOutgoingMessage(message);

            agent.ProcessMessage(message);
            message = LoadMessage(message);

            if (agent.Settings.InternalMessage.EnableRelay)
            {
                VerifyIncomingMessage(message);
            }
            else
            {
                VerifyOutgoingMessage(message);
            }
            return message;
        }
Esempio n. 11
0
 public void Test()
 {
     Assert.DoesNotThrow(() => m_agent.ProcessMessage(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid()))));
     Assert.Throws <OutgoingAgentException>(() => m_agent.ProcessMessage(this.LoadMessage(BadMessage)));
 }
Esempio n. 12
0
 internal void RunMdnInBoundProcessingTest(CDO.Message message, SmtpAgent smtpAgent)
 {
     VerifyOutgoingMessage(message);       //Encryted Message
     smtpAgent.ProcessMessage(message);    //Decrypts Message
     VerifyMdnIncomingMessage(message);    //Mdn looped back
 }