コード例 #1
0
ファイル: TestTimeOut.cs プロジェクト: ywangmaxmd/nhin-d
        public void TestDispatchedTimeOutToDSNFail()
        {
            //
            // Sample data
            //
            MdnManager target = CreateManager();

            InitMdnRecords();
            CleanMessages(PickupFolder);

            //timespan and max records set
            var mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);

            Assert.Equal(10, mdns.Count());

            MdnDispatchedTimeout dispatchedTimeout = new MdnDispatchedTimeout();

            //Execute unprocessed records over 11 minutes old.
            JobExecutionContext context = CreateDispatchedJobExecutionContext(11, 5);

            dispatchedTimeout.Execute(context);

            //Nothing was processed
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(10, mdns.Count());

            var files = Directory.GetFiles(PickupFolder);

            Assert.Equal(0, files.Count());

            //Execute unprocessed records over 10 minutes old.
            context = CreateDispatchedJobExecutionContext(10, 5);
            dispatchedTimeout.Execute(context);

            //10 records left
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(5, mdns.Count());

            files = Directory.GetFiles(PickupFolder);
            Assert.Equal(5, files.Count());

            //Do it again
            dispatchedTimeout.Execute(context);
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(0, mdns.Count());

            files = Directory.GetFiles(PickupFolder);
            Assert.Equal(10, files.Count());

            foreach (var file in files)
            {
                Message loadedMessage = Message.Load(File.ReadAllText(file));
                Assert.True(loadedMessage.IsDSN());
                Assert.Equal("multipart/report", loadedMessage.ParsedContentType.MediaType);
                Assert.Equal("Rejected:To dispatch or not dispatch", loadedMessage.SubjectValue);
                var dsnActual = DSNParser.Parse(loadedMessage);
                Assert.Equal(DSNStandard.DSNAction.Failed, dsnActual.PerRecipient.First().Action);
                Assert.Equal("5.4.72", dsnActual.PerRecipient.First().Status);
            }
        }
コード例 #2
0
ファイル: TestDSN.cs プロジェクト: nagyistge/nhin-d.net35
        public void TestFailedDeliveryStatusSerialization()
        {
            Message source = this.CreateSourceMessage();

            DSN        dsnExpected = this.CreateFailedStatusNotification(3);
            DSNMessage dsnMessage  = source.CreateStatusMessage(new MailAddress(Postmaster), dsnExpected);

            Console.WriteLine(dsnMessage);
            var path = Path.GetTempFileName();

            try
            {
                dsnMessage.Save(path);
                Message loadedMessage = Message.Load(File.ReadAllText(path));
                Assert.True(loadedMessage.IsDSN());
                Assert.Equal(dsnMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
                Assert.Equal(dsnMessage.SubjectValue, loadedMessage.SubjectValue);
                Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
                Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
                Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);
                var dsnActual = DSNParser.Parse(loadedMessage);

                VerifyEqual(dsnExpected, dsnActual);
            }
            finally
            {
                File.Delete(path);
            }
        }
コード例 #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.
            //
            //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;
        }
コード例 #4
0
ファイル: TestDSN.cs プロジェクト: nagyistge/nhin-d.net35
        public void TestDSNDeserialization()
        {
            string dsnMessage =
                @"MIME-Version:1.0
To:[email protected]
From:[email protected]
Content-Type:multipart/report; boundary=8bacf4b73bef45f2a4f481c20c00e664; report-type=delivery-status
Message-ID:d6bff591-598c-4b20-ac6a-25da27f4918c
Subject:Rejected:Sound Grenade
Date:31 Oct 2012 14:00:52 -07:00


--8bacf4b73bef45f2a4f481c20c00e664
Content-Type:text/plain

Delivery Status Notification
--8bacf4b73bef45f2a4f481c20c00e664
Content-Type:message/delivery-status

Reporting-MTA: dns;reporting_mta_name
X-Original-Message-ID: Message In a Bottle

Final-Recipient: rfc822;[email protected]
Action: failed
Status: 5.0.0

Original-Recipient: rfc822;[email protected]
Final-Recipient: rfc822;[email protected]
Action: failed
Status: 5.0.0 (permanent failure)
Diagnostic-Code: smtp;  550 '*****@*****.**' is not a 
 registered gateway user
Remote-MTA: dns; vnet.ibm.com

Final-Recipient: rfc822;[email protected]
Action: failed
Status: 5.0.0

--8bacf4b73bef45f2a4f481c20c00e664--

";
            Message loadedMessage = Message.Load(dsnMessage);

            Console.WriteLine(loadedMessage);

            Assert.True(loadedMessage.IsDSN());
            Assert.Equal(loadedMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
            Assert.Equal(loadedMessage.SubjectValue, loadedMessage.SubjectValue);
            Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
            Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
            Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);
            var dsnActual  = DSNParser.Parse(loadedMessage);
            var recipients = dsnActual.PerRecipient.ToList();

            Assert.Equal("smtp;  550 '*****@*****.**' is not a registered gateway user",
                         recipients[1].OtherFields.GetValue(DSNStandard.Fields.DiagnosticCode));
        }
コード例 #5
0
ファイル: TestDSN.cs プロジェクト: nagyistge/nhin-d.net35
        /// <summary>
        /// Verify Disposition-Type MDN notification
        /// </summary>
        void VerifyDSNHeaders(MimeEntity notificationEntity, DSN notification)
        {
            HeaderCollection fields = DSNParser.ParseDSNFields(notificationEntity);

            Assert.NotEmpty(fields);
            //
            // perMessage
            //
            Assert.True(fields.HasHeader(DSNStandard.Fields.ReportingMTA, "dns;" + ReportingMtaName));
            Assert.True(fields.HasHeader(DSNStandard.Fields.OriginalMessageID, OriginalID));

            //
            // perRecipient
            //
            Assert.True(fields.HasHeader(DSNStandard.Fields.FinalRecipient,
                                         "rfc822;" + notification.PerRecipient.First().FinalRecipient.Address));
            Assert.True(fields.HasHeader(DSNStandard.Fields.Action, "failed"));
            Assert.True(fields.HasHeader(DSNStandard.Fields.Status, "5.0.0"));
        }
コード例 #6
0
ファイル: TestSmtpAgentDSNs.cs プロジェクト: ssavarala/nhin-d
        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;
        }
コード例 #7
0
ファイル: TestSmtpAgentDSNs.cs プロジェクト: ssavarala/nhin-d
        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;
        }