コード例 #1
0
        public void validLogRequestDTO()
        {
            newLog = new LogRequestDTO(DTO.Constants.Constants.Sources.AdminDashboard, newUser.Id.ToString(), newSession.CreatedAt,
                                       newSession.ExpiresAt, newSession.UpdatedAt, newSession.Token);
            newLog = (LogRequestDTO)_tu.getLogContent(newLog); //Valid after initalization and retrieving auth contents

            Assert.IsTrue(newLog.isValid());
        }
コード例 #2
0
        public void invalidLogRequestDTO()
        {
            newLog         = new LogRequestDTO();
            newLog.details = "Test details";
            newLog.setSource(DTO.Constants.Constants.Sources.Session);
            newLog = (LogRequestDTO)_tu.getLogContent(newLog);

            Assert.IsFalse(newLog.isValid()); //No userId
        }
コード例 #3
0
        public void sendLogSyncFail()
        {
            newLog = new LogRequestDTO();
            newLog.setSource(DTO.Constants.Constants.Sources.Logout);
            Assert.IsFalse(logger.sendLogSync(newLog));//Missing userId

            newLog           = new LogRequestDTO();
            newLog.ssoUserId = newUser.Id.ToString();
            Assert.IsFalse(logger.sendLogSync(newLog)); //Missing source
        }
コード例 #4
0
        public async Task LogAsyncResponse401()
        {
            newLog                  = new LogRequestDTO(); //Missing signature, timestamp and salt
            newLog.details          = "testing stacktrace";
            newLog.ssoUserId        = newUser.Id.ToString();
            newLog.sessionCreatedAt = newSession.CreatedAt;
            newLog.sessionExpiredAt = newSession.ExpiresAt;
            newLog.sessionUpdatedAt = newSession.UpdatedAt;
            newLog.token            = newSession.Token;
            var responseStatus = await _ls.sendLogAsync(newLog);

            Assert.AreEqual(responseStatus, System.Net.HttpStatusCode.Unauthorized);
        }
コード例 #5
0
        public async Task sendLogAsyncFail()
        {
            newLog = new LogRequestDTO();
            newLog.setSource(DTO.Constants.Constants.Sources.Logout);
            Assert.IsFalse(logger.sendLogSync(newLog));
            Assert.IsFalse(await logger.sendLogAsync(newLog)); //Missing UserId


            newLog           = new LogRequestDTO();
            newLog.ssoUserId = newUser.Id.ToString();
            Assert.IsFalse(logger.sendLogSync(newLog));
            Assert.IsFalse(await logger.sendLogAsync(newLog)); //Missing Source
        }
コード例 #6
0
        public void SendAnalytics()
        {
            LogRequestDTO  newLog = new LogRequestDTO();
            LoggingService _ls    = new LoggingService();

            newLog.setSource(DTO.Constants.Constants.Sources.Session);
            newLog.details = "testing stacktrace";
            Random rand = new Random();

            for (var i = 0; i < 20; i++)
            {
                User    newUser    = CreateUserObject();
                Session newSession = CreateSessionObject(newUser);
                CreateSessionInDb(newSession);
                newLog.ssoUserId = newUser.Id.ToString();
                newLog.setPage(DTO.Constants.Constants.Pages.PointDetails);
                for (var j = 0; j < 3; j++)
                {
                    var month = rand.Next(8, 12);
                    newLog.logCreatedAt = new DateTime(2018, 12, 21);
                    newLog.setSource(DTO.Constants.Constants.Sources.Login);
                    var pageDuration = rand.Next(1, 600);
                    newLog.pageDuration = pageDuration;
                    if (j == 0)
                    {
                        newLog.setSource(DTO.Constants.Constants.Sources.Registration);
                        newLog.setPage(DTO.Constants.Constants.Pages.MapView);
                    }
                    var duration = rand.Next(1, 1000);
                    if (duration < 300)
                    {
                        newLog.setPage(DTO.Constants.Constants.Pages.AdminDashboard);
                    }
                    else if (duration < 500)
                    {
                        newLog.setPage(DTO.Constants.Constants.Pages.PointDetails);
                    }
                    else if (duration < 700)
                    {
                        newLog.setPage(DTO.Constants.Constants.Pages.PointEditor);
                    }

                    newLog.sessionCreatedAt = newSession.CreatedAt;
                    newLog.sessionExpiredAt = newSession.ExpiresAt.AddSeconds(duration);
                    newLog.sessionUpdatedAt = newSession.UpdatedAt.AddSeconds(duration);
                    newLog.token            = newSession.Token;
                    newLog = (LogRequestDTO)getLogContent(newLog);
                    _ls.sendLogSync(newLog);
                }
            }
        }
