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 CannotDeleteNotCreatedUser()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            user.Delete();

            // Assert
            // Expected exception;
        }
        public void CannotDeleteNotCreatedUser()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            user.Delete();

            // Assert
            // Expected exception;
        }
        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();
            }
        }
        public void TestListPrisonUsers()
        {
            string username = "******";

            string[] newwinusers = { "Administrator", "Guest", "openshift_service", username };

            using (ShimsContext.Create())
            {
                ShimWindowsUsersAndGroups.GetUsers = () => { return(newwinusers); };
                PrisonTestsHelper.PersistanceReadDataFake(username);
                PrisonUser[] users = PrisonUser.ListUsers();

                Assert.IsTrue(users.Length == Array.FindAll(newwinusers, user => user.StartsWith("prison")).Length);
            }
        }
        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));
        }
        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));
        }
Exemple #9
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));
        }
        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));
        }
        public void CredentialGenerationWithPrefix()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            string        username       = user.Username;
            string        password       = user.Password;
            string        prefix         = user.UsernamePrefix;
            List <string> usernamePieces = username.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            // Assert
            Assert.AreEqual(3, usernamePieces.Count);
            Assert.AreEqual("untst", prefix);
            Assert.IsFalse(string.IsNullOrWhiteSpace(username));
            Assert.IsFalse(string.IsNullOrWhiteSpace(password));
            Assert.IsTrue(username.Contains("untst"));
        }
        public void CredentialGenerationWithPrefix()
        {
            // Arrange
            PrisonUser user = new PrisonUser("untst");

            // Act
            string username = user.UserName;
            string password = user.Password;
            string prefix = user.UserNamePrefix;
            List<string> usernamePieces = username.Split(new string[] {"_"}, StringSplitOptions.RemoveEmptyEntries).ToList();

            // Assert
            Assert.AreEqual(3, usernamePieces.Count);
            Assert.AreEqual("untst", prefix);
            Assert.IsFalse(string.IsNullOrWhiteSpace(username));
            Assert.IsFalse(string.IsNullOrWhiteSpace(password));
            Assert.IsTrue(username.Contains("untst"));
        }
        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;
            }
        }
Exemple #14
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 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);
            }
        }
Exemple #16
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 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();
            }
        }
Exemple #20
0
        static void Main(string[] args)
        {
            string invokedVerb         = null;
            object invokedVerbInstance = null;

            var options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options,
                                                           (verb, subOptions) =>
            {
                // if parsing succeeds the verb name and correct instance
                // will be passed to onVerbCommand delegate (string,object)
                invokedVerb = verb;
                invokedVerbInstance = subOptions;
            }))
            {
                Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
            }

            if (invokedVerb == "list")
            {
                var listSubOptions = (ListSubOptions)invokedVerbInstance;
                if (listSubOptions.Orphaned)
                {
                    Dictionary <CellType, CellInstanceInfo[]> instances = Prison.ListCellInstances();

                    foreach (CellType cellType in instances.Keys)
                    {
                        TableBuilder tb = new TableBuilder();
                        tb.AddRow(cellType.ToString(), "Info");
                        tb.AddRow(new string('-', cellType.ToString().Length), "----");

                        foreach (CellInstanceInfo cellInstance in instances[cellType])
                        {
                            tb.AddRow(cellInstance.Name, cellInstance.Info);
                        }

                        Console.Write(tb.Output());
                        Console.WriteLine();
                    }
                }
            }
            else if (invokedVerb == "list-users")
            {
                var listUsersSubOptions = (ListUsersSubOptions)invokedVerbInstance;

                if (string.IsNullOrWhiteSpace(listUsersSubOptions.Filter))
                {
                    PrisonUser[] users = PrisonUser.ListUsers();

                    TableBuilder tb = new TableBuilder();
                    tb.AddRow("Full Username", "Prefix");
                    tb.AddRow("-------------", "------");

                    foreach (PrisonUser user in users)
                    {
                        tb.AddRow(user.Username, user.UsernamePrefix);
                    }

                    Console.Write(tb.Output());
                    Console.WriteLine();
                }
            }
        }
        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);

            }
        }
        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();
            }
        }