Example #1
0
        public void TestConstructContextUnParsablePatient(string file)
        {
            var smtpMessage  = new CDOSmtpMessage(SmtpAgent.Extensions.LoadCDOMessage(file));
            var testFileName = SmtpAgent.Extensions.CreateUniqueFileName();

            var receiver = new LoopBackContext
            {
                TestFilename = testFileName
            };

            var settings = new PongContextSettings()
            {
                PickupFolder = TestPickupFolder
            };

            receiver.Settings = settings;
            Assert.True(receiver.Receive(smtpMessage));

            var resultMessage = MimeMessage.Load(
                Path.Combine(
                    settings.PickupFolder,
                    testFileName));

            Assert.Equal("Context Error=InvalidPatient", resultMessage.TextBody);
        }
Example #2
0
        public void TestConstructContextSuccess(string file)
        {
            var smtpMessage  = new CDOSmtpMessage(SmtpAgent.Extensions.LoadCDOMessage(file));
            var testFileName = SmtpAgent.Extensions.CreateUniqueFileName();

            var receiver = new LoopBackContext
            {
                TestFilename = testFileName
            };

            var settings = new PongContextSettings()
            {
                PickupFolder = TestPickupFolder
            };

            receiver.Settings = settings;
            Assert.True(receiver.Receive(smtpMessage));

            var mimeMessage = MimeMessage.Load(Path.Combine(
                                                   settings.PickupFolder,
                                                   testFileName));

            Assert.StartsWith("<", mimeMessage.Headers["X-Direct-Context"]);
            Assert.EndsWith(">", mimeMessage.Headers["X-Direct-Context"]);
        }
Example #3
0
        public void TestConstructContextNoContext(string file)
        {
            var smtpMessage  = new CDOSmtpMessage(SmtpAgent.Extensions.LoadCDOMessage(file));
            var testFileName = SmtpAgent.Extensions.CreateUniqueFileName();

            var receiver = new LoopBackContext
            {
                TestFilename = testFileName
            };

            var settings = new PongContextSettings()
            {
                PickupFolder = TestPickupFolder
            };

            receiver.Settings = settings;
            Assert.True(receiver.Receive(smtpMessage));

            var resultMessage = MimeMessage.Load(
                Path.Combine(
                    settings.PickupFolder,
                    testFileName));

            Assert.Equal("Object reference not set to an instance of an object.", resultMessage.TextBody);
        }
Example #4
0
        public void TestFromXml()
        {
            SmtpAgent agent = null;

            Assert.Null(Record.Exception(() => agent = SmtpAgentFactory.Create(GetSettingsPath("TestPlugin.xml"))));
            Assert.True(agent.Router.Count == 3);

            Route[] routes = agent.Router.ToArray();

            ValidateHttpReceivers(routes[0], 2, "http://foo/one");
            ValidateHttpReceivers(routes[1], 1, "http://bar/one");
            ValidateSmtpReceivers(routes[2], 2, "foo.xyz");

            //
            // Pump a few messages through
            //
            CDOSmtpMessage message = new CDOSmtpMessage(base.LoadMessage(MultiToMessage));

            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < routes.Length - 1; ++j) // Not testing the last route, which is Smtp
                {
                    Assert.True(routes[j].Process(message));
                }
            }
        }
