Пример #1
0
        private LdapUser setupReadOnlyTestUser()
        {
            string userDN = "cn=Matteo,o=ApexNet,ou=People,dc=maxcrc,dc=com";
            string userCN = "Matteo";
            string userSN = "Paci";

            LdapUser testLdapUser = new LdapUser(userDN, userCN, userSN, null);

            testLdapUser.CreateUserAttribute("userPassword", "1");
            testLdapUser.CreateUserAttribute("description", "test");

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["LDAPMatchFieldUsername"]))
            {
                if (ConfigurationManager.AppSettings["LDAPMatchFieldUsername"].Equals("cn"))
                    LDAPMatchSearchField = new string[1] { testLdapUser.GetUserCn() };
                else if (ConfigurationManager.AppSettings["LDAPMatchFieldUsername"].Equals("dn"))
                    LDAPMatchSearchField = new string[1] { testLdapUser.GetUserDn() };
                else if (ConfigurationManager.AppSettings["LDAPMatchFieldUsername"].Equals("sn"))
                    LDAPMatchSearchField = new string[1] { testLdapUser.GetUserSn() };
                else
                    LDAPMatchSearchField = new string[1] {
						testLdapUser.GetUserAttribute( ConfigurationManager.AppSettings["LDAPMatchFieldUsername"] )[0]
					};
            }

            //Set the test user
            return testLdapUser;
        }
Пример #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);

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