コード例 #7
0
        public async Task LogAsyncResponse400()
        {
            newLog                  = new LogRequestDTO(); //Missing Required Source field
            newLog.details          = "testing stacktrace";
            newLog.ssoUserId        = newUser.Id.ToString();
            newLog.sessionCreatedAt = newSession.CreatedAt;
            newLog.sessionExpiredAt = newSession.ExpiresAt;
            newLog.sessionUpdatedAt = newSession.UpdatedAt;
            newLog.token            = newSession.Token;
            newLog                  = (LogRequestDTO)_tu.getLogContent(newLog); //[signature, timestamp]
            var responseStatus = await _ls.sendLogAsync(newLog);

            Assert.AreEqual(responseStatus, System.Net.HttpStatusCode.BadRequest);
        }
コード例 #8
0
        public void LogSyncResponse401()
        {
            newLog = new LogRequestDTO();
            newLog.setSource(DTO.Constants.Constants.Sources.AdminDashboard);
            newLog.details          = "testing stacktrace";
            newLog.ssoUserId        = newUser.Id.ToString();
            newLog.sessionCreatedAt = newSession.CreatedAt;
            newLog.sessionExpiredAt = newSession.ExpiresAt;
            newLog.sessionUpdatedAt = newSession.UpdatedAt;
            newLog.token            = newSession.Token; //Missing signature and timestamp
            var responseStatus = _ls.sendLogSync(newLog);

            Assert.AreEqual(responseStatus, System.Net.HttpStatusCode.Unauthorized);
        }
コード例 #9
0
        public void LogSyncResponse200()
        {
            newLog = new LogRequestDTO();
            newLog.setSource(DTO.Constants.Constants.Sources.AdminDashboard);
            newLog.details          = "testing stacktrace";
            newLog.ssoUserId        = newUser.Id.ToString();
            newLog.sessionCreatedAt = newSession.CreatedAt;
            newLog.sessionExpiredAt = newSession.ExpiresAt;
            newLog.sessionUpdatedAt = newSession.UpdatedAt;
            newLog.token            = newSession.Token;
            newLog = (LogRequestDTO)_tu.getLogContent(newLog);
            var responseStatus = _ls.sendLogSync(newLog);

            Assert.AreEqual(responseStatus, System.Net.HttpStatusCode.OK);
        }
コード例 #10
0
        public void dontNotifySystemAdmin()
        {
            newLog = new LogRequestDTO();
            newLog.setSource(DTO.Constants.Constants.Sources.AdminDashboard);
            newLog.details          = "testing stacktrace";
            newLog.ssoUserId        = newUser.Id.ToString();
            newLog.sessionCreatedAt = newSession.CreatedAt;
            newLog.sessionExpiredAt = newSession.ExpiresAt;
            newLog.sessionUpdatedAt = newSession.UpdatedAt;
            newLog.token            = newSession.Token;
            newLog = (LogRequestDTO)_tu.getLogContent(newLog); //[signature, timestamp]
            var  content       = _ls.getLogContent(newLog);
            bool adminNotified = _ls.notifyAdmin(System.Net.HttpStatusCode.OK, content);

            Assert.IsTrue(adminNotified);
        }
コード例 #11
0
        public IHttpActionResult LogWebpageUsage(LogWebpageUsageRequest payload)
        {
            try
            {
                // Throws SessionNotFound
                //var session = ControllerHelpers.ValidateSession(Request);
                var isValidPage = Enum.IsDefined(typeof(Constants.Pages), payload.Page);
                if (!isValidPage)
                {
                    return(Content(HttpStatusCode.PreconditionFailed, "Webpage is not valid."));
                }

                var session = ControllerHelpers.ValidateAndUpdateSession(Request);
                newLog = new LogRequestDTO(Constants.Sources.Analytics, session.UserId.ToString(), session.CreatedAt, session.UpdatedAt,
                                           session.ExpiresAt, session.Token);
                Constants.Pages page;
                Enum.TryParse(payload.Page, out page);
                newLog.setPage(page);
                newLog.pageDuration = payload.GetDuration();
                logger.sendLogAsync(newLog);

                return(Ok("Webpage (" + payload.Page + ") usage has been logged."));
            }
            catch (Exception e) when(e is NoTokenProvidedException ||
                                     e is SessionNotFoundException)
            {
                return(Content(HttpStatusCode.Unauthorized, e.Message));
            }
            catch (Exception e) when(e is ArgumentException)
            {
                return(Content(HttpStatusCode.PreconditionFailed, e.Message));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, e.Message));
            }
        }
コード例 #12
0
 public void sendLogSyncPass()
 {
     newLog = new LogRequestDTO(DTO.Constants.Constants.Sources.AdminDashboard, newUser.Id.ToString(), newSession.CreatedAt,
                                newSession.ExpiresAt, newSession.UpdatedAt, newSession.Token);
     Assert.IsTrue(logger.sendLogSync(newLog));
 }