Example #5
0
        public void TestFinalDestinationDelivery(string unDeliverableRecipientMessage, List <DSNPerRecipient> perRecipientExpected)
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse  = true;
            m_agent.Settings.Notifications.AlwaysAck     = true;
            //
            // Do not need to set AutoDsnOption to TimelyAndReliable as it is the default setting.
            //
            //m_agent.Settings.Notifications.AutoDsnFailureCreation =
            //    NotificationSettings.AutoDsnOption.TimelyAndReliable.ToString();
            m_agent.Settings.AddressManager     = new ClientSettings();
            m_agent.Settings.AddressManager.Url = "http://localhost/ConfigService/DomainManagerService.svc/Addresses";
            m_agent.Settings.MdnMonitor         = new ClientSettings();
            m_agent.Settings.MdnMonitor.Url     = "http://localhost/ConfigService/MonitorService.svc/Dispositions";

            foreach (FolderRoute route in m_agent.Settings.IncomingRoutes.Where(route => route.AddressType == "Throw"))
            {
                route.CopyMessageHandler = ThrowCopy;
            }

            //
            // 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(unDeliverableRecipientMessage);

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

            var foundDsn = false;

            foreach (var pickupMessage in PickupMessages())
            {
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message cdoMessage  = LoadMessage(messageText);
                var         message     = new CDOSmtpMessage(cdoMessage).GetEnvelope();
                if (message.Message.IsDSN())
                {
                    foundDsn = true;

                    var dsn = DSNParser.Parse(message.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);

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #6
0
        protected static Mdn BuildQueryFromDSN(CDO.Message message)
        {
            var messageEnvelope = new CDOSmtpMessage(message).GetEnvelope();

            Assert.True(messageEnvelope.Message.IsDSN());
            var    mimeMessage = messageEnvelope.Message;
            var    messageId   = mimeMessage.IDValue;
            string sender      = messageEnvelope.Sender.Address;
            string recipient   = messageEnvelope.Recipients[0].Address;

            return(new Mdn(messageId, recipient, sender));
        }
Example #7
0
        protected static Mdn BuildMdnQueryFromMdn(CDO.Message message)
        {
            var messageEnvelope = new CDOSmtpMessage(message).GetEnvelope();

            Assert.True(messageEnvelope.Message.IsMDN());
            var    notification      = MDNParser.Parse(messageEnvelope.Message);
            var    originalMessageId = notification.OriginalMessageID;
            string originalSender    = messageEnvelope.Recipients[0].Address;
            string originalRecipient = messageEnvelope.Sender.Address;

            return(new Mdn(originalMessageId, originalRecipient, originalSender));
        }
Example #8
0
        public void TestEndToEnd_GatewayIsDestination_Is_True_And_TimelyAndReliable_Not_Requestd()
        {
            CleanMessages(m_agent.Settings);
            m_agent.Settings.InternalMessage.EnableRelay        = true;
            m_agent.Settings.Outgoing.EnableRelay               = true;
            m_agent.Settings.Notifications.AutoResponse         = true;
            m_agent.Settings.Notifications.AlwaysAck            = true;
            m_agent.Settings.Notifications.GatewayIsDestination = true;

            //
            // 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.
            //
            string textMessage    = string.Format(string.Format(TestMessageHsmToSoft, Guid.NewGuid()), Guid.NewGuid());
            var    sendingMessage = LoadMessage(textMessage);

            RunEndToEndTest(sendingMessage, m_agent);

            //
            // grab the clear text mdns and delete others.
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    RunMdnOutBoundProcessingTest(LoadMessage(messageText), m_agent);
                }
            }

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

                RunMdnInBoundProcessingTest(message, m_agent);
                var envelope = new CDOSmtpMessage(message).GetEnvelope();
                var mdn      = MDNParser.Parse(envelope.Message);

                //
                // Only expect processed MDNs
                //
                Assert.Equal(MDNStandard.NotificationType.Processed, mdn.Disposition.Notification);
                TestMdnTimelyAndReliableExtensionField(mdn, false);
            }

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #9
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);
        }
Example #10
0
        public void SendMail(string[] args)
        {
            CDOSmtpMessage smtpMessage = new CDOSmtpMessage(Extensions.LoadCDOMessage(args.GetRequiredValue(0)));
            //
            // Use SmtpRoute to get some free code coverage/easy test
            //
            SmtpMessageForwarder route    = new SmtpMessageForwarder();
            SmtpSettings         settings = new SmtpSettings()
            {
                Server = args.GetRequiredValue(1),
                Port   = args.GetOptionalValue(2, -1)
            };

            route.Settings = settings;
            route.Receive(smtpMessage);
        }
Example #11
0
        CDO.Message RunEndToEndTest(CDO.Message message)
        {
            m_agent.ProcessMessage(message);
            message = LoadMessage(message);
            VerifyOutgoingMessage(message);

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

            if (m_agent.Settings.InternalMessage.EnableRelay)
            {
                var smtpMessage = new CDOSmtpMessage(message).GetEnvelope();
                VerifyIncomingMessage(message);
            }
            else
            {
                VerifyOutgoingMessage(message);
            }
            return(message);
        }
Example #12
0
        public void TestConstructContextIgnorDSN(string file)
        {
            var smtpMessage  = new CDOSmtpMessage(SmtpAgent.Extensions.LoadCDOMessage(file));
            var testFileName = SmtpAgent.Extensions.CreateUniqueFileName();

            var receiver = new LoopBackContext
            {
                TestFilename = testFileName
            };

            var settings = new PongContextSettings()
            {
                PickupFolder = TestPickupFolder
            };

            receiver.Settings = settings;
            Assert.True(receiver.Receive(smtpMessage));

            Assert.False(File.Exists(Path.Combine(
                                         settings.PickupFolder,
                                         testFileName)));
        }
