private void SetPolicyTestSettings(SmtpAgentSettings settings)
        {
            settings.InternalMessage.EnableRelay          = true;
            settings.Notifications.AutoResponse           = true;
            settings.Notifications.AlwaysAck              = true;
            settings.Notifications.AutoDsnFailureCreation =
                NotificationSettings.AutoDsnOption.Always.ToString();

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

            settings.MdnMonitor = mockMdnClientSettings.Object;
        }
Пример #2
0
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_TimelyAndReliable_missingRequest()
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay          = true;
            m_agent.Settings.Notifications.AutoResponse           = true;
            m_agent.Settings.Notifications.AlwaysAck              = true;
            m_agent.Settings.Notifications.AutoDsnFailureCreation =
                NotificationSettings.AutoDsnOption.TimelyAndReliable.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.False(foundDsn);

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
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;
        }