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);
            }
        }
Beispiel #2
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));
        }
        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 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);
            }
        }
Beispiel #5
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();
                }
            }
        }