Example #13
0
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_AlwaysGenerate()
        {
            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(ContainsUntrustedRecipientMessageNoTandR);

            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            //
            // 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());
            }
            Assert.True(foundDsn);

            //Ensure no MDNs where created by the DSN.
            Assert.True(PickupMessages().Count() == 0);

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #14
0
        public void TestFinalDestinationDelivery(string unDeliverableRecipientMessage
                                                 , List <DSNPerRecipient> perRecipientExpected)
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse  = true;
            m_agent.Settings.Notifications.AlwaysAck     = true;
            //
            // Do not need to set AutoDsnOption to TimelyAndReliable as it is the default setting.
            //

            AddressMemoryStore.Clear();
            AddressMemoryStore.AddRange(new Address[]
            {
                new Address()
                {
                    EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled
                },
                new Address()
                {
                    EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled, Type = "Throw"
                },
                new Address()
                {
                    EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled, Type = "Throw"
                }
            });

            Mock <ClientSettings> mockAddressClientSettings = MockAddressClientSettings();

            m_agent.Settings.AddressManager = mockAddressClientSettings.Object;


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

            m_agent.Settings.MdnMonitor = mockMdnClientSettings.Object;

            foreach (FolderRoute route in m_agent.Settings.IncomingRoutes.Where(route => route.AddressType == "Throw"))
            {
                route.CopyMessageHandler = ThrowCopy;
            }

            //
            // 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(unDeliverableRecipientMessage);

            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            var foundDsn = false;

            foreach (var pickupMessage in PickupMessages())
            {
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message cdoMessage  = LoadMessage(messageText);
                var         message     = new CDOSmtpMessage(cdoMessage).GetEnvelope();
                if (message.Message.IsDSN())
                {
                    foundDsn = true;

                    var dsn = DSNParser.Parse(message.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);


            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #15
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;
        }
Example #16
0
        public void TestFinalDestinationDelivery(string unDeliverableRecipientMessage
            , List<DSNPerRecipient> perRecipientExpected)
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse = true;
            m_agent.Settings.Notifications.AlwaysAck = true;
            //
            // Do not need to set AutoDsnOption to TimelyAndReliable as it is the default setting.
            //
            
            AddressMemoryStore.Clear();
            AddressMemoryStore.AddRange(new Address[]
                {
                    new Address(){EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled},
                    new Address(){EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled, Type = "Throw"},
                    new Address(){EmailAddress = "*****@*****.**", Status = EntityStatus.Enabled, Type = "Throw"}
                });

            Mock<ClientSettings> mockAddressClientSettings = MockAddressClientSettings();
            m_agent.Settings.AddressManager = mockAddressClientSettings.Object;

            
            MdnMemoryStore.Clear();
            Mock<ClientSettings> mockMdnClientSettings = MockMdnClientSettings();
            m_agent.Settings.MdnMonitor = mockMdnClientSettings.Object;

            foreach (FolderRoute route in m_agent.Settings.IncomingRoutes.Where(route => route.AddressType == "Throw"))
            {
                route.CopyMessageHandler = ThrowCopy;
            }
 
            //
            // 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(unDeliverableRecipientMessage);
            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            var foundDsn = false;
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                CDO.Message cdoMessage = LoadMessage(messageText);
                var message = new CDOSmtpMessage(cdoMessage).GetEnvelope();
                if(message.Message.IsDSN())
                {
                    foundDsn = true;

                    var dsn = DSNParser.Parse(message.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);


            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #17
0
 protected static Mdn BuildQueryFromDSN(CDO.Message message)
 {
     var messageEnvelope = new CDOSmtpMessage(message).GetEnvelope();
     Assert.True(messageEnvelope.Message.IsDSN());
     var mimeMessage = messageEnvelope.Message;
     var messageId = mimeMessage.IDValue;
     string sender = messageEnvelope.Sender.Address;
     string recipient = messageEnvelope.Recipients[0].Address;
     return new Mdn(messageId, recipient, sender);
 }
Example #18
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;
        }
Example #19
0
        public void TestEndToEnd_GatewayIsDestination_Is_True_And_TimelyAndReliable_Not_Requestd()
        {
            CleanMessages(m_agent.Settings);
            m_agent.Settings.InternalMessage.EnableRelay        = true;
            m_agent.Settings.Outgoing.EnableRelay               = true;
            m_agent.Settings.Notifications.AutoResponse         = true;
            m_agent.Settings.Notifications.AlwaysAck            = true;
            m_agent.Settings.Notifications.GatewayIsDestination = 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.
            //
            string textMessage    = string.Format(string.Format(TestMessage, Guid.NewGuid()), Guid.NewGuid());
            var    sendingMessage = LoadMessage(textMessage);

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

            //
            // grab the clear text mdns and delete others.
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    Assert.Null(Record.Exception(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText))));
                }
            }

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

                Assert.Null(Record.Exception(() => RunMdnInBoundProcessingTest(message)));
                var envelope = new CDOSmtpMessage(message).GetEnvelope();
                var mdn      = MDNParser.Parse(envelope.Message);

                //
                // Only expect processed MDNs
                //
                Assert.Equal(MDNStandard.NotificationType.Processed, mdn.Disposition.Notification);
                TestMdnTimelyAndReliableExtensionField(mdn, false);
            }

            //
            // Test Mdn data is processed
            // Remember above (Settings.Notifications.GatewayIsDestination = true)
            // but message did not request TimelyAndReliable
            //
            var messageEnvelope = new CDOSmtpMessage(sendingMessage).GetEnvelope();

            foreach (var recipient in messageEnvelope.Recipients)
            {
                var queryMdn = new Mdn(messageEnvelope.Message.IDValue
                                       , recipient.Address
                                       , messageEnvelope.Message.FromValue
                                       , MdnStatus.Processed);

                var mdnManager = CreateConfigStore().Mdns;
                var mdn        = mdnManager.Get(queryMdn.MdnIdentifier);
                Assert.NotNull(mdn);
                Assert.Equal("processed", mdn.Status, StringComparer.OrdinalIgnoreCase);
                Assert.Equal(false, mdn.NotifyDispatched);
            }

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #20
0
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_GenerateOnlyIfRequested()
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse = true;
            m_agent.Settings.Notifications.AlwaysAck = true;
            //
            // Do not need to set AutoDsnOption to TimelyAndReliable as it is the default setting.
            //

            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(ContainsUntrustedRecipientMessageRequestTandR);
            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            //
            // 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());
            }
            Assert.True(foundDsn);

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

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #21
0
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_GenerateOnlyIfRequested()
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse  = true;
            m_agent.Settings.Notifications.AlwaysAck     = true;
            //
            // Do not need to set AutoDsnOption to TimelyAndReliable as it is the default setting.
            //
            //m_agent.Settings.Notifications.AutoDsnFailureCreation =
            //    NotificationSettings.AutoDsnOption.TimelyAndReliable.ToString();
            //m_agent.Settings.AddressManager = new ClientSettings();
            //m_agent.Settings.AddressManager.Url = "http://localhost:6692/DomainManagerService.svc/Addresses";
            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(ContainsUntrustedRecipientMessageRequestTandR);

            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            //
            // 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));
                    queryMdn.Status = MdnStatus.Started;
                    var mdnManager = CreateConfigStore().Mdns;
                    var mdn        = mdnManager.Get(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());
            }
            Assert.True(foundDsn);

            //Ensure no MDNs where created by the DSN.
            Assert.True(PickupMessages().Count() == 0);

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #22
0
 internal void VerifyDSNIncomingMessage(CDO.Message message)
 {
     var envelope = new CDOSmtpMessage(message).GetEnvelope();
     Assert.True(envelope.Message.IsDSN());
 }
