コード例 #1
0
        public void GetUserDataTest()
        {
            Users    user     = db.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
            UserData userData = Auth0APIClient.GetUserData(user.Auth0Uid);

            Assert.IsNotNull(userData);
        }
コード例 #2
0
        /// <summary>
        /// Posts edited ticket data entry to DataEditor service
        /// </summary>
        /// <param name="td">TicketData instance from edit form</param>
        /// <returns>Index View</returns>
        public async Task <ViewResult> PostEdit(TicketData td)
        {
            try
            {
                Authorize();
            }
            catch (HttpResponseException e)
            {
                return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page")));
            }

            try
            {
                DataEditor de           = new DataEditor();
                UserData   loggedInUser = Auth0APIClient.GetUserData(User.Claims.First().Value);
                de.PostEditor(td, loggedInUser);
                RecordRetriever rr  = new RecordRetriever();
                var             res = rr.RetrieveRecords(1000);
                return(View("Index", res));
            }
            catch (HttpResponseException e)
            {
                ServerErrorViewModel error = await Utility.CreateServerErrorView(e);

                return(View("ServerError", error));
            }
            catch (Exception e)
            {
                var            guid  = ExceptionReporter.DumpException(e);
                ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid);
                return(View("Error", error));
            }
        }
コード例 #3
0
        public void GetUserRole(string auth0id, string shiftType)
        {
            var       result = Auth0APIClient.GetUserRole(auth0id);
            Auth0Role role   = result.ElementAt(0);

            Assert.AreEqual(role.name, shiftType);
        }
コード例 #4
0
        public void DeleteUserTest(string Auth0id)
        {
            bool result = Auth0APIClient.DeleteUser(Auth0id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result);
        }
コード例 #5
0
        /// <summary>
        /// Function to authorize the currently logged in user
        /// </summary>
        /// <returns></returns>
        public bool Authorize()
        {
            try
            {
                var      userId = User.Claims.First().Value;
                UserData ud     = Auth0APIClient.GetUserData(userId);
                List <UserPermission> permissions = Auth0APIClient.GetPermissions(ud.user_id);
                bool authorized = false;

                foreach (UserPermission perm in permissions)
                {
                    if (perm.permission_name == ModelUtility.AccessLevel1 || perm.permission_name == ModelUtility.AccessLevel2)
                    {
                        authorized = true;
                        break;
                    }
                }

                if (authorized == false)
                {
                    throw new HttpResponseException(HttpStatusCode.Unauthorized);
                }

                return(authorized);
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Utility.CreateResponseMessage(e));
            }
        }
コード例 #6
0
        public void FetchRoleTest(string shiftType)
        {
            Auth0Role result = Auth0APIClient.FetchRole(shiftType);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.name, shiftType);
        }
コード例 #7
0
        public void DeleteUserTest(Users user)
        {
            Auth0APIClient.DeleteUser(user.Auth0Uid);
            var actual = um.DeleteUser(user.UserId);

            Assert.IsTrue(actual);
        }
コード例 #8
0
        /// <summary>
        /// Endpoint to create a new user in the database and Auth0
        /// </summary>
        /// <param name="newUser"></param>
        /// <returns></returns>
        public async Task <ViewResult> CreateUser(Users newUser)
        {
            try
            {
                Authorize();
            }
            catch (HttpResponseException e)
            {
                return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page")));
            }
            UserManager um = new UserManager();

            try
            {
                um.CreateUser(newUser, Auth0APIClient.GetUserData(User.Claims.First().Value));
                return(View("UsersHome", um.GetUsers()));
            }
            catch (HttpResponseException e)
            {
                ServerErrorViewModel error = await Utility.CreateServerErrorView(e);

                return(View("ServerError", error));
            }
            catch (Exception e)
            {
                var            guid  = ExceptionReporter.DumpException(e);
                ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid);
                return(View("Error", error));
            }
        }
コード例 #9
0
        public void UpdateDBUserTest()
        {
            using (var db = new TicketingSystemDBContext())
            {
                Users user   = db.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
                var   actual = Auth0APIClient.UpdateDBUser(user.Auth0Uid);

                Assert.IsNotNull(actual);
                Assert.IsTrue(actual);
            }
        }
コード例 #10
0
 public void GetRecordByIDTest()
 {
     using (var context = new TicketingSystemDBContext())
     {
         var       td     = TestUtility.CreateTestData();
         DataEntry de     = new DataEntry();
         Users     dbUser = context.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
         de.PostEntry(td, Auth0APIClient.GetUserData(dbUser.Auth0Uid));
         int             id  = context.TicketData.First().EntryId;
         RecordRetriever rr  = new RecordRetriever();
         var             res = rr.GetRecordByID(id);
         Assert.IsNotNull(res);
         Assert.IsTrue(res.GetType() == typeof(TicketData));
     }
 }
コード例 #11
0
        public void CreateUserTest()
        {
            using (var db = new TicketingSystemDBContext())
            {
                Users newUser = TestUtility.CreateTestUser();

                Users    loggedUser = db.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
                UserData userData   = Auth0APIClient.GetUserData(loggedUser.Auth0Uid);

                bool actual = um.CreateUser(newUser, userData);

                ToggleActivationTest(newUser);
                DeleteUserTest(newUser);

                Assert.IsTrue(actual);
            }
        }
