Exemple #1
0
            public override async Task <DbResult <IEnumerable <GuildModerationAuditRecord> > > Handle(GetGuildModerationAuditRecords request, CancellationToken cancellationToken)
            {
                try
                {
                    AuditFilters filter = request.Filter;
                    List <GuildModerationAuditRecord> result = await this.DbContext.GuildModerationAuditRecords
                                                               .Where(record =>
                                                                      record.GuildId == request.Filter.GuildId &&
                                                                      (filter.ModeratorUserId == null || record.ModeratorUserId == filter.ModeratorUserId) &&
                                                                      (filter.UserId == null || record.UserId == filter.UserId) &&
                                                                      (filter.ModerationAction == ModerationActionType.NONE || record.ModerationAction == filter.ModerationAction))
                                                               .ToListAsync(cancellationToken: cancellationToken);

                    return(new DbResult <IEnumerable <GuildModerationAuditRecord> >
                    {
                        Success = true,
                        Value = result,
                    });
                }
                catch (Exception e) when(e is ArgumentNullException or OperationCanceledException)
                {
                    return(new DbResult <IEnumerable <GuildModerationAuditRecord> >
                    {
                        Success = false,
                        Value = null,
                    });
                }
            }
        }
        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);
        }
Exemple #3
0
        public void ByUser()
        {
            AuditFilterBase filter = AuditFilters.ByUser("User #1");

            Assert.IsTrue(filter.CheckFilter(record1), "User not included");
            Assert.IsFalse(filter.CheckFilter(record2), "User not excluded");
        }
Exemple #4
0
        public void ByEventType()
        {
            AuditFilterBase filter = AuditFilters.ByEventType(SecurityEvent.ViewAuditLog);

            Assert.IsTrue(filter.CheckFilter(record1), "SecurityEvent not included");
            Assert.IsFalse(filter.CheckFilter(record2), "SecurityEvent not excluded");
        }
Exemple #5
0
        public void ByRight()
        {
            AuditFilterBase filter = AuditFilters.ByRight(SecurityRight.Allow);

            Assert.IsTrue(filter.CheckFilter(record1), "SecurityRight not included");
            Assert.IsFalse(filter.CheckFilter(record2), "SecurityRight not excluded");
        }
Exemple #6
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");
        }
Exemple #7
0
        public void ByDateRange()
        {
            AuditFilterBase filter = AuditFilters.ByDateRange(DateTime.Today.AddDays(-2), DateTime.Today);

            Assert.IsTrue(filter.CheckFilter(record1), "Date/Time not included");
            Assert.IsFalse(filter.CheckFilter(record2), "Date/Time not excluded");
        }
Exemple #8
0
        public void ReadFilteredAuditEventsWithoutReader()
        {
            manager.Initialise();
            List <AuditRecord> actual = manager.ReadAuditRecords(0, 100, AuditFilters.ByProject("Project #1"));

            Assert.AreEqual(0, actual.Count);
        }
Exemple #9
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));
        }
        public void ReadAuditRecordsWithFilterIsNotImplemented()
        {
            var client = new TestClient();

            Assert.Throws <NotImplementedException>(
                () => client.ReadAuditRecords(0, 10, AuditFilters.ByRight(SecurityRight.Allow)));
        }
        public void ReadSomeFilteredEvents()
        {
            FileXmlReader reader = new FileXmlReader();

            reader.AuditFileLocation = GenerateAuditFile();
            List <AuditRecord> records = reader.Read(0, 1, AuditFilters.ByUser("User #1"));

            Assert.AreEqual(1, records.Count, "Incorrect number of records returned");
        }
Exemple #12
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");
        }
Exemple #13
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);
        }
Exemple #14
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);
        }