Exemplo n.º 1
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 {
                }
            }
        }
Exemplo n.º 2
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 {
                }
            }
        }
Exemplo n.º 3
0
        public void TestLocalGroupCreateDelete()
        {
            NTHost       host      = NTHost.CurrentMachine;
            string       groupName = GenerateGroupName(host);
            NTLocalGroup group     = host.CreateLocalGroup(groupName, null);

            Assert.IsNotNull(group);
            Assert.IsTrue(ContainsObjectByName(host.GetLocalGroups(), groupName));
            group.Delete();
            Assert.IsFalse(ContainsObjectByName(host.GetLocalGroups(), groupName));
        }
Exemplo n.º 4
0
        public void TestLocalGroupGetDescription()
        {
            NTHost       host        = NTHost.CurrentMachine;
            string       groupName   = GenerateGroupName(host);
            string       description = "Test description";
            NTLocalGroup group       = host.CreateLocalGroup(groupName, description);

            try {
                group = GetObjectByName(host.GetLocalGroups(), groupName);
                Assert.AreEqual(description, group.Description);
            } finally {
                group.Delete();
            }
        }
Exemplo n.º 5
0
        public void TestLocalGroupEmptyMembers()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalGroup group = null;

            try {
                group = host.CreateLocalGroup(GenerateGroupName(host), "description");
                CollectionAssert.IsEmpty(group.GetLocalMembers());
            } finally {
                try {
                    if (group != null)
                    {
                        group.Delete();
                    }
                } catch {
                }
            }
        }
Exemplo n.º 6
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 {
                }
            }
        }
Exemplo n.º 7
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 {
                }
            }
        }
Exemplo n.º 8
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 {
                }
            }
        }