Пример #1
0
        public void ReadFilteredAuditEventsWithoutReader()
        {
            manager.Initialise();
            List <AuditRecord> actual = manager.ReadAuditRecords(0, 100, AuditFilters.ByProject("Project #1"));

            Assert.AreEqual(0, actual.Count);
        }
        public void ToStringSerialisesAllValues()
        {
            ReadAuditRequest request = new ReadAuditRequest();

            request.Identifier      = "identifier";
            request.StartRecord     = 10;
            request.NumberOfRecords = 20;
            request.Filter          = AuditFilters.ByProject("testing");
            request.ServerName      = "serverName";
            request.SessionToken    = "sessionToken";
            request.SourceName      = "sourceName";
            request.Timestamp       = DateTime.Now;
            string actual   = request.ToString();
            string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<readAuditMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
                                            "timestamp=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" server=\"{1}\" source=\"{2}\" session=\"{3}\" start=\"{5}\" number=\"{6}\">" +
                                            "<filter xsi:type=\"ProjectAuditFilter\" project=\"testing\" />" +
                                            "</readAuditMessage>",
                                            request.Identifier,
                                            request.ServerName,
                                            request.SourceName,
                                            request.SessionToken,
                                            request.Timestamp,
                                            request.StartRecord,
                                            request.NumberOfRecords);

            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void ByProject()
        {
            AuditFilterBase filter = AuditFilters.ByProject("Project #1");

            Assert.IsTrue(filter.CheckFilter(record1), "Project not included");
            Assert.IsFalse(filter.CheckFilter(record2), "Project not excluded");
        }
Пример #4
0
        private IResponse GenerateAuditHistory(ICruiseRequest request)
        {
            var velocityContext = new Hashtable();
            var links           = new List <IAbsoluteLink>();

            links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "Server", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());

            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerAuditHistoryServerPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            string sessionToken = request.RetrieveSessionToken(sessionRetriever);

            if (!string.IsNullOrEmpty(request.ProjectName))
            {
                velocityContext["currentProject"] = request.ProjectName;
                AuditFilterBase filter = AuditFilters.ByProject(request.ProjectName);
                velocityContext["auditHistory"] = farmService.ReadAuditRecords(request.ServerSpecifier, sessionToken, 0, 100, filter);
            }
            else
            {
                velocityContext["auditHistory"] = new ServerLink(request.UrlBuilder, request.ServerSpecifier, string.Empty, DiagnosticsActionName);
                velocityContext["auditHistory"] = farmService.ReadAuditRecords(request.ServerSpecifier, sessionToken, 0, 100);
            }

            return(viewGenerator.GenerateView(@"AuditHistory.vm", velocityContext));
        }
Пример #5
0
        public void ByProjectAndRight()
        {
            AuditFilterBase filter = AuditFilters.ByProject("Project #1")
                                     .ByRight(SecurityRight.Allow);

            Assert.IsTrue(filter.CheckFilter(record1), "SecurityRight not included");
            Assert.IsFalse(filter.CheckFilter(record3), "SecurityRight not excluded");
        }
Пример #6
0
        public void ByProjectAndEventType()
        {
            AuditFilterBase filter = AuditFilters.ByProject("Project #1")
                                     .ByEventType(SecurityEvent.ViewAuditLog);

            Assert.IsTrue(filter.CheckFilter(record1), "SecurityEvent not included");
            Assert.IsFalse(filter.CheckFilter(record3), "SecurityEvent not excluded");
        }
Пример #7
0
        public void ByProjectAndDateRange()
        {
            AuditFilterBase filter = AuditFilters.ByProject("Project #1")
                                     .ByDateRange(DateTime.Today.AddDays(-2), DateTime.Today);

            Assert.IsTrue(filter.CheckFilter(record1), "Date/Time not included");
            Assert.IsFalse(filter.CheckFilter(record3), "Date/Time not excluded");
        }
Пример #8
0
        public void Combined()
        {
            AuditFilterBase filter = AuditFilters.Combine(
                AuditFilters.ByProject("Project #1"),
                AuditFilters.ByUser("User #2"));

            Assert.IsTrue(filter.CheckFilter(record1), "Project not included");
            Assert.IsTrue(filter.CheckFilter(record2), "Project not included");
            Assert.IsFalse(filter.CheckFilter(record3), "Project not excluded");
        }
Пример #9
0
        public void ReadAuditRecordsWithFilter()
        {
            ReadAuditResponse response = new ReadAuditResponse();

            response.Result = ResponseResult.Success;
            CruiseServerClient client = new CruiseServerClient(
                new ServerStub("ReadAuditRecords", typeof(ReadAuditRequest), null, response));
            AuditFilterBase filter = AuditFilters.ByProject("Project #1");

            client.ReadAuditRecords(0, 10, filter);
        }
Пример #10
0
        public void ReadFilteredAuditEventsWithReader()
        {
            AuditFilterBase    filter     = AuditFilters.ByProject("Project #1");
            IAuditReader       readerMock = mocks.Create <IAuditReader>().Object;
            List <AuditRecord> records    = new List <AuditRecord>();

            records.Add(new AuditRecord());
            Mock.Get(readerMock).Setup(_readerMock => _readerMock.Read(0, 100, filter)).Returns(records);
            manager.AuditReader = readerMock;
            manager.Initialise();
            List <AuditRecord> actual = manager.ReadAuditRecords(0, 100, filter);

            Assert.AreEqual(1, actual.Count);
        }
        public void ReadFilteredAuditEventsWithReader()
        {
            AuditFilterBase    filter     = AuditFilters.ByProject("Project #1");
            IAuditReader       readerMock = mocks.DynamicMock <IAuditReader>();
            List <AuditRecord> records    = new List <AuditRecord>();

            records.Add(new AuditRecord());
            SetupResult.For(readerMock.Read(0, 100, filter)).Return(records);
            manager.AuditReader = readerMock;
            mocks.ReplayAll();
            manager.Initialise();
            List <AuditRecord> actual = manager.ReadAuditRecords(0, 100, filter);

            Assert.AreEqual(1, actual.Count);
        }