Ejemplo n.º 1
0
        public void TestFilterEventByMinimumSeveritySetting()
        {
            // Set minimum log level to error
            var auditLogSettings = Entity.Get <AuditLogSettings>("tenantAuditLogSettingsInstance", true);

            auditLogSettings.MinAuditLogSeverity_Enum = AuditLogSeverityEnum_Enumeration.AuditLogError;
            auditLogSettings.Save();

            var  entityModelSettings = ConfigurationSettings.GetAuditLogConfigurationSection().EntityModelSettings;
            bool isEnabled           = entityModelSettings.IsEnabled;

            try
            {
                var mockDeleter = new Mock <IAuditLogDeleter>(MockBehavior.Loose);

                // Ensure event log is enabled
                entityModelSettings.IsEnabled = true;
                var entityModelWriter = new AuditLogEntityModelWriter(mockDeleter.Object);

                Guid userName = Guid.NewGuid();

                IAuditLogEntryData auditLogEventData = new AuditLogEntryData(true, "logonAuditLogEntryMetadata", new Dictionary <string, object>
                {
                    { "loggedOnUserName", userName.ToString() }
                });

                entityModelWriter.Write(auditLogEventData);

                // Verify that logon event was not created
                IEnumerable <LogonAuditLogEntry> logonEvents = Entity.GetInstancesOfType <LogonAuditLogEntry>();
                LogonAuditLogEntry logonEvent = logonEvents.FirstOrDefault(l => l.LoggedOnUserName == userName.ToString());

                Assert.IsNull(logonEvent, "The logon event was found");
            }
            finally
            {
                entityModelSettings.IsEnabled = isEnabled;
            }
        }
Ejemplo n.º 2
0
        public void TestWriteAuditLogEntryToEntityModel()
        {
            var  entityModelSettings = ConfigurationSettings.GetAuditLogConfigurationSection().EntityModelSettings;
            bool isEnabled           = entityModelSettings.IsEnabled;

            try
            {
                var mockDeleter = new Mock <IAuditLogDeleter>(MockBehavior.Loose);

                // Ensure event log is enabled
                entityModelSettings.IsEnabled = true;
                var entityModelWriter = new AuditLogEntityModelWriter(mockDeleter.Object);

                string userName = "******" + Guid.NewGuid();

                IAuditLogEntryData auditLogEventData = new AuditLogEntryData(false, "logonAuditLogEntryMetadata", new Dictionary <string, object>
                {
                    { "loggedOnUserName", userName }
                });

                entityModelWriter.Write(auditLogEventData);

                // Verify that logon event was created
                IEnumerable <LogonAuditLogEntry> logonEvents = Entity.GetInstancesOfType <LogonAuditLogEntry>();
                LogonAuditLogEntry logonEvent = logonEvents.FirstOrDefault(l => l.LoggedOnUserName == userName);

                Assert.IsNotNull(logonEvent, "The logon event was not found");
                Assert.AreEqual(auditLogEventData.Success, logonEvent.AuditLogEntrySuccess, "Success is invalid");
                Assert.AreEqual(auditLogEventData.UserName, logonEvent.AuditLogEntryUser, "Name is invalid");
                Assert.AreEqual(auditLogEventData.Message, logonEvent.AuditLogEntryMessage, "Message is invalid");
                Assert.AreEqual(auditLogEventData.CreatedDate, logonEvent.AuditLogEntryCreatedDate, "Created Date is invalid");
                Assert.AreEqual(auditLogEventData.SeverityEnum, logonEvent.AuditLogEntrySeverity_Enum, "Severity is invalid");
            }
            finally
            {
                entityModelSettings.IsEnabled = isEnabled;
            }
        }