public void TestCreatePrisonUser_UserExist()
        {
            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return(true); };

                PrisonUser user = new PrisonUser("untst");
                user.Create();
            }
        }
        public void TestCreatePrisonUser_UserExist()
        {
            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return true; };

                PrisonUser user = new PrisonUser("untst");
                user.Create();
            }
        }
        public void TestDeletePrisonUser_UserDoNotExist()
        {
            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.ExistsUserString       = (username) => { return(false); };
                ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { return; };
                ShimWindowsUsersAndGroups.GetLocalUserSidString  = (username) => { return("a string"); };

                PrisonUser user = new PrisonUser("untst");
                user.Create();

                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return(false); };
                user.Delete();
            }
        }
Esempio n. 4
0
        public void CreateAndDeleteUser()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            user.Create();

            // Assert
            Assert.IsTrue(PrisonUser.ListUsers("untst").Any(u => u.Username == user.Username));

            // Act
            user.Delete();

            // Assert
            Assert.IsFalse(PrisonUser.ListUsers("untst").Any(u => u.Username == user.Username));
        }
Esempio n. 5
0
        public void CreateAndDeleteUser()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            user.Create();

            // Assert
            Assert.IsTrue(PrisonUser.ListOrphanedUsers("untst").Contains(user.UserName));

            // Act
            user.Delete();

            // Assert
            Assert.IsFalse(PrisonUser.ListOrphanedUsers("untst").Contains(user.UserName));
        }
Esempio n. 6
0
        public void CreateAndDeleteUser()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            user.Create();

            // Assert
            Assert.IsTrue(PrisonUser.ListOrphanedUsers("untst").Contains(user.UserName));

            // Act
            user.Delete();

            // Assert
            Assert.IsFalse(PrisonUser.ListOrphanedUsers("untst").Contains(user.UserName));
        }
Esempio n. 7
0
        public void CreateAndDeleteUser()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            user.Create();

            // Assert
            Assert.IsTrue(PrisonUser.ListUsers("untst").Any(u => u.Username == user.Username));

            // Act
            user.Delete();

            // Assert
            Assert.IsFalse(PrisonUser.ListUsers("untst").Any(u => u.Username == user.Username));
        }
