Exemple #1
0
        public void TestLocalUserWithSingleGroup()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user  = null;
            NTLocalGroup group = null;

            try {
                group = host.CreateLocalGroup(GenerateGroupName(host), null);
                user  = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user.AddMembership(group.Name);
                Assert.IsTrue(ContainsObjectByName(user.GetMembership(), group.Name));
            } finally {
                try {
                    if (user != null)
                    {
                        user.Delete();
                    }
                } catch {
                }

                try {
                    if (user != null)
                    {
                        group.Delete();
                    }
                } catch {
                }
            }
        }
Exemple #2
0
        public void TestLocalGroupDeleteByName()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user  = null;
            NTLocalGroup group = null;

            try {
                group = host.CreateLocalGroup(GenerateGroupName(host), null);
                user  = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                group.AddLocalMember(user.Name);
                Assert.IsTrue(ContainsObjectByName(group.GetLocalMembers(), user.Name));
                group.DeleteLocalMember(user.Name);
                CollectionAssert.IsEmpty(group.GetLocalMembers());
            } finally {
                try {
                    if (user != null)
                    {
                        user.Delete();
                    }
                } catch {
                }

                try {
                    if (user != null)
                    {
                        group.Delete();
                    }
                } catch {
                }
            }
        }
Exemple #3
0
        public void TestLocalPersistUserPassword()
        {
            NTHost host  = NTHost.CurrentMachine;
            string value = "AbCn1122CeF123";
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            user.Password = value;
            user.Update();
            user.Delete();
        }
Exemple #4
0
        public void TestLocalUserCreateDelete()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            Assert.IsNotNull(user);
            Assert.IsTrue(ContainsObjectByName(host.GetLocalUsers(), userName));
            user.Delete();
            Assert.IsFalse(ContainsObjectByName(host.GetLocalUsers(), userName));
        }
Exemple #5
0
        public void TestLocalUserSIDContainsHostSID()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.AreEqual(user.SID.AccountDomainSid, host.SID);
            } finally {
                user.Delete();
            }
        }
Exemple #6
0
        public void TestLocalUserUpdateLogonServer()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.AreEqual("\\\\*", user.LogonServer);
            } finally {
                user.Delete();
            }
        }
Exemple #7
0
        public void TestLocalUserUpdatePrivilege()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.AreEqual(user.Privilege, UserPrivilege.Guest);
            } finally {
                user.Delete();
            }
        }
Exemple #8
0
        public void TestLocalUserUpdateSID()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.IsNotNull(user.SID);
            } finally {
                user.Delete();
            }
        }
Exemple #9
0
        public void TestLocalUserUpdatePasswordAge()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.IsTrue(0 <= user.PasswordAge.TotalSeconds && user.PasswordAge.TotalSeconds <= 2);
            } finally {
                user.Delete();
            }
        }
Exemple #10
0
        public void TestLocalUserUpdateLastLogon()
        {
            NTHost   host  = NTHost.CurrentMachine;
            DateTime value = DateTime.MinValue;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(value, user.LastLogon);
            } finally {
                user.Delete();
            }
        }
Exemple #11
0
        public void TestLocalUserUpdateHomeDirectory()
        {
            NTHost host  = NTHost.CurrentMachine;
            string value = "c:\\";
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.HomeDirectory = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(user.HomeDirectory, value);
            } finally {
                user.Delete();
            }
        }
Exemple #12
0
        public void TestLocalGetUserUnitsPerWeek()
        {
            NTHost host  = NTHost.CurrentMachine;
            uint   value = 5;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.UnitsPerWeek = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(user.UnitsPerWeek, value);
            } finally {
                user.Delete();
            }
        }
Exemple #13
0
        public void TestLocalUserUpdateScriptPath()
        {
            NTHost host  = NTHost.CurrentMachine;
            string value = Process.GetCurrentProcess().StartInfo.FileName;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.ScriptPath = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(user.ScriptPath, value);
            } finally {
                user.Delete();
            }
        }
Exemple #14
0
        public void TestLocalUserUpdateLogonHours()
        {
            NTHost host = NTHost.CurrentMachine;

            byte[] value = new byte[21] {
                1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1
            };
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            user.LogonHours = value;
            user.Update();
            user = GetObjectByName(host.GetLocalUsers(), userName);
            CollectionAssert.AreEqual(user.LogonHours, value);
            user.Delete();
        }
Exemple #15
0
        public void TestLocalUserGetWorkstations()
        {
            NTHost host = NTHost.CurrentMachine;

            string[] value = new string[] { "W1", "w2" };
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.Workstations = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                CollectionAssert.AreEqual(user.Workstations, value);
            } finally {
                user.Delete();
            }
        }
Exemple #16
0
        public void TestLocalUserUpdateMaxStorage()
        {
            NTHost host  = NTHost.CurrentMachine;
            uint   value = 1000;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
//                user.Flags |= UserFlags.
                user.MaxStorage = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(value, user.MaxStorage);
            } finally {
                user.Delete();
            }
        }
Exemple #17
0
        public void TestLocalUserWithEmptyMembership()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser user = null;

            try {
                user = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                CollectionAssert.IsEmpty(user.GetMembership());
            } finally {
                try {
                    if (user != null)
                    {
                        user.Delete();
                    }
                } catch {
                }
            }
        }