Example #23
0
 protected static Mdn BuildMdnQueryFromMdn(CDO.Message message)
 {
     var messageEnvelope = new CDOSmtpMessage(message).GetEnvelope();
     Assert.True(messageEnvelope.Message.IsMDN());
     var notification = MDNParser.Parse(messageEnvelope.Message);
     var originalMessageId = notification.OriginalMessageID;
     string originalSender = messageEnvelope.Recipients[0].Address;
     string originalRecipient = messageEnvelope.Sender.Address;
     return new Mdn(originalMessageId, originalRecipient, originalSender);
 }
Example #24
0
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_AlwaysGenerate()
        {
            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(); 
            //m_agent.Settings.AddressManager = new ClientSettings();
            //m_agent.Settings.AddressManager.Url = "http://localhost:6692/DomainManagerService.svc/Addresses";
            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(ContainsUntrustedRecipientMessageNoTandR);
            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            //
            // 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));
                    queryMdn.Status = MdnStatus.Started;
                    var mdnManager = CreateConfigStore().Mdns;
                    var mdn = mdnManager.Get(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());
            }
            Assert.True(foundDsn);

            //Ensure no MDNs where created by the DSN.
            Assert.True(PickupMessages().Count() == 0);

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #25
0
        internal void VerifyDSNIncomingMessage(CDO.Message message)
        {
            var envelope = new CDOSmtpMessage(message).GetEnvelope();

            Assert.True(envelope.Message.IsDSN());
        }
        public void TestEndToEnd_GatewayIsDestination_Is_True_And_TimelyAndReliable_Not_Requestd()
        {
            CleanMessages(m_agent.Settings);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Outgoing.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse = true;
            m_agent.Settings.Notifications.AlwaysAck = true;
            m_agent.Settings.Notifications.GatewayIsDestination = true;
            m_agent.Settings.MdnMonitor = new ClientSettings();
            m_agent.Settings.MdnMonitor.Url = "http://localhost:6692/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.
            //
            string textMessage = string.Format(string.Format(TestMessage, Guid.NewGuid()), Guid.NewGuid());
            var sendingMessage = LoadMessage(textMessage);
            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            //
            // grab the clear text mdns and delete others.
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    Assert.DoesNotThrow(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText)));
                }
            }

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

                Assert.DoesNotThrow(() => RunMdnInBoundProcessingTest(message));
                var envelope = new CDOSmtpMessage(message).GetEnvelope();
                var mdn = MDNParser.Parse(envelope.Message);

                //
                // Only expect processed MDNs
                //
                Assert.Equal(MDNStandard.NotificationType.Processed, mdn.Disposition.Notification);
                TestMdnTimelyAndReliableExtensionField(mdn, false);
            }

            //
            // Test Mdn data is processed
            // Remember above (Settings.Notifications.GatewayIsDestination = true)
            // but message did not request TimelyAndReliable
            //
            var messageEnvelope = new CDOSmtpMessage(sendingMessage).GetEnvelope();
            foreach (var recipient in messageEnvelope.Recipients)
            {
                var queryMdn = new Mdn(messageEnvelope.Message.IDValue
                        , recipient.Address
                        , messageEnvelope.Message.FromValue
                        , MdnStatus.Processed);

                var mdnManager = CreateConfigStore().Mdns;
                var mdn = mdnManager.Get(queryMdn.MdnIdentifier);
                Assert.NotNull(mdn);
                Assert.Equal("processed", mdn.Status, StringComparer.OrdinalIgnoreCase);
                Assert.Equal(false, mdn.NotifyDispatched);
            }

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Example #27
0
        public void TestFinalDestinationDelivery(string unDeliverableRecipientMessage
            , List<DSNPerRecipient> perRecipientExpected)
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse = true;
            m_agent.Settings.Notifications.AlwaysAck = true;
            //
            // Do not need to set AutoDsnOption to TimelyAndReliable as it is the default setting.
            //
            //m_agent.Settings.Notifications.AutoDsnFailureCreation =
            //    NotificationSettings.AutoDsnOption.TimelyAndReliable.ToString();
            m_agent.Settings.AddressManager = new ClientSettings();
            m_agent.Settings.AddressManager.Url = "http://localhost/ConfigService/DomainManagerService.svc/Addresses";
            m_agent.Settings.MdnMonitor = new ClientSettings();
            m_agent.Settings.MdnMonitor.Url = "http://localhost/ConfigService/MonitorService.svc/Dispositions";

            foreach (FolderRoute route in m_agent.Settings.IncomingRoutes.Where(route => route.AddressType == "Throw"))
            {
                route.CopyMessageHandler = ThrowCopy;
            }
 
            //
            // 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(unDeliverableRecipientMessage);
            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage));

            var foundDsn = false;
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                CDO.Message cdoMessage = LoadMessage(messageText);
                var message = new CDOSmtpMessage(cdoMessage).GetEnvelope();
                if(message.Message.IsDSN())
                {
                    foundDsn = true;

                    var dsn = DSNParser.Parse(message.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);


            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
        CDO.Message RunEndToEndTest(CDO.Message message)
        {
            m_agent.ProcessMessage(message);
            message = LoadMessage(message);
            VerifyOutgoingMessage(message);

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

            if (m_agent.Settings.InternalMessage.EnableRelay)
            {
                var smtpMessage = new CDOSmtpMessage(message).GetEnvelope();
                VerifyIncomingMessage(message);
            }
            else
            {
                VerifyOutgoingMessage(message);
            }
            return message;
        }