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

            SimpleComponentSettings[] components = new SimpleComponentSettings[2];

            //
            // Retain configured
            //
            components[0] = settings.Container.Components[0];

            //
            // Add a second auditor
            //
            SimpleComponentSettings localAuditComponent = new SimpleComponentSettings();

            localAuditComponent.Scope   = InstanceScope.Singleton;
            localAuditComponent.Service = "Health.Direct.SmtpAgent.Diagnostics.IAuditor`1[[Health.Direct.SmtpAgent.Diagnostics.IBuildAuditLogMessage, Health.Direct.SmtpAgent]], Health.Direct.SmtpAgent";
            localAuditComponent.Type    = "Health.Direct.SmtpAgent.Tests.LocalTestAuditor`1[[Health.Direct.SmtpAgent.Tests.LocalBuildAuditLogMessage, Health.Direct.SmtpAgent.Tests]], Health.Direct.SmtpAgent.Tests";
            components[1] = localAuditComponent;

            settings.Container.Components = components;
            m_agent = SmtpAgentFactory.Create(settings);

            Assert.True(IoC.Resolve <IAuditor <IBuildAuditLogMessage> >() != null);
            Assert.Equal(0, AuditEventCount);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid())))));
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(CrossDomainMessage))));
            m_agent.Settings.InternalMessage.EnableRelay = false;
            Assert.Equal(8, AuditEventCount);
        }
Ejemplo n.º 2
0
        public void Test_DatabaseAuditor_HeaderAuditMessageBuilder()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentAuditConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            SimpleComponentSettings[] components = new SimpleComponentSettings[1];


            SimpleComponentSettings localAuditComponent = new SimpleComponentSettings();

            localAuditComponent.Scope   = InstanceScope.Singleton;
            localAuditComponent.Service = "Health.Direct.SmtpAgent.Diagnostics.IAuditor`1[[Health.Direct.SmtpAgent.Diagnostics.IBuildAuditLogMessage, Health.Direct.SmtpAgent]], Health.Direct.SmtpAgent";
            localAuditComponent.Type    = "Health.Direct.DatabaseAuditor.Auditor`1[[Health.Direct.DatabaseAuditor.HeaderAuditMessageBuilder, Health.Direct.DatabaseAuditor]], Health.Direct.DatabaseAuditor";
            components[0] = localAuditComponent;

            settings.Container.Components = components;
            m_agent = SmtpAgentFactory.Create(settings);
            Assert.True(IoC.Resolve <IAuditor <IBuildAuditLogMessage> >() is DatabaseAuditor.Auditor <HeaderAuditMessageBuilder>);

            Assert.Equal(0, AuditEventCount);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid())))));
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(CrossDomainMessage))));
            m_agent.Settings.InternalMessage.EnableRelay = false;
            Assert.Equal(4, AuditEventCount);

            using (var db = new AuditContext().CreateContext(m_settings))
            {
                foreach (AuditEvent auditEvent in db.AuditEvents)
                {
                    Console.WriteLine(auditEvent.Message);
                }
            }
        }
Ejemplo n.º 3
0
        public void Test_LocalAuditorSettings()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentAuditConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            SimpleComponentSettings[] components = new SimpleComponentSettings[1];


            SimpleComponentSettings localAuditComponent = new SimpleComponentSettings();

            localAuditComponent.Scope   = InstanceScope.Singleton;
            localAuditComponent.Service = "Health.Direct.SmtpAgent.Diagnostics.IAuditor`1[[Health.Direct.SmtpAgent.Diagnostics.IBuildAuditLogMessage, Health.Direct.SmtpAgent]], Health.Direct.SmtpAgent";
            localAuditComponent.Type    = "Health.Direct.SmtpAgent.Tests.LocalTestAuditor`1[[Health.Direct.SmtpAgent.Tests.LocalBuildAuditLogMessage, Health.Direct.SmtpAgent.Tests]], Health.Direct.SmtpAgent.Tests";
            components[0] = localAuditComponent;

            settings.Container.Components = components;
            m_agent = SmtpAgentFactory.Create(settings);
            Assert.True(IoC.Resolve <IAuditor <IBuildAuditLogMessage> >() is LocalTestAuditor <LocalBuildAuditLogMessage>);

            Assert.Equal(0, AuditEventCount);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            Assert.DoesNotThrow(() => RunEndToEndTest(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid()))));
            Assert.DoesNotThrow(() => RunEndToEndTest(this.LoadMessage(CrossDomainMessage)));
            m_agent.Settings.InternalMessage.EnableRelay = false;
            Assert.Equal(4, AuditEventCount);
        }
