Beispiel #1
0
        public void testModifyUserAttribute()
        {
            bool result;

            testAdminConnect();
            LdapUser testLdapUser = setupTestUser();

            result = LdapManagerObj.CreateUser(testLdapUser);

            Assert.IsTrue(result);

            List <LdapUser> returnUsers        = new List <LdapUser>();
            const string    userAttributeValue = "description Modified";

            result = LdapManagerObj.ModifyUserAttribute(DirectoryAttributeOperation.Replace, testLdapUser, "description", userAttributeValue);

            Assert.IsTrue(result);

            result = LdapManagerObj.SearchUsers(
                new List <string> {
                "description"
            },
                LDAPMatchSearchField,
                out returnUsers);

            Assert.IsTrue(result);
            Assert.AreEqual(returnUsers[0].GetUserCn(), testLdapUser.GetUserCn());
            Assert.AreEqual(returnUsers[0].GetUserAttribute("description")[0], userAttributeValue);

            result = LdapManagerObj.DeleteUser(testLdapUser);

            Assert.IsTrue(result);
        }
Beispiel #2
0
        public void TestModifyUserAttribute()
        {
            TestAdminConnect();
            var testLdapUser = new LdapUser(WriteUserDn, WriteUserCn, "test",
                                            new Dictionary <string, List <string> > {
                { "description", new List <string> {
                      "test"
                  } }
            });
            var result = _ldapManagerObj.CreateUser(testLdapUser);

            Assert.IsTrue(result);

            IList <ILdapUser> returnUsers;
            const string      userAttributeValue = "description Modified";

            result = _ldapManagerObj.ModifyUserAttribute(DirectoryAttributeOperation.Delete, testLdapUser, "ciccio",
                                                         userAttributeValue);

            Assert.IsFalse(result);
            Assert.AreEqual(_ldapManagerObj.GetLdapMessage().Split('-')[1].Substring(1),
                            "LDAP MODIFY USER ATTRIBUTE ERROR: ");

            result = _ldapManagerObj.ModifyUserAttribute(DirectoryAttributeOperation.Replace, testLdapUser,
                                                         "description", userAttributeValue);

            Assert.IsTrue(result);
            Assert.AreEqual(_ldapManagerObj.GetLdapMessage().Split('-')[1].Substring(1),
                            "LDAP USER MANIPULATION SUCCESS: ");

            result = _ldapManagerObj.SearchUsers(
                new List <string> {
                "description"
            },
                new[] { WriteUserCn },
                out returnUsers);

            Assert.IsTrue(result);
            Assert.AreEqual(returnUsers[0].GetUserCn(), testLdapUser.GetUserCn());
            Assert.AreEqual(returnUsers[0].GetUserAttribute("description")[0], userAttributeValue);

            result = _ldapManagerObj.DeleteUser(testLdapUser);

            Assert.IsTrue(result);
        }
Beispiel #3
0
        public bool TestModifyUserAttribute()
        {
            string oldDescription;

            if (!TestAdminConnect())
            {
                return(false);
            }

            if (!_ldapManagerObj.CreateUser(_userRepository.TestUser))
            {
                return(false);
            }

            IList <ILdapUser> returnUsers;

            try
            {
                oldDescription = _userRepository.TestUser.GetUserAttribute("description")[0];
            }
            catch (Exception)
            {
                oldDescription = "";
            }
            bool result = _ldapManagerObj.ModifyUserAttribute(DirectoryAttributeOperation.Replace,
                                                              _userRepository.TestUser,
                                                              "description", _userRepository.TestUserNewDescription);

            if (!result)
            {
                _ldapManagerObj.DeleteUser(_userRepository.TestUser);
                _userRepository.TestUser.OverwriteUserAttribute("description", oldDescription);
                return(false);
            }
            switch (_ldapMatchSearchField[0])
            {
            case "cn":
                result = _ldapManagerObj.SearchUsers(new List <string> {
                    "description"
                },
                                                     new[] { _userRepository.TestUser.GetUserCn() },
                                                     out returnUsers);
                break;

            case "sn":
                result = _ldapManagerObj.SearchUsers(new List <string> {
                    "description"
                },
                                                     new[] { _userRepository.TestUser.GetUserSn() },
                                                     out returnUsers);
                break;

            case "dn":
                result = _ldapManagerObj.SearchUsers(new List <string> {
                    "description"
                },
                                                     new[] { _userRepository.TestUser.GetUserDn() },
                                                     out returnUsers);
                break;

            default:
                result = _ldapManagerObj.SearchUsers(new List <string> {
                    "description"
                },
                                                     _userRepository.TestUser.GetUserAttribute(_ldapMatchSearchField[0]).ToArray(),
                                                     out returnUsers);
                break;
            }

            if (result &&
                returnUsers[0].GetUserCn().Equals(_userRepository.TestUser.GetUserCn()) &&
                returnUsers[0].GetUserAttribute("description")[0].Equals(_userRepository.TestUserNewDescription))
            {
                result = _ldapManagerObj.DeleteUser(_userRepository.TestUser);
                if (result)
                {
                    return(true);
                }
                return(false);
            }
            _ldapManagerObj.DeleteUser(_userRepository.TestUser);
            _userRepository.TestUser.OverwriteUserAttribute("description",
                                                            returnUsers[0].GetUserAttribute("description"));
            return(false);
        }