Exemple #18
0
        public void TestLocalGroupDeleteMultipleMembersWithWithUserMembershipVerify()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user1  = null;
            NTLocalUser  user2  = null;
            NTLocalGroup group1 = null;
            NTLocalGroup group2 = null;
            NTLocalGroup group3 = null;

            try {
                group1 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group1);
                group2 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group2);
                group3 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group3);

                user1 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user2 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");

                group1.AddLocalMember(user1.Name);
                group1.AddLocalMember(user2.Name);
                group2.AddLocalMember(user1.Name);
                group3.AddLocalMember(user2.Name);

                group1.DeleteLocalMember(user1.Name);
                group1.DeleteLocalMember(user2.Name);
                group2.DeleteLocalMember(user1.Name);
                group3.DeleteLocalMember(user2.Name);


                NTLocalGroup[] user1Membership = user1.GetMembership();
                Assert.IsNotNull(user1Membership);
                Assert.AreEqual(0, user1Membership.Length);

                NTLocalGroup[] user2Membership = user2.GetMembership();
                Assert.IsNotNull(user2Membership);
                Assert.AreEqual(0, user2Membership.Length);
            } finally {
                try {
                    if (user1 != null)
                    {
                        user1.Delete();
                    }
                } catch {
                }

                try {
                    if (user2 != null)
                    {
                        user2.Delete();
                    }
                } catch {
                }

                try {
                    if (group1 != null)
                    {
                        group1.Delete();
                    }
                } catch {
                }


                try {
                    if (group2 != null)
                    {
                        group2.Delete();
                    }
                } catch {
                }


                try {
                    if (group3 != null)
                    {
                        group3.Delete();
                    }
                } catch {
                }
            }
        }
Exemple #19
0
        public void TestLocalGroupWithMultipleMembersWithWithGroupMembershipVerify()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user1  = null;
            NTLocalUser  user2  = null;
            NTLocalGroup group1 = null;
            NTLocalGroup group2 = null;
            NTLocalGroup group3 = null;

            try {
                group1 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group1);
                group2 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group2);
                group3 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group3);


                user1 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user2 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");

                group1.AddLocalMember(user1.Name);
                group1.AddLocalMember(user2.Name);
                group2.AddLocalMember(user1.Name);
                group3.AddLocalMember(user2.Name);

                NTLocalObject[] group1Members = group1.GetLocalMembers();
                Assert.IsNotNull(group1Members);
                Assert.AreEqual(2, group1Members.Length);
                Assert.IsTrue(ContainsObjectByName(group1Members, user1.Name));
                Assert.IsTrue(ContainsObjectByName(group1Members, user2.Name));

                NTLocalObject[] group2Members = group2.GetLocalMembers();
                Assert.IsNotNull(group2Members);
                Assert.AreEqual(1, group2Members.Length);
                Assert.IsTrue(ContainsObjectByName(group2Members, user1.Name));

                NTLocalObject[] group3Members = group3.GetLocalMembers();
                Assert.IsNotNull(group3Members);
                Assert.AreEqual(1, group3Members.Length);
                Assert.IsTrue(ContainsObjectByName(group3Members, user2.Name));
            } finally {
                try {
                    if (user1 != null)
                    {
                        user1.Delete();
                    }
                } catch {
                }

                try {
                    if (user2 != null)
                    {
                        user2.Delete();
                    }
                } catch {
                }

                try {
                    if (group1 != null)
                    {
                        group1.Delete();
                    }
                } catch {
                }


                try {
                    if (group2 != null)
                    {
                        group2.Delete();
                    }
                } catch {
                }


                try {
                    if (group3 != null)
                    {
                        group3.Delete();
                    }
                } catch {
                }
            }
        }
Exemple #20
0
        public void TestLocalUsersWithMultipleGroups()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user1  = null;
            NTLocalUser  user2  = null;
            NTLocalGroup group1 = null;
            NTLocalGroup group2 = null;
            NTLocalGroup group3 = null;

            try {
                group1 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group1);
                group2 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group2);
                group3 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group3);


                user1 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user2 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");

                user1.AddMembership(group1.Name);
                user1.AddMembership(group2.Name);
                user2.AddMembership(group1.Name);
                user2.AddMembership(group3.Name);

                NTLocalGroup[] user1Membership = user1.GetMembership();
                Assert.IsNotNull(user1Membership);

                Assert.IsTrue(ContainsObjectByName(user1Membership, group1.Name));
                Assert.IsTrue(ContainsObjectByName(user1Membership, group2.Name));

                NTLocalGroup[] user2Membership = user2.GetMembership();
                Assert.IsNotNull(user2Membership);

                Assert.IsTrue(ContainsObjectByName(user2Membership, group1.Name));
                Assert.IsTrue(ContainsObjectByName(user2Membership, group3.Name));
            } finally {
                try {
                    if (user1 != null)
                    {
                        user1.Delete();
                    }
                } catch {
                }

                try {
                    if (user2 != null)
                    {
                        user2.Delete();
                    }
                } catch {
                }

                try {
                    if (group1 != null)
                    {
                        group1.Delete();
                    }
                } catch {
                }


                try {
                    if (group2 != null)
                    {
                        group2.Delete();
                    }
                } catch {
                }


                try {
                    if (group3 != null)
                    {
                        group3.Delete();
                    }
                } catch {
                }
            }
        }