コード例 #12
0
        /// <summary>
        /// Endpoint to delete an entry from the database
        /// </summary>
        /// <param name="entryId"></param>
        /// <returns></returns>
        public async Task <JsonResult> RemoveEntry(string entryId)
        {
            try
            {
                Authorize();
            }
            catch (HttpResponseException e)
            {
                string guid = ExceptionReporter.DumpException(e);
                return(Json(new
                {
                    newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized"))
                }));
            }

            try
            {
                DataEditor de = new DataEditor();
                de.DeleteEntry(entryId, Auth0APIClient.GetUserData(User.Claims.First().Value));

                return(Json(new
                {
                    newUrl = Url.Action("Index", "Edit"),
                    message = "Deleted entry",
                    id = entryId
                }));
            }
            catch (HttpResponseException e)
            {
                string guid = ExceptionReporter.DumpException(e);
                ServerErrorViewModel error = await Utility.CreateServerErrorView(e);

                return(Json(new
                {
                    newUrl = Url.Action("ServerError", error)
                }));
            }
            catch (Exception e)
            {
                string guid = ExceptionReporter.DumpException(e);
                return(Json(new
                {
                    newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid))
                }));
            }
        }
コード例 #13
0
        public void PostEditTest()
        {
            using (var context = new TicketingSystemDBContext())
            {
                TicketData td = TestUtility.CreateTestData();

                DataEditor DaEd   = new DataEditor();
                Users      dbUser = context.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
                UserData   ud     = Auth0APIClient.GetUserData(dbUser.Auth0Uid);

                var result = DaEd.PostEditor(td, ud);

                DeleteEntryTest(td, ud);

                Assert.IsTrue(result);
            }
        }
コード例 #14
0
        /// <summary>
        /// Endpoint to return all the permissions associated with a given user
        /// </summary>
        /// <returns>JSON containing permissions</returns>
        public async Task <JsonResult> Permissions()
        {
            try
            {
                Authorize();
            }
            catch (HttpResponseException e)
            {
                return(Json(new
                {
                    newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized"))
                }));
            }
            try
            {
                var      userId = User.Claims.First().Value;
                UserData ud     = Auth0APIClient.GetUserData(userId);
                List <UserPermission> permissions = Auth0APIClient.GetPermissions(ud.user_id);

                return(Json(new
                {
                    permissions = permissions
                }));
            }
            catch (HttpResponseException e)
            {
                string guid = ExceptionReporter.DumpException(e);
                ServerErrorViewModel error = await Utility.CreateServerErrorView(e);

                return(Json(new
                {
                    newUrl = Url.Action("ServerError", error)
                }));
            }
            catch (Exception e)
            {
                string guid = ExceptionReporter.DumpException(e);
                return(Json(new
                {
                    newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid))
                }));
            }
        }
コード例 #15
0
        public static void UserCleanup()
        {
            UserManager um = new UserManager();

            using (var db = new TicketingSystemDBContext())
            {
                var dbUsers = db.Users.Where(u => u.FullName == "Unit Test User").ToList();
                foreach (Users u in dbUsers)
                {
                    um.DeleteUser(u.UserId);
                }

                var auth0Users = Auth0APIClient.GetAllUsers();
                foreach (var u in auth0Users)
                {
                    if (u.name == "Unit Test User")
                    {
                        Auth0APIClient.DeleteUser(u.user_id);
                    }
                }
            }
        }
コード例 #16
0
        public async Task EditFormTest()
        {
            using (var db = new TicketingSystemDBContext())
            {
                Users user = db.Users.Where(u => u.FullName == "Test User").FirstOrDefault();

                DataEntry de = new DataEntry();
                de.PostEntry(TestUtility.CreateTestData(), Auth0APIClient.GetUserData(user.Auth0Uid));

                TicketData td = db.TicketData.Where(t => t.EntryAuthorId == user.UserId).FirstOrDefault();
                td.JobType = db.JobType.Where(jt => jt.JobTypeId == td.JobTypeId).FirstOrDefault();

                ViewResult result = await ec.EditForm(td);

                ViewResult testView = View("EditForm", td);

                await PostEditorTest(td);

                Assert.IsNotNull(result);
                Assert.AreEqual(testView.ViewName, result.ViewName);
            }
        }
コード例 #17
0
        public void AddUserTest()
        {
            Users       user = TestUtility.CreateTestUser();
            UserManager um   = new UserManager();


            using (var db = new TicketingSystemDBContext())
            {
                string   testerId = db.Users.Where(u => u.Email == "*****@*****.**").FirstOrDefault().Auth0Uid;
                UserData ud       = Auth0APIClient.GetUserData(testerId);

                um.CreateUser(user, ud);

                string id = db.Users.Find(user.UserId).Auth0Uid;

                SetRoleTest(id, user.ShiftType);
                FetchRoleTest(user.ShiftType);
                GetUserRole(id, user.ShiftType);
                DeleteUserTest(id);

                Assert.IsNotNull(id);
            }
        }
コード例 #18
0
 public void GetAllUsersTest()
 {
     Assert.IsNotNull(Auth0APIClient.GetAllUsers());
 }
コード例 #19
0
        public void SetRoleTest(string auth0Id, string shiftType)
        {
            bool result = Auth0APIClient.SetRole(auth0Id, shiftType);

            Assert.IsTrue(result);
        }
コード例 #20
0
 public void InitAPITokenTest()
 {
     Assert.IsTrue(Auth0APIClient.InitAPIToken());
 }
コード例 #21
0
        public void GetPermissionsTest()
        {
            var users = Auth0APIClient.GetAllUsers();

            Assert.IsNotNull(Auth0APIClient.GetPermissions(users[0].user_id));
        }
コード例 #22
0
 public void ValidateTokenTest()
 {
     Assert.IsTrue(Auth0APIClient.ValidateToken());
 }