Esempio n. 8
0
        public static void InitOpenDirectoriesList()
        {
            string[] result = null;

            lock (openDirLock)
            {
                PrisonUser isolationUser = new PrisonUser("acl");
                isolationUser.Create();

                using (new UserImpersonator(isolationUser.Username, ".", isolationUser.Password, true))
                {
                    result = GetOpenDirectories(new DirectoryInfo(@"c:\")).ToArray();
                }

                isolationUser.Delete();

                openDirs = result;
            }
        }
        public static void InitOpenDirectoriesList()
        {
            string[] result = null;

            lock (openDirLock)
            {
                PrisonUser isolationUser = new PrisonUser("acl");
                isolationUser.Create();

                using (new UserImpersonator(isolationUser.Username, ".", isolationUser.Password, true))
                {
                    result = GetOpenDirectories(new DirectoryInfo(@"c:\")).ToArray();
                }

                isolationUser.Delete();

                openDirs = result;
            }
        }
        public void TestDeletePrisonUserOK()
        {
            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.ExistsUserString       = (username) => { return(false); };
                ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { return; };
                ShimWindowsUsersAndGroups.GetLocalUserSidString  = (username) => { return("a string"); };

                PrisonUser user = new PrisonUser("untst");
                user.Create();

                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return(true); };
                ShimWindowsUsersAndGroups.DeleteUserString = (username) => { return; };
                user.Delete();

                ShimWindowsUsersAndGroups.GetUsers = () => { return(new string[] { "Administrator", "Guest", "openshift_service" }); };
                PrisonUser[] users = PrisonUser.ListUsers("untst");

                Assert.IsTrue(Array.Find(users, u => u.Username == user.Username) == null);
            }
        }
Esempio n. 11
0
        public void TestGrantAndRevokeTokenPrivilege()
        {
            // Arrange
            PrisonUser newUser = new PrisonUser("prtst");

            try
            {
                newUser.Create();
                bool hasPrivilege = UserRightsAssignmentPolicies.UserHasPrivilege(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);
                Assert.IsFalse(hasPrivilege);

                // Act
                UserRightsAssignmentPolicies.GrantPrivilegeToUser(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);
                hasPrivilege = UserRightsAssignmentPolicies.UserHasPrivilege(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);

                // Assert
                Assert.IsTrue(hasPrivilege);

                // Act
                UserRightsAssignmentPolicies.RevokePrivilegeToUser(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);
                hasPrivilege = UserRightsAssignmentPolicies.UserHasPrivilege(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);

                // Assert
                Assert.IsFalse(hasPrivilege);
            }
            finally
            {
                newUser.Delete();
            }
        }
        public void TestCreatePrisonUserOK()
        {
            using (ShimsContext.Create())
            {
                string newuser = string.Empty;

                ShimWindowsUsersAndGroups.ExistsUserString       = (username) => { return(false); };
                ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { newuser = username; return; };
                ShimWindowsUsersAndGroups.GetLocalUserSidString  = (username) => { return("a string"); };

                ShimPersistence.SaveValueStringStringObject = (group, key, value) => { return; };

                PrisonUser user = new PrisonUser("untst");
                user.Create();

                ShimWindowsUsersAndGroups.GetUsers = () => { return(new string [] { "Administrator", "Guest", "openshift_service", newuser }); };
                PrisonTestsHelper.PersistanceReadDataFake(newuser);
                PrisonUser[] users = PrisonUser.ListUsers("untst");

                Assert.IsTrue(Array.Find(users, u => u.Username == user.Username) != null);
            }
        }
        public void TestGrantAndRevokeTokenPrivilege()
        {
            // Arrange
            PrisonUser newUser = new PrisonUser("prtst");
            try
            {
                newUser.Create();
                bool hasPrivilege = UserRightsAssignmentPolicies.UserHasPrivilege(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);
                Assert.IsFalse(hasPrivilege);

                // Act
                UserRightsAssignmentPolicies.GrantPrivilegeToUser(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);
                hasPrivilege = UserRightsAssignmentPolicies.UserHasPrivilege(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);

                // Assert
                Assert.IsTrue(hasPrivilege);

                // Act
                UserRightsAssignmentPolicies.RevokePrivilegeToUser(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);
                hasPrivilege = UserRightsAssignmentPolicies.UserHasPrivilege(
                    UserRightsAssignmentPolicies.ReplaceTokenPrivilege,
                    newUser.UserName);

                // Assert
                Assert.IsFalse(hasPrivilege);
            }
            finally
            {
                newUser.Delete();
            }
        }
Esempio n. 14
0
        public void TestCreatePrisonUserOK()
        {           
            using (ShimsContext.Create())
            {
                string newuser = string.Empty;

                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return false; };
                ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { newuser = username; return; };
                ShimWindowsUsersAndGroups.GetLocalUserSidString = (username) => { return "a string"; };

                ShimPersistence.SaveValueStringStringObject = (group, key, value) => { return; };

                PrisonUser user = new PrisonUser("untst");
                user.Create();

                ShimWindowsUsersAndGroups.GetUsers = () => { return new string [] { "Administrator", "Guest", "openshift_service", newuser }; };
                PrisonTestsHelper.PersistanceReadDataFake(newuser);
                PrisonUser[] users = PrisonUser.ListUsers("untst");

                Assert.IsTrue(Array.Find(users, u => u.Username == user.Username) != null);              
            }
        }
Esempio n. 15
0
        public void TestDeletePrisonUserOK()
        {
            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return false; };
                ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { return; };
                ShimWindowsUsersAndGroups.GetLocalUserSidString = (username) => { return "a string"; };

                PrisonUser user = new PrisonUser("untst");
                user.Create();

                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return true; };
                ShimWindowsUsersAndGroups.DeleteUserString = (username) => { return; };
                user.Delete();

                ShimWindowsUsersAndGroups.GetUsers = () => { return new string[] { "Administrator", "Guest", "openshift_service"}; };
                PrisonUser[] users = PrisonUser.ListUsers("untst");

                Assert.IsTrue(Array.Find(users, u => u.Username == user.Username) == null);

            }
        }
Esempio n. 16
0
        public void TestDeletePrisonUser_UserDoNotExist()
        {
            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return false; };
                ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { return; };
                ShimWindowsUsersAndGroups.GetLocalUserSidString = (username) => { return "a string"; };

                PrisonUser user = new PrisonUser("untst");
                user.Create();

                ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return false; };
                user.Delete();
            }
        }