コード例 #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 TestChangeUserPassword()
        {
            TestAdminConnect();
            const string newPassword = "******";
            var testUser = new LdapUser(WriteUserDn, WriteUserCn, "test",
                new Dictionary<string, List<string>> {{"userPassword", new List<string> {WriteUserPwd}}});
            //Create the user
            var result = _ldapManagerObj.CreateUser(testUser);

            Assert.IsTrue(result);

            //Perform change of password
            result = _ldapManagerObj.ChangeUserPassword(testUser, newPassword);
            Assert.IsTrue(result);
            Assert.AreEqual(_ldapManagerObj.GetLdapMessage().Split('-')[1].Substring(1),
                "LDAP USER MANIPULATION SUCCESS: ");

            //Try to connect with the old password
            var testUserCredential = new NetworkCredential(
                testUser.GetUserDn(),
                WriteUserPwd,
                "");

            result = _ldapManagerObj.Connect(testUserCredential);

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

            //Try to connect with the new password
            testUserCredential = new NetworkCredential(
                testUser.GetUserDn(),
                newPassword,
                "");

            result = _ldapManagerObj.Connect(testUserCredential);

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

            TestAdminConnect();

            result = _ldapManagerObj.DeleteUser(testUser);

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