Ejemplo n.º 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));
                }
            }
        }
Ejemplo n.º 5
0
        public void TestFilterCertificateByPolicy_nullResolver_assertNoCertsFiltered()
        {
            SmtpAgent m_agent = SmtpAgentFactory.Create(GetSettingsPath("TestSmtpAgentConfigWithCertPolicy.xml"));

            m_agent.Settings.InternalMessage.EnableRelay = true;
            CleanMessages(m_agent.Settings);
            CleanMonitor();

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

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

            //
            // 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), m_agent)));
                }
            }
            Assert.True(foundMdns);
        }
Ejemplo n.º 6
0
        public void TestFilterCertificateByPolicy_trust_badPolicyThrow_assertNoCertsFiltered()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            CleanMessages(settings);
            CleanMonitor();

            SetPolicyTestSettings(settings);

            //
            // Mock all policy resolvers
            //
            Mock <PrivatePolicyResolver> mockPrivatePolicyResolver;
            Mock <PublicPolicyResolver>  mockPublicPolicyResolver;
            Mock <TrustPolicyResolver>   mockTrustPolicyResolver;
            Mock <IPolicyFilter>         mockPolicyFilter;

            MockPolicyResolvers(settings, out mockPrivatePolicyResolver, out mockPublicPolicyResolver, out mockTrustPolicyResolver, out mockPolicyFilter);

            Mock <IPolicyExpression> policyExpression = new Mock <IPolicyExpression>();

            mockTrustPolicyResolver.Setup(r => r.GetIncomingPolicy(It.IsAny <MailAddress>()))
            .Returns(new List <IPolicyExpression>()
            {
                policyExpression.Object
            });
            mockPolicyFilter.Setup(r => r.IsCompliant(It.IsAny <X509Certificate2>(), It.IsAny <IPolicyExpression>()))
            .Throws <PolicyRequiredException>();
            ;

            SmtpAgent smtpAgent = SmtpAgentFactory.Create(settings);


            //
            // Process loopback messages.  Leaves message in bad message 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(TestMessage);

            Assert.Throws <AgentException>(() => RunEndToEndTest(sendingMessage, smtpAgent));

            Assert.Equal(1, BadMessages().Count());


            mockPrivatePolicyResolver.Verify(r => r.GetOutgoingPolicy(new MailAddress("*****@*****.**"))
                                             , Times.Exactly(1));

            mockPolicyFilter.Verify(c => c.IsCompliant(It.IsAny <X509Certificate2>(), It.IsAny <IPolicyExpression>()),
                                    Times.Exactly(2));

            //
            // These two are never called.  These code paths do not exist.
            //
            mockPublicPolicyResolver.Verify(r => r.GetIncomingPolicy(It.IsAny <MailAddress>()), Times.Never());
            mockTrustPolicyResolver.Verify(r => r.GetOutgoingPolicy(It.IsAny <MailAddress>()), Times.Never());
        }
Ejemplo n.º 7
0
        public void TestFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentConfigWithCertPolicy.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            CleanMessages(settings);
            CleanMonitor();

            SetPolicyTestSettings(settings);

            //
            // Mock all policy resolvers
            //
            Mock <PrivatePolicyResolver> mockPrivatePolicyResolver;
            Mock <PublicPolicyResolver>  mockPublicPolicyResolver;
            Mock <TrustPolicyResolver>   mockTrustPolicyResolver;
            Mock <IPolicyFilter>         mockPolicyFilter;

            MockPolicyResolvers(settings, out mockPrivatePolicyResolver, out mockPublicPolicyResolver, out mockTrustPolicyResolver, out mockPolicyFilter);

            SmtpAgent smtpAgent = SmtpAgentFactory.Create(settings);

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

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

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

            mockPrivatePolicyResolver.Verify(r => r.GetIncomingPolicy(new MailAddress("*****@*****.**"))
                                             , Times.Exactly(1));
            mockPrivatePolicyResolver.Verify(r => r.GetIncomingPolicy(new MailAddress("*****@*****.**"))
                                             , Times.Exactly(1));
            mockPolicyFilter.Verify(p => p.IsCompliant(It.IsAny <X509Certificate2>(), It.IsAny <IPolicyExpression>()), Times.Exactly(0));
            //
            // These two are never called.  These code paths do not exist.
            //
            mockPublicPolicyResolver.Verify(r => r.GetIncomingPolicy(It.IsAny <MailAddress>()), Times.Never());
            mockTrustPolicyResolver.Verify(r => r.GetOutgoingPolicy(It.IsAny <MailAddress>()), Times.Never());
        }
Ejemplo n.º 8
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)));
        }
Ejemplo n.º 9
0
        public void StartAgent(string[] args)
        {
            if (m_agent != null)
            {
                return;
            }

            string configFile = args.GetRequiredValue(0);

            m_agent = SmtpAgentFactory.Create(configFile);
        }
Ejemplo n.º 10
0
        public void TestBadlyFormedSmtpAgentSettings()
        {
            var agent     = SmtpAgentFactory.Create(GetSettingsPath("TestSmtpAgentConfigBadlyFormed.xml"));
            var messageId = Guid.NewGuid();

            Assert.Throws <SmtpAgentSettingsException>(() => agent.ProcessMessage(LoadMessage(string.Format(TestMessage, messageId))));

            Assert.True(FileMessages(SettingsInitializer.BadmailFolder)
                        .Select(File.ReadAllText)
                        .Any(m => m.Contains(messageId.ToString())));
        }
Ejemplo n.º 11
0
        public void TestUnavailableTokenSettingsOutgoing()
        {
            var agent     = SmtpAgentFactory.Create(GetSettingsPath("TestSmtpAgentConfigService_HsmCryptographerBadUrl.xml"));
            var messageId = Guid.NewGuid();
            var message   = LoadMessage(string.Format(TestMessageDualToHsm, messageId));

            Assert.Throws <SmtpAgentSettingsException>(() => agent.ProcessMessage(message));

            Assert.True(FileMessages(agent.Settings.BadMessage.CopyFolder)
                        .Select(File.ReadAllText)
                        .Any(m => m.Contains(messageId.ToString())));
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public void TestEndToEndInternalMessage()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentAuditConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            m_agent = SmtpAgentFactory.Create(settings);

            Assert.True(IoC.Resolve <IAuditor <IBuildAuditLogMessage> >() != null);
            Assert.Equal(0, AuditEventCount);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid())))));
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(CrossDomainMessage))));
            m_agent.Settings.InternalMessage.EnableRelay = false;
            Assert.Equal(4, AuditEventCount);
        }
Ejemplo n.º 14
0
        public void TestBad_DatabaseAuditorSettings()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentAuditConfig_BadAuditor_Defaults.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            m_agent = SmtpAgentFactory.Create(settings);

            Assert.Equal(0, AuditEventCount);
            m_agent.Settings.InternalMessage.EnableRelay = true;
            //
            // Failes to load DatabaseAuditor.Auditor and defaults to EventLogAuditor
            //
            Assert.True(IoC.Resolve <IAuditor <IBuildAuditLogMessage> >() is SmtpAgentEventLogAuditor);
            Assert.Null(Record.Exception(() => RunEndToEndTest(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid())))));
            m_agent.Settings.InternalMessage.EnableRelay = false;
            Assert.Equal(0, AuditEventCount);
        }
Ejemplo n.º 15
0
        public void TestContainer()
        {
            SmtpAgentSettings settings = null;

            Assert.DoesNotThrow(() => settings = SmtpAgentSettings.LoadSettings(Fullpath("TestPlugin.xml")));
            Assert.NotNull(settings.Container);
            Assert.True(settings.Container.HasComponents);

            ResetSmtpAgentFactory();
            SmtpAgent agent = SmtpAgentFactory.Create(Fullpath("TestPlugin.xml"));

            ILogFactory logFactory = null;

            Assert.DoesNotThrow(() => logFactory = IoC.Resolve <ILogFactory>());

            IAuditor auditor = null;

            Assert.DoesNotThrow(() => auditor = IoC.Resolve <IAuditor>());
            Assert.True(auditor is DummyAuditor);
        }
Ejemplo n.º 16
0
        public void TestMissing_DatabaseAuditorSettings()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentAuditConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            SimpleComponentSettings[]      components         = new SimpleComponentSettings[1];
            Mock <SimpleComponentSettings> auditComponentMock = new Mock <SimpleComponentSettings>()
            {
                CallBase = true
            };

            auditComponentMock.SetupAllProperties();
            components[0]                 = auditComponentMock.Object;
            components[0].Scope           = InstanceScope.Singleton;
            components[0].Service         = "Health.Direct.SmtpAgent.Diagnostics.IAuditor`1[[Health.Direct.SmtpAgent.Diagnostics.IBuildAuditLogMessage, Health.Direct.SmtpAgent]], Health.Direct.SmtpAgent";
            components[0].Type            = "Health.Direct.SmtpAgent.Tests.LocalTestAuditorSettingsMissing`1[[Health.Direct.SmtpAgent.Tests.LocalBuildAuditLogMessage, Health.Direct.SmtpAgent.Tests]], Health.Direct.SmtpAgent.Tests";
            settings.Container.Components = components;


            m_agent = SmtpAgentFactory.Create(settings);

            //
            // Not really asserting the exception.  It would take some architecture changes to get the IoC in a more testable state.
            //
            auditComponentMock.Verify(c => c.CreateInstance(), Times.Once);

            Assert.Equal(0, AuditEventCount);
            m_agent.Settings.InternalMessage.EnableRelay = true;

            //
            // Failes to find connection string info in DatabaseAuditorSettings.xml file so loads default EventLogAuditor
            //
            Assert.True(IoC.Resolve <IAuditor <IBuildAuditLogMessage> >() is SmtpAgentEventLogAuditor);
            Assert.DoesNotThrow(() => RunEndToEndTest(this.LoadMessage(string.Format(TestMessage, Guid.NewGuid()))));
            m_agent.Settings.InternalMessage.EnableRelay = false;
            Assert.Equal(0, AuditEventCount);
        }
Ejemplo n.º 17
0
 public TestSmtpAgentDSNs()
 {
     m_agent = SmtpAgentFactory.Create(GetSettingsPath("TestSmtpAgentConfig.xml"));
 }
Ejemplo n.º 18
0
 public TestSmtpAgentMdns()
 {
     m_agent = SmtpAgentFactory.Create(GetSettingsPath("TestSmtpAgentConfigService_HsmCryptographer.xml"));
 }
Ejemplo n.º 19
0
 public TestSmtpAgentMDNs()
 {
     //m_agent = SmtpAgentFactory.Create(base.GetSettingsPath("TestSmtpAgentConfigService.xml"));
     //m_agent = SmtpAgentFactory.Create(base.GetSettingsPath("TestSmtpAgentConfigServiceProd.xml"));
     m_agent = SmtpAgentFactory.Create(GetSettingsPath("TestSmtpAgentConfig.xml"));
 }
Ejemplo n.º 20
0
 SmtpAgent LoadAgent(string configFile)
 {
     return(SmtpAgentFactory.Create(GetSettingsPath(configFile)));
 }
Ejemplo n.º 21
0
 public TestNotifications()
 {
     m_agent    = SmtpAgentFactory.Create(MakeFilePath("SmtpAgentTestFiles\\TestSmtpAgentConfig.xml"));
     m_producer = new NotificationProducer(m_agent.Settings.Notifications);
 }