--- /dev/null
+//\r
+// DirectoryServicesDirectoryEntryTest.cs -\r
+// NUnit Test Cases for DirectoryServices.DirectoryEntry\r
+//\r
+// Author:\r
+// Boris Kirzner <borisk@mainsoft.com>\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.DirectoryServices;\r
+\r
+namespace MonoTests.System.DirectoryServices \r
+{\r
+ [TestFixture]\r
+ [Category ("InetAccess")]\r
+ public class DirectoryServicesDirectoryEntryTest\r
+ {\r
+ #region Fields\r
+\r
+ static string LDAPServerRoot;\r
+ static string LDAPServerConnectionString;\r
+ static string LDAPServerUsername;\r
+ static string LDAPServerPassword;\r
+ static DirectoryEntry de;\r
+\r
+ #endregion // Fields\r
+\r
+ #region SetUp and TearDown\r
+\r
+ [TestFixtureSetUp]\r
+ public void TestFixtureSetUp()\r
+ {\r
+ de = null;\r
+ string ldapServerName = Environment.GetEnvironmentVariable("MONO_LDAP_TEST_SERVER");\r
+ Assert.IsFalse((ldapServerName == null || ldapServerName == String.Empty),"This test fixture requires environment variable MONO_LDAP_TEST_SERVER to be set up to LDAP server name.");\r
+ LDAPServerRoot = "LDAP://" + ldapServerName + "/";\r
+ LDAPServerConnectionString = LDAPServerRoot + "dc=myhosting,dc=example";\r
+ LDAPServerUsername = "cn=Manager,dc=myhosting,dc=example";\r
+ LDAPServerPassword = "secret";\r
+ }\r
+\r
+\r
+ [TestFixtureTearDown]\r
+ public void TestFixtureTearDown()\r
+ {\r
+ de = null;\r
+ }\r
+\r
+\r
+ [SetUp]\r
+ public void SetUp()\r
+ {\r
+ #region Initialize basics\r
+\r
+ DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");\r
+ ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouPeople.Properties["description"].Value = "All people in organisation";\r
+ ouPeople.Properties["ou"].Value = "people";\r
+ ouPeople.CommitChanges();\r
+\r
+ #endregion // Initialize basics\r
+\r
+ #region Human Resources\r
+ \r
+ DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");\r
+ ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouHumanResources.Properties["ou"].Value = "Human Resources";\r
+ ouHumanResources.CommitChanges();\r
+\r
+ DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");\r
+ cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";\r
+ cnJohnSmith.Properties["cn"].Value = "John Smith";\r
+ cnJohnSmith.Properties["description"].Value = "Very clever person";\r
+ cnJohnSmith.Properties["ou"].Value = "Human Resources";\r
+ cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";\r
+ cnJohnSmith.CommitChanges();\r
+\r
+ DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
+ cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
+ cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
+ cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
+ cnBarakTsabari.CommitChanges();\r
+\r
+ #endregion // Human Resources\r
+\r
+ #region R&D\r
+\r
+ DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");\r
+ ouRnD.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouRnD.Properties["ou"].Value = "R&D";\r
+ ouRnD.CommitChanges();\r
+\r
+ DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";\r
+ cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");\r
+ cnYossiCohen.Properties["sn"].Value = "Cohen";\r
+ cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";\r
+ cnYossiCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnUziCohen.Properties["cn"].Value = "Uzi Cohen";\r
+ cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
+ ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");\r
+ cnUziCohen.Properties["sn"].Value = "Cohen";\r
+ cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
+ cnUziCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";\r
+ cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");\r
+ cnDanielCohen.Properties["sn"].Value = "Cohen";\r
+ cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";\r
+ cnDanielCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnSaraCohen.Properties["cn"].Value = "Sara Cohen";\r
+ cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");\r
+ cnSaraCohen.Properties["sn"].Value = "Cohen";\r
+ cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";\r
+ cnSaraCohen.CommitChanges();\r
+\r
+ #endregion // R&D\r
+\r
+ #region DevQA\r
+\r
+ DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");\r
+ ouDevQA.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouDevQA.Properties["ou"].Value = "DevQA";\r
+ ouDevQA.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielSmith.Properties["cn"].Value = "Daniel Smith";\r
+ cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";\r
+ cnDanielSmith.Properties["l"].Value = "Santa Clara";\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");\r
+ cnDanielSmith.Properties["sn"].Value = "Smith";\r
+ cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";\r
+ cnDanielSmith.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";\r
+ cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");\r
+ cnDanielMorgan.Properties["sn"].Value = "Morgan";\r
+ cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";\r
+ cnDanielMorgan.CommitChanges();\r
+\r
+ #endregion // DevQA\r
+\r
+ #region Manager\r
+\r
+ DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");\r
+ cnManager.Properties["objectClass"].Value = "organizationalRole";\r
+ cnManager.Properties["cn"].Value = "Manager";\r
+ cnManager.CommitChanges();\r
+\r
+ DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";\r
+ cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");\r
+ cnUziCohen_.Properties["sn"].Value = "Cohen";\r
+ cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
+ cnUziCohen_.CommitChanges();\r
+\r
+ #endregion // Manager\r
+\r
+ }\r
+\r
+\r
+ [TearDown]\r
+ public void TearDown()\r
+ {\r
+ de = null;\r
+\r
+ DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ \r
+ foreach(DirectoryEntry child in root.Children) {\r
+ DeleteTree_DFS(child);\r
+ } \r
+ }\r
+\r
+ private void DeleteTree_DFS(DirectoryEntry de)\r
+ {\r
+ foreach(DirectoryEntry child in de.Children) {\r
+ DeleteTree_DFS(child);\r
+ }\r
+ de.DeleteTree();\r
+ de.CommitChanges();\r
+ }\r
+\r
+ #endregion //SetUp and TearDown\r
+\r
+ #region Tests\r
+\r
+ [Test]\r
+ public void DirectoryEntry_DirectoryEntry()\r
+ {\r
+ de = new DirectoryEntry();\r
+\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
+ Assert.AreEqual(de.Password,null);\r
+ Assert.AreEqual(de.Path,String.Empty);\r
+ Assert.AreEqual(de.SchemaClassName,"domainDNS");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,null); \r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_DirectoryEntry_Str()\r
+ {\r
+ DirectoryEntry de = new DirectoryEntry(LDAPServerConnectionString);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ Assert.AreEqual(de.Password,null);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,null);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_DirectoryEntry_StrStrStrAuth()\r
+ {\r
+\r
+ #region AuthenticationTypes.Anonymous\r
+\r
+ DirectoryEntry de = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.Anonymous);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.Anonymous\r
+\r
+ #region AuthenticationTypes.Delegation\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.Delegation);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.Delegation\r
+\r
+ #region AuthenticationTypes.Encryption\r
+\r
+// de = new DirectoryEntry( LDAPServerConnectionString,\r
+// LDAPServerUsername,\r
+// LDAPServerPassword,\r
+// AuthenticationTypes.Encryption);\r
+// \r
+// Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
+// //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+// Assert.AreEqual(de.Name,"dc=myhosting");\r
+// //Assert.AreEqual(de.NativeGuid,null);\r
+// Assert.AreEqual(de.Password,LDAPServerPassword);\r
+// Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+// Assert.AreEqual(de.SchemaClassName,"organization");\r
+// Assert.AreEqual(de.UsePropertyCache,true);\r
+// Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.Encryption\r
+\r
+ #region AuthenticationTypes.FastBind\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.FastBind);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.FastBind\r
+\r
+ #region AuthenticationTypes.None\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.None);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.None\r
+\r
+ #region AuthenticationTypes.ReadonlyServer\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ReadonlyServer);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.ReadonlyServer\r
+\r
+ #region AuthenticationTypes.Sealing\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.Sealing);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.Sealing\r
+\r
+ #region AuthenticationTypes.Secure\r
+\r
+// de = new DirectoryEntry(LDAPServerConnectionString,\r
+// LDAPServerUsername,\r
+// LDAPServerPassword,\r
+// AuthenticationTypes.Secure);\r
+// \r
+// Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
+// //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+// Assert.AreEqual(de.Name,"dc=myhosting");\r
+// //Assert.AreEqual(de.NativeGuid,null);\r
+// Assert.AreEqual(de.Password,LDAPServerPassword);\r
+// Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+// Assert.AreEqual(de.SchemaClassName,"organization");\r
+// Assert.AreEqual(de.UsePropertyCache,true);\r
+// Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.Secure\r
+\r
+ #region AuthenticationTypes.SecureSocketsLayer\r
+\r
+// de = new DirectoryEntry(LDAPServerConnectionString,\r
+// LDAPServerUsername,\r
+// LDAPServerPassword,\r
+// AuthenticationTypes.SecureSocketsLayer);\r
+// \r
+// Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
+// //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+// Assert.AreEqual(de.Name,"dc=myhosting");\r
+// //Assert.AreEqual(de.NativeGuid,null);\r
+// Assert.AreEqual(de.Password,LDAPServerPassword);\r
+// Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+// Assert.AreEqual(de.SchemaClassName,"organization");\r
+// Assert.AreEqual(de.UsePropertyCache,true);\r
+// Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.SecureSocketsLayer\r
+\r
+ #region AuthenticationTypes.ServerBind\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.ServerBind\r
+\r
+ #region AuthenticationTypes.Signing\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.Signing);\r
+ \r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
+ //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+ //Assert.AreEqual(de.NativeGuid,null);\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+ Assert.AreEqual(de.SchemaClassName,"organization");\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ #endregion //AuthenticationTypes.Signing\r
+\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_AuthenticationType()\r
+ {\r
+ de = new DirectoryEntry();\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Anonymous;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Delegation;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Encryption;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.FastBind;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.None;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.ReadonlyServer;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Sealing;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Secure;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.ServerBind;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Signing;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Anonymous;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Delegation;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Encryption;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.FastBind;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.None;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.ReadonlyServer;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Sealing;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Secure;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.ServerBind;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Signing;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.None);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Anonymous;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Delegation;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Encryption;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.FastBind;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.None;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.ReadonlyServer;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Sealing;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Secure;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.ServerBind;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
+\r
+ de.AuthenticationType = AuthenticationTypes.Signing;\r
+ Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
+ }\r
+\r
+ \r
+ [Test]\r
+ public void DirectoryEntry_UsePropertyCache()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.None);\r
+\r
+ de.UsePropertyCache = true;\r
+ Assert.AreEqual(de.UsePropertyCache,true);\r
+\r
+ de.UsePropertyCache = false;\r
+ Assert.AreEqual(de.UsePropertyCache,false);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Children()\r
+ {\r
+ de = new DirectoryEntry();\r
+ DirectoryEntries children = de.Children;\r
+ Assert.AreEqual(children.SchemaFilter.Count,0); \r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+ children = de.Children;\r
+\r
+ Assert.AreEqual(children.SchemaFilter.Count,0);\r
+\r
+ int childrenCount = 0;\r
+ foreach(DirectoryEntry childDe in children) {\r
+ childrenCount++;\r
+ }\r
+ Assert.AreEqual(childrenCount,2);\r
+ Assert.AreEqual(children.Find("ou=people").Name,"ou=people");\r
+ Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ children = de.Children;\r
+\r
+ Assert.AreEqual(children.SchemaFilter.Count,0);\r
+\r
+ childrenCount = 0;\r
+ foreach(DirectoryEntry childDe in children) {\r
+ childrenCount++;\r
+ }\r
+ Assert.AreEqual(childrenCount,2);\r
+ Assert.AreEqual(children.Find("ou=people").Name,"ou=people");\r
+ Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example" ,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ children = de.Children;\r
+\r
+ Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");\r
+ Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");\r
+ }\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Name()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ Assert.AreEqual(de.Name,"dc=myhosting");\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example",\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ Assert.AreEqual(de.Name,"ou=Human Resources");\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example" ,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ Assert.AreEqual(de.Name,"cn=Barak Tsabari");\r
+ }\r
+ \r
+\r
+ [Test]\r
+ public void DirectoryEntry_Parent()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+\r
+ Assert.AreEqual(de.Parent.Path,LDAPServerRoot + "dc=example");\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ Assert.AreEqual(de.Parent.Path,LDAPServerRoot + "dc=example");\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example" ,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ Assert.AreEqual(de.Parent.Path,LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Password()\r
+ {\r
+ string wrongPassword = "some wrong password";\r
+\r
+ de = new DirectoryEntry();\r
+\r
+ Assert.AreEqual(de.Password,null);\r
+\r
+ de.Password = LDAPServerPassword;\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+\r
+ de.Password = "";\r
+ Assert.AreEqual(de.Password,String.Empty);\r
+ \r
+ de.Password = wrongPassword;\r
+ Assert.AreEqual(de.Password,wrongPassword);\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+\r
+ de.Password = LDAPServerPassword;\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+\r
+ de.Password = "";\r
+ Assert.AreEqual(de.Password,String.Empty);\r
+\r
+ de.Password = wrongPassword;\r
+ Assert.AreEqual(de.Password,wrongPassword);\r
+\r
+ \r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ de.Password = LDAPServerPassword;\r
+ Assert.AreEqual(de.Password,LDAPServerPassword);\r
+\r
+ de.Password = "";\r
+ Assert.AreEqual(de.Password,String.Empty);\r
+\r
+ de.Password = wrongPassword;\r
+ Assert.AreEqual(de.Password,wrongPassword);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Path()\r
+ {\r
+ string wrongPath = "something that is not LDAP path";\r
+\r
+ de = new DirectoryEntry();\r
+\r
+ Assert.AreEqual(de.Path,String.Empty);\r
+\r
+ de.Path = LDAPServerConnectionString;\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+\r
+ de.Path = "";\r
+ Assert.AreEqual(de.Path,String.Empty);\r
+ \r
+ de.Path = wrongPath;\r
+ Assert.AreEqual(de.Path,wrongPath);\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+\r
+ de.Path = LDAPServerConnectionString;\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+\r
+ de.Path = "";\r
+ Assert.AreEqual(de.Path,String.Empty);\r
+\r
+ de.Path = wrongPath;\r
+ Assert.AreEqual(de.Path,wrongPath);\r
+\r
+ \r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ de.Path = LDAPServerConnectionString;\r
+ Assert.AreEqual(de.Path,LDAPServerConnectionString);\r
+\r
+ de.Path = "";\r
+ Assert.AreEqual(de.Path,String.Empty);\r
+\r
+ de.Path = wrongPath;\r
+ Assert.AreEqual(de.Path,wrongPath);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Properties()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+\r
+ Assert.AreEqual(de.Properties.Count,4);\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"myhosting");\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,"My wonderful company as much text as you want to place in this line up to 32Kcontinuation data for the line above must have <CR> or <CR><LF> i.e. ENTER works on both Windows and *nix system - new line MUST begin with ONE SPACE");\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["o"]).Value,"Example, Inc.");\r
+\r
+ \r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ Assert.AreEqual(de.Properties.Count,4);\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"myhosting");\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,"My wonderful company as much text as you want to place in this line up to 32Kcontinuation data for the line above must have <CR> or <CR><LF> i.e. ENTER works on both Windows and *nix system - new line MUST begin with ONE SPACE");\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["o"]).Value,"Example, Inc.");\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_SchemaEntry()\r
+ {\r
+ de = new DirectoryEntry();\r
+ DirectoryEntry schemaEntry = de.SchemaEntry;\r
+\r
+ Assert.AreEqual(schemaEntry.Path,"LDAP://schema/domainDNS");\r
+ Assert.AreEqual(schemaEntry.Name,"domainDNS");\r
+ Assert.AreEqual(schemaEntry.Username,null);\r
+ Assert.AreEqual(schemaEntry.Password,null);\r
+ Assert.AreEqual(schemaEntry.UsePropertyCache,true);\r
+ Assert.AreEqual(schemaEntry.SchemaClassName,"Class");\r
+ Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+ schemaEntry = de.SchemaEntry;\r
+\r
+ Assert.AreEqual(schemaEntry.Path,LDAPServerRoot + "schema/organization");\r
+ Assert.AreEqual(schemaEntry.Name,"organization");\r
+ Assert.AreEqual(schemaEntry.Username,null);\r
+ Assert.AreEqual(schemaEntry.Password,null);\r
+ Assert.AreEqual(schemaEntry.UsePropertyCache,true);\r
+ Assert.AreEqual(schemaEntry.SchemaClassName,"Class");\r
+ Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.None);\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ schemaEntry = de.SchemaEntry;\r
+\r
+ Assert.AreEqual(schemaEntry.Path,LDAPServerRoot + "schema/organization");\r
+ Assert.AreEqual(schemaEntry.Name,"organization");\r
+ Assert.AreEqual(schemaEntry.Username,LDAPServerUsername);\r
+ Assert.AreEqual(schemaEntry.Password,LDAPServerPassword);\r
+ Assert.AreEqual(schemaEntry.UsePropertyCache,true);\r
+ Assert.AreEqual(schemaEntry.SchemaClassName,"Class");\r
+ Assert.AreEqual(schemaEntry.AuthenticationType,AuthenticationTypes.ServerBind);\r
+ } \r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Username()\r
+ {\r
+ string wrongUsername = "some wrong username";\r
+\r
+ de = new DirectoryEntry();\r
+\r
+ Assert.AreEqual(de.Username,null);\r
+\r
+ de.Username = LDAPServerUsername;\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ de.Username = "";\r
+ Assert.AreEqual(de.Username,String.Empty);\r
+ \r
+ de.Username = wrongUsername;\r
+ Assert.AreEqual(de.Username,wrongUsername);\r
+\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+\r
+ de.Username = LDAPServerUsername;\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ de.Username = "";\r
+ Assert.AreEqual(de.Username,String.Empty);\r
+\r
+ de.Username = wrongUsername;\r
+ Assert.AreEqual(de.Username,wrongUsername);\r
+\r
+ \r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ de.Username = LDAPServerUsername;\r
+ Assert.AreEqual(de.Username,LDAPServerUsername);\r
+\r
+ de.Username = "";\r
+ Assert.AreEqual(de.Username,String.Empty);\r
+\r
+ de.Username = wrongUsername;\r
+ Assert.AreEqual(de.Username,wrongUsername);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Close()\r
+ {\r
+ de = new DirectoryEntry();\r
+ de.Close();\r
+\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+ de.Close();\r
+ \r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ de.Close();\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_CommitChanges()\r
+ {\r
+ string humanResourcesDN = LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ DirectoryEntry ouHumanResources = new DirectoryEntry( humanResourcesDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ // new entry\r
+ string newEmployeeDN = LDAPServerRoot + "cn=New Employee,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ de = ouHumanResources.Children.Add("cn=New Employee","Class");\r
+ Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));\r
+\r
+ de.Properties["objectClass"].Value = "organizationalRole";\r
+ de.Properties["cn"].Value = "New Employee";\r
+ Assert.IsFalse(DirectoryEntry.Exists(newEmployeeDN));\r
+ \r
+ de.CommitChanges();\r
+ Assert.IsTrue(DirectoryEntry.Exists(newEmployeeDN));\r
+\r
+ // existing entry\r
+ string barakTsabariDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ de = new DirectoryEntry(barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ string oldTelephone = (string)((PropertyValueCollection)de.Properties["telephoneNumber"]).Value;\r
+ string newTelephone = "+972 3 6078596";\r
+\r
+ // UsePropertyCache - true\r
+ de.UsePropertyCache = true;\r
+ ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = newTelephone;\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);\r
+\r
+ DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ //check that on server there is still an old value\r
+ Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);\r
+\r
+ de.CommitChanges();\r
+\r
+ cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ // check that new value is updated on the server\r
+ Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,newTelephone);\r
+\r
+ // UsePropertyCache - false\r
+ de = new DirectoryEntry(barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ de.UsePropertyCache = false;\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);\r
+ ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = oldTelephone;\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,oldTelephone);\r
+\r
+ cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ // check that new value is updated on the server\r
+ Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);\r
+\r
+ de.CommitChanges(); // this should do nothing\r
+ }\r
+\r
+\r
+ [Test]\r
+ [ExpectedException(typeof(NotImplementedException))]\r
+ public void DirectoryEntry_CopyTo()\r
+ {\r
+ string barakTsabariDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ DirectoryEntry cnBarakTsabari = new DirectoryEntry( barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ cnBarakTsabari.CopyTo(de);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_DeleteTree()\r
+ {\r
+ string barakTsabariDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+\r
+ de = new DirectoryEntry(barakTsabariDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ \r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));\r
+\r
+ de.DeleteTree();\r
+ de.CommitChanges();\r
+\r
+ Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN));\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Exists()\r
+ {\r
+ string barakTsabariDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ string johnSmithDN = LDAPServerRoot + "cn=John Smith,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ string humanResourcesOU = LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDN));\r
+ Assert.IsTrue(DirectoryEntry.Exists(johnSmithDN));\r
+ Assert.IsTrue(DirectoryEntry.Exists(humanResourcesOU));\r
+\r
+ Assert.IsFalse(DirectoryEntry.Exists(barakTsabariDN + ",dc=mono"));\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_MoveTo_De()\r
+ {\r
+ string barakTsabariHumanResourcesDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ string barakTsabariDevQaDN = LDAPServerRoot + "cn=Barak Tsabari,ou=DevQA,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ string devQaOU = LDAPServerRoot + "ou=DevQA,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ barakTsabariDE.MoveTo(devQaDE);\r
+ barakTsabariDE.CommitChanges();\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));\r
+\r
+ string humanRwsourcesOU = LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ barakTsabariDE.MoveTo(humanResourcesDE);\r
+ barakTsabariDE.CommitChanges();\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectoryEntry_MoveTo_DeStr()\r
+ {\r
+ string barakTsabariHumanResourcesDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ string barakTsabariDevQaDN = LDAPServerRoot + "cn=My Name,ou=DevQA,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariHumanResourcesDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ string devQaOU = LDAPServerRoot + "ou=DevQA,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ barakTsabariDE.MoveTo(devQaDE,"cn=My Name");\r
+ barakTsabariDE.CommitChanges();\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariDevQaDN));\r
+\r
+ string humanRwsourcesOU = LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry humanResourcesDE = new DirectoryEntry( humanRwsourcesOU,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ barakTsabariDE.MoveTo(humanResourcesDE,"cn=Barak Tsabari");\r
+ barakTsabariDE.CommitChanges();\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectoryEntry_RefreshCache()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+ de.UsePropertyCache = true;\r
+ \r
+ string newValue = "Just a company";\r
+ string oldValue = (string)((PropertyValueCollection)de.Properties["description"]).Value;\r
+ ((PropertyValueCollection)de.Properties["description"]).Value = newValue;\r
+ \r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);\r
+\r
+ de.RefreshCache();\r
+\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,oldValue); \r
+ }\r
+\r
+ [Test]\r
+ public void DirectoryEntry_RefreshCache_StrArr()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString);\r
+ de.UsePropertyCache = true;\r
+ \r
+ string newValue = "Just a company";\r
+ string oldValue = (string)((PropertyValueCollection)de.Properties["description"]).Value;\r
+ ((PropertyValueCollection)de.Properties["description"]).Value = newValue;\r
+ \r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);\r
+\r
+ de.RefreshCache(new string[] {"cn"});\r
+\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,newValue);\r
+\r
+ de.RefreshCache(new string[] {"description"});\r
+\r
+ Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,oldValue); \r
+ }\r
+\r
+ [Test]\r
+ public void DirectoryEntry_Rename()\r
+ {\r
+ string barakTsabariOldDN = LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+ string barakTsabariNewDN = LDAPServerRoot + "cn=My Name,ou=Human Resources,ou=people,dc=myhosting,dc=example";\r
+\r
+ DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariOldDN,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ barakTsabariDE.Rename("cn=My Name");\r
+ barakTsabariDE.CommitChanges();\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariNewDN));\r
+\r
+ barakTsabariDE.Rename("cn=Barak Tsabari");\r
+ barakTsabariDE.CommitChanges();\r
+\r
+ Assert.IsTrue(DirectoryEntry.Exists(barakTsabariOldDN));\r
+ }\r
+\r
+ #endregion Tests\r
+ }\r
+}\r
--- /dev/null
+//\r
+// DirectoryServicesDirectorySearcherTest.cs -\r
+// NUnit Test Cases for DirectoryServices.DirectorySearcher\r
+//\r
+// Author:\r
+// Boris Kirzner <borisk@mainsoft.com>\r
+//\r
+using NUnit.Framework;\r
+using System;\r
+using System.DirectoryServices;\r
+using System.Collections;\r
+\r
+namespace MonoTests.System.DirectoryServices \r
+{\r
+ [TestFixture]\r
+ [Category ("InetAccess")]\r
+ public class DirectoryServicesDirectorySearcherTest\r
+ {\r
+ #region Fields\r
+\r
+ static string LDAPServerRoot;\r
+ static string LDAPServerConnectionString;\r
+ static string LDAPServerUsername;\r
+ static string LDAPServerPassword;\r
+ static DirectoryEntry de;\r
+ static DirectorySearcher ds;\r
+\r
+ #endregion // Fields\r
+\r
+ #region SetUp and TearDown\r
+\r
+ [TestFixtureSetUp]\r
+ public void TestFixtureSetUp()\r
+ {\r
+ de = null; \r
+ string ldapServerName = Environment.GetEnvironmentVariable("MONO_LDAP_TEST_SERVER");\r
+ Assert.IsFalse((ldapServerName == null || ldapServerName == String.Empty),"This test fixture requires environment variable MONO_LDAP_TEST_SERVER to be set up to LDAP server name.");\r
+ LDAPServerRoot = "LDAP://" + ldapServerName + "/";\r
+ LDAPServerConnectionString = LDAPServerRoot + "dc=myhosting,dc=example";\r
+ LDAPServerUsername = "cn=Manager,dc=myhosting,dc=example";\r
+ LDAPServerPassword = "secret";\r
+ }\r
+\r
+\r
+ [TestFixtureTearDown]\r
+ public void TestFixtureTearDown()\r
+ {\r
+ ds = null;\r
+ de = null;\r
+ }\r
+\r
+\r
+ [SetUp]\r
+ public void SetUp()\r
+ {\r
+ #region Initialize basics\r
+\r
+ DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");\r
+ ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouPeople.Properties["description"].Value = "All people in organisation";\r
+ ouPeople.Properties["ou"].Value = "people";\r
+ ouPeople.CommitChanges();\r
+\r
+ #endregion // Initialize basics\r
+\r
+ #region Human Resources\r
+ \r
+ DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");\r
+ ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouHumanResources.Properties["ou"].Value = "Human Resources";\r
+ ouHumanResources.CommitChanges();\r
+\r
+ DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");\r
+ cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";\r
+ cnJohnSmith.Properties["cn"].Value = "John Smith";\r
+ cnJohnSmith.Properties["description"].Value = "Very clever person";\r
+ cnJohnSmith.Properties["ou"].Value = "Human Resources";\r
+ cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";\r
+ cnJohnSmith.CommitChanges();\r
+\r
+ DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
+ cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
+ cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
+ cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
+ cnBarakTsabari.CommitChanges();\r
+\r
+ #endregion // Human Resources\r
+\r
+ #region R&D\r
+\r
+ DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");\r
+ ouRnD.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouRnD.Properties["ou"].Value = "R&D";\r
+ ouRnD.CommitChanges();\r
+\r
+ DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";\r
+ cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");\r
+ cnYossiCohen.Properties["sn"].Value = "Cohen";\r
+ cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";\r
+ cnYossiCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnUziCohen.Properties["cn"].Value = "Uzi Cohen";\r
+ cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
+ ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");\r
+ cnUziCohen.Properties["sn"].Value = "Cohen";\r
+ cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
+ cnUziCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";\r
+ cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");\r
+ cnDanielCohen.Properties["sn"].Value = "Cohen";\r
+ cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";\r
+ cnDanielCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnSaraCohen.Properties["cn"].Value = "Sara Cohen";\r
+ cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");\r
+ cnSaraCohen.Properties["sn"].Value = "Cohen";\r
+ cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";\r
+ cnSaraCohen.CommitChanges();\r
+\r
+ #endregion // R&D\r
+\r
+ #region DevQA\r
+\r
+ DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");\r
+ ouDevQA.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouDevQA.Properties["ou"].Value = "DevQA";\r
+ ouDevQA.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielSmith.Properties["cn"].Value = "Daniel Smith";\r
+ cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";\r
+ cnDanielSmith.Properties["l"].Value = "Santa Clara";\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");\r
+ cnDanielSmith.Properties["sn"].Value = "Smith";\r
+ cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";\r
+ cnDanielSmith.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";\r
+ cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");\r
+ cnDanielMorgan.Properties["sn"].Value = "Morgan";\r
+ cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";\r
+ cnDanielMorgan.CommitChanges();\r
+\r
+ #endregion // DevQA\r
+\r
+ #region Manager\r
+\r
+ DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");\r
+ cnManager.Properties["objectClass"].Value = "organizationalRole";\r
+ cnManager.Properties["cn"].Value = "Manager";\r
+ cnManager.CommitChanges();\r
+\r
+ DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";\r
+ cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");\r
+ cnUziCohen_.Properties["sn"].Value = "Cohen";\r
+ cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
+ cnUziCohen_.CommitChanges();\r
+\r
+ #endregion // Manager\r
+\r
+ }\r
+\r
+\r
+ [TearDown]\r
+ public void TearDown()\r
+ {\r
+ ds = null;\r
+ de = null;\r
+\r
+ DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ \r
+ foreach(DirectoryEntry child in root.Children) {\r
+ DeleteTree_DFS(child);\r
+ } \r
+ }\r
+\r
+\r
+ private void DeleteTree_DFS(DirectoryEntry de)\r
+ {\r
+ foreach(DirectoryEntry child in de.Children) {\r
+ DeleteTree_DFS(child);\r
+ }\r
+ de.DeleteTree();\r
+ de.CommitChanges();\r
+ }\r
+\r
+ #endregion //SetUp and TearDown\r
+\r
+ #region Tests\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher()\r
+ {\r
+ ds = new DirectorySearcher();\r
+\r
+ Assert.AreEqual(ds.Filter,"(objectClass=*)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_De()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.SearchRoot.Name,"dc=myhosting");\r
+ Assert.AreEqual(ds.Filter,"(objectClass=*)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_Str()\r
+ {\r
+ ds = new DirectorySearcher("(objectClass=organizationalRole)");\r
+\r
+ Assert.AreEqual(ds.Filter,"(objectClass=organizationalRole)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_DeStr()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de,"(objectClass=organizationalRole)");\r
+\r
+ Assert.AreEqual(ds.SearchRoot.Name,"dc=myhosting");\r
+ Assert.AreEqual(ds.Filter,"(objectClass=organizationalRole)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_StrStrArr()\r
+ {\r
+ string[] properties = new string[] {"objectClass","ou","cn"};\r
+ ds = new DirectorySearcher("(objectClass=organizationalRole)",properties);\r
+\r
+ Assert.AreEqual(ds.Filter,"(objectClass=organizationalRole)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ foreach(string s in properties) {\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains(s));\r
+ }\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_DeStrStrArr()\r
+ {\r
+ string[] properties = new string[] {"objectClass","ou","cn"};\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de,"(objectClass=organizationalRole)",properties);\r
+\r
+ Assert.AreEqual(ds.SearchRoot.Name,"dc=myhosting");\r
+ Assert.AreEqual(ds.Filter,"(objectClass=organizationalRole)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ foreach(string s in properties) {\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains(s));\r
+ }\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_StrStrArrScp()\r
+ {\r
+ string[] properties = new string[] {"objectClass","ou","cn"};\r
+ ds = new DirectorySearcher("(objectClass=organizationalRole)",properties,SearchScope.Base);\r
+\r
+ Assert.AreEqual(ds.Filter,"(objectClass=organizationalRole)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ foreach(string s in properties) {\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains(s));\r
+ }\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Base);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_DirectorySearcher_DeStrStrArrScp()\r
+ {\r
+ string[] properties = new string[] {"objectClass","ou","cn"};\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de,"(objectClass=organizationalRole)",properties,SearchScope.Base);\r
+\r
+ Assert.AreEqual(ds.SearchRoot.Name,"dc=myhosting");\r
+ Assert.AreEqual(ds.Filter,"(objectClass=organizationalRole)");\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ foreach(string s in properties) {\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains(s));\r
+ }\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Base);\r
+ Assert.AreEqual(ds.CacheResults,true);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_CacheResults()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
+ ds.CacheResults = true;\r
+\r
+ SearchResult result = ds.FindOne();\r
+ DirectoryEntry resultDE = result.GetDirectoryEntry();\r
+\r
+ string oldValue = (string)((PropertyValueCollection)resultDE.Properties["description"]).Value;\r
+ string newValue = "New Description";\r
+\r
+ ((PropertyValueCollection)resultDE.Properties["description"]).Value = newValue;\r
+ Assert.AreEqual(((PropertyValueCollection)resultDE.Properties["description"]).Value,newValue);\r
+\r
+ DirectorySearcher secondDs = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
+ SearchResult secondResult = secondDs.FindOne();\r
+ DirectoryEntry secondResultDE = secondResult.GetDirectoryEntry();\r
+\r
+ Assert.AreEqual(((PropertyValueCollection)secondResultDE.Properties["description"]).Value,oldValue);\r
+\r
+ ((PropertyValueCollection)resultDE.Properties["description"]).Value = oldValue;\r
+ \r
+ \r
+ ds = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
+ ds.CacheResults = false;\r
+ result = ds.FindOne();\r
+ resultDE = result.GetDirectoryEntry();\r
+\r
+ ((PropertyValueCollection)resultDE.Properties["description"]).Value = newValue;\r
+ Assert.AreEqual(((PropertyValueCollection)resultDE.Properties["description"]).Value,newValue);\r
+\r
+ secondDs = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
+ secondResult = secondDs.FindOne();\r
+ secondResultDE = secondResult.GetDirectoryEntry();\r
+\r
+ // LAMESPEC : according to documentation, the value retrieved should be the new one,\r
+ // but actually it is an old one\r
+ Assert.AreEqual(((PropertyValueCollection)secondResultDE.Properties["description"]).Value,oldValue);\r
+\r
+ ((PropertyValueCollection)resultDE.Properties["description"]).Value = oldValue; \r
+ }\r
+\r
+ \r
+ [Test]\r
+ public void DirectorySearcher_ClientTimeout()\r
+ {\r
+ ds = new DirectorySearcher();\r
+\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(-10000000));\r
+\r
+ ds.ClientTimeout = new TimeSpan(500000000);\r
+ Assert.AreEqual(ds.ClientTimeout,new TimeSpan(500000000));\r
+\r
+ ds.ClientTimeout = TimeSpan.MaxValue;\r
+ Assert.AreEqual(ds.ClientTimeout,TimeSpan.MaxValue);\r
+\r
+ ds.ClientTimeout = TimeSpan.MinValue;\r
+ Assert.AreEqual(ds.ClientTimeout,TimeSpan.MinValue);\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_Filter()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+ \r
+ ds.Filter = "(objectClass=person)";\r
+ SearchResultCollection results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,8);\r
+\r
+ ds.Filter = "(|(objectClass=person)(objectClass=organizationalUnit))";\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,12);\r
+\r
+ ds.Filter = "(&(objectClass=person)(objectClass=organizationalUnit))";\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,0);\r
+ }\r
+\r
+\r
+ [Test]\r
+ public void DirectorySearcher_PageSize()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.PageSize,0);\r
+ \r
+ ds.Filter = "(|(objectClass=person)(objectClass=organizationalUnit))";\r
+ SearchResultCollection results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,12);\r
+\r
+ ds.PageSize = 3;\r
+ Assert.AreEqual(ds.PageSize,3);\r
+\r
+ ds.Filter = "(|(objectClass=person)(objectClass=organizationalUnit))";\r
+ results = ds.FindAll();\r
+ // LAMESPEC : according to documentation there should be only 3 results !!!\r
+ Assert.AreEqual(results.Count,12);\r
+\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_PropertiesToLoad()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+\r
+ ds.PropertiesToLoad.Add("cn");\r
+ ds.PropertiesToLoad.Add("ADsPath");\r
+ ds.PropertiesToLoad.Add("objectClass");\r
+\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("cn"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("ADsPath"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("objectClass"));\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ SearchResult result = ds.FindOne();\r
+\r
+ Assert.AreEqual(result.Properties.Count,3);\r
+ Assert.IsTrue(result.Properties.Contains("cn"));\r
+ Assert.IsTrue(result.Properties.Contains("objectClass"));\r
+ Assert.IsTrue(result.Properties.Contains("ADsPath"));\r
+\r
+ \r
+ ds.PropertiesToLoad.Clear();\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+\r
+ ds.PropertiesToLoad.Add("cn");\r
+ ds.PropertiesToLoad.Add("objectClass");\r
+\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,2);\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("cn"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("objectClass"));\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ result = ds.FindOne();\r
+\r
+ Assert.AreEqual(result.Properties.Count,3);\r
+ Assert.IsTrue(result.Properties.Contains("cn"));\r
+ Assert.IsTrue(result.Properties.Contains("objectClass"));\r
+ Assert.IsTrue(result.Properties.Contains("ADsPath"));\r
+\r
+ \r
+ ds.PropertiesToLoad.Clear();\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,0);\r
+\r
+ ds.PropertiesToLoad.Add("cn");\r
+ ds.PropertiesToLoad.Add("dn");\r
+ ds.PropertiesToLoad.Add("objectClass");\r
+\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("cn"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("dn"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("objectClass"));\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ result = ds.FindOne();\r
+\r
+ Assert.AreEqual(result.Properties.Count,3);\r
+ Assert.IsTrue(result.Properties.Contains("cn"));\r
+ Assert.IsTrue(result.Properties.Contains("objectClass"));\r
+ // FIXME : .NET framework threats "dn" as "ADsPath"\r
+ // More on http://www.rlmueller.net/Name_Attributes.htm\r
+ Assert.IsTrue(result.Properties.Contains("ADsPath"));\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_PropertyNamesOnly()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.PropertyNamesOnly,false);\r
+\r
+ // All rpoperties are loaded without values, except "ADsPath"\r
+ ds.PropertyNamesOnly = true;\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ SearchResult result = ds.FindOne();\r
+\r
+ foreach(DictionaryEntry en in result.Properties) {\r
+ if(String.Compare((string)en.Key,"adspath",true) != 0) {\r
+ Assert.AreEqual(((ResultPropertyValueCollection)en.Value).Count,0);\r
+ }\r
+ else {\r
+ Assert.AreEqual(((ResultPropertyValueCollection)en.Value).Count,1);\r
+ } \r
+ }\r
+\r
+\r
+ // all properties are loaded including values\r
+ ds.PropertyNamesOnly = false;\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ result = ds.FindOne();\r
+\r
+ foreach(DictionaryEntry en in result.Properties) {\r
+ Assert.IsTrue(((ResultPropertyValueCollection)en.Value).Count > 0);\r
+ }\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_ReferralChasing()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.ReferralChasing,ReferralChasingOption.External);\r
+\r
+ ds.ReferralChasing = ReferralChasingOption.All;\r
+ Assert.AreEqual(ds.ReferralChasing,ReferralChasingOption.All);\r
+\r
+ ds.ReferralChasing = ReferralChasingOption.External;\r
+ Assert.AreEqual(ds.ReferralChasing,ReferralChasingOption.External);\r
+\r
+ ds.ReferralChasing = ReferralChasingOption.None;\r
+ Assert.AreEqual(ds.ReferralChasing,ReferralChasingOption.None);\r
+\r
+ ds.ReferralChasing = ReferralChasingOption.Subordinate;\r
+ Assert.AreEqual(ds.ReferralChasing,ReferralChasingOption.Subordinate);\r
+\r
+ // FIXME : currently we do not have an infrastucture for good testing of this feature\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_SearchRoot()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher();\r
+ ds.SearchRoot = de;\r
+\r
+ Assert.AreEqual(ds.SearchRoot.Name,"dc=myhosting");\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ SearchResultCollection results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,8);\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "ou=people,dc=myhosting,dc=example",\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds.SearchRoot = de;\r
+ Assert.AreEqual(ds.SearchRoot.Name,"ou=people");\r
+\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,7);\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example",\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds.SearchRoot = de;\r
+ Assert.AreEqual(ds.SearchRoot.Name,"ou=Human Resources");\r
+\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,1);\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_SearchScope()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+ \r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+\r
+ ds.SearchScope = SearchScope.Base;\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Base);\r
+\r
+ ds.Filter = "(objectClass=organizationalUnit)";\r
+ SearchResultCollection results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,0);\r
+\r
+ ds.SearchScope = SearchScope.OneLevel;\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.OneLevel);\r
+\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,1);\r
+\r
+ ds.SearchScope = SearchScope.Subtree;\r
+ Assert.AreEqual(ds.SearchScope,SearchScope.Subtree);\r
+\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,4);\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_ServerPageTimeLimit()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.ServerPageTimeLimit,new TimeSpan(-10000000));\r
+\r
+ // According to spec PageSize should be set to a value that is not the default of -1\r
+ ds.PageSize = 5;\r
+ ds.ServerPageTimeLimit = new TimeSpan(500000000);\r
+ Assert.AreEqual(ds.ServerPageTimeLimit,new TimeSpan(500000000));\r
+\r
+ ds.ServerPageTimeLimit = TimeSpan.MaxValue;\r
+ Assert.AreEqual(ds.ServerPageTimeLimit,TimeSpan.MaxValue);\r
+\r
+ ds.ServerPageTimeLimit = TimeSpan.MinValue;\r
+ Assert.AreEqual(ds.ServerPageTimeLimit,TimeSpan.MinValue);\r
+\r
+ // FIXME : currently we do not have an infrastucture for good testing of this feature\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_ServerTimeLimit()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.ServerTimeLimit,new TimeSpan(-10000000));\r
+\r
+ // According to spec PageSize should be set to a value that is not the default of -1\r
+ ds.PageSize = 5;\r
+ ds.ServerTimeLimit = new TimeSpan(500000000);\r
+ Assert.AreEqual(ds.ServerTimeLimit,new TimeSpan(500000000));\r
+\r
+ ds.ServerTimeLimit = TimeSpan.MaxValue;\r
+ Assert.AreEqual(ds.ServerTimeLimit,TimeSpan.MaxValue);\r
+\r
+ ds.ServerTimeLimit = TimeSpan.MinValue;\r
+ Assert.AreEqual(ds.ServerTimeLimit,TimeSpan.MinValue);\r
+\r
+ // FIXME : currently we do not have an infrastucture for good testing of this feature\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_SizeLimit()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ Assert.AreEqual(ds.SizeLimit,0);\r
+ \r
+ ds.Filter = "(|(objectClass=person)(objectClass=organizationalUnit))";\r
+ SearchResultCollection results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,12);\r
+\r
+ ds.SizeLimit = 3;\r
+ Assert.AreEqual(ds.SizeLimit,3);\r
+\r
+ ds.Filter = "(|(objectClass=person)(objectClass=organizationalUnit))";\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,3);\r
+\r
+ ds.SizeLimit = Int32.MaxValue;\r
+ Assert.AreEqual(ds.SizeLimit,Int32.MaxValue);\r
+\r
+ ds.Filter = "(|(objectClass=person)(objectClass=organizationalUnit))";\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,12);\r
+\r
+ }\r
+\r
+ [Test]\r
+ [ExpectedException(typeof(ArgumentException))]\r
+ public void DirectorySearcher_SizeLimit_Neg()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+ ds.SizeLimit = -1;\r
+ Assert.AreEqual(ds.SizeLimit,-1);\r
+\r
+ SearchResultCollection results = ds.FindAll();\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_Sort()\r
+ {\r
+ // FIXME : howto create good sorting\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_FindAll()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ SearchResultCollection results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,8);\r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example",\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ results = ds.FindAll();\r
+ Assert.AreEqual(results.Count,3);\r
+ }\r
+\r
+ [Test]\r
+ public void DirectorySearcher_FindOne()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ ds.Filter = "(objectClass=person)";\r
+ SearchResult result = ds.FindOne();\r
+ Assert.IsNotNull(result);\r
+ Assert.AreEqual(result.GetDirectoryEntry().Name,"cn=Barak Tsabari");\r
+ \r
+\r
+ de = new DirectoryEntry(LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example",\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ ds = new DirectorySearcher(de);\r
+\r
+ result = ds.FindOne();\r
+ Assert.IsNotNull(result);\r
+ Assert.AreEqual(result.GetDirectoryEntry().Name,"ou=Human Resources");\r
+\r
+ ds.Filter = "(objectClass=Barak Tsabari)";\r
+ result = ds.FindOne();\r
+ Assert.IsNull(result);\r
+ }\r
+\r
+\r
+ #endregion Tests\r
+ }\r
+}\r
+\r
--- /dev/null
+//\r
+// DirectoryServicesSearchResultTest.cs -\r
+// NUnit Test Cases for DirectoryServices.SearchResult\r
+//\r
+// Author:\r
+// Boris Kirzner <borisk@mainsoft.com>\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.DirectoryServices;\r
+\r
+namespace MonoTests.System.DirectoryServices \r
+{\r
+ [TestFixture]\r
+ [Category ("InetAccess")]\r
+ public class DirectoryServicesSearchResultTest\r
+ {\r
+ #region Fields\r
+\r
+ static string LDAPServerRoot;\r
+ static string LDAPServerConnectionString;\r
+ static string LDAPServerUsername;\r
+ static string LDAPServerPassword;\r
+ static DirectoryEntry de;\r
+ static DirectorySearcher ds;\r
+\r
+ #endregion // Fields\r
+\r
+ #region SetUp and TearDown\r
+\r
+ [TestFixtureSetUp]\r
+ public void TestFixtureSetUp()\r
+ {\r
+ de = null;\r
+ string ldapServerName = Environment.GetEnvironmentVariable("MONO_LDAP_TEST_SERVER");\r
+ Assert.IsFalse((ldapServerName == null || ldapServerName == String.Empty),"This test fixture requires environment variable MONO_LDAP_TEST_SERVER to be set up to LDAP server name.");\r
+ LDAPServerRoot = "LDAP://" + ldapServerName + "/";\r
+ LDAPServerConnectionString = LDAPServerRoot + "dc=myhosting,dc=example";\r
+ LDAPServerUsername = "cn=Manager,dc=myhosting,dc=example";\r
+ LDAPServerPassword = "secret";\r
+ }\r
+\r
+\r
+ [TestFixtureTearDown]\r
+ public void TestFixtureTearDown()\r
+ {\r
+ de = null;\r
+ }\r
+\r
+\r
+ [SetUp]\r
+ public void SetUp()\r
+ {\r
+ #region Initialize basics\r
+\r
+ DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");\r
+ ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouPeople.Properties["description"].Value = "All people in organisation";\r
+ ouPeople.Properties["ou"].Value = "people";\r
+ ouPeople.CommitChanges();\r
+\r
+ #endregion // Initialize basics\r
+\r
+ #region Human Resources\r
+ \r
+ DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");\r
+ ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouHumanResources.Properties["ou"].Value = "Human Resources";\r
+ ouHumanResources.CommitChanges();\r
+\r
+ DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");\r
+ cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";\r
+ cnJohnSmith.Properties["cn"].Value = "John Smith";\r
+ cnJohnSmith.Properties["description"].Value = "Very clever person";\r
+ cnJohnSmith.Properties["ou"].Value = "Human Resources";\r
+ cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";\r
+ cnJohnSmith.CommitChanges();\r
+\r
+ DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
+ cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");\r
+ ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");\r
+ cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
+ cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
+ cnBarakTsabari.CommitChanges();\r
+\r
+ #endregion // Human Resources\r
+\r
+ #region R&D\r
+\r
+ DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");\r
+ ouRnD.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouRnD.Properties["ou"].Value = "R&D";\r
+ ouRnD.CommitChanges();\r
+\r
+ DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";\r
+ cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");\r
+ cnYossiCohen.Properties["sn"].Value = "Cohen";\r
+ cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";\r
+ cnYossiCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnUziCohen.Properties["cn"].Value = "Uzi Cohen";\r
+ cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
+ ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");\r
+ cnUziCohen.Properties["sn"].Value = "Cohen";\r
+ cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
+ cnUziCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";\r
+ cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");\r
+ cnDanielCohen.Properties["sn"].Value = "Cohen";\r
+ cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";\r
+ cnDanielCohen.CommitChanges();\r
+\r
+ DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnSaraCohen.Properties["cn"].Value = "Sara Cohen";\r
+ cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");\r
+ cnSaraCohen.Properties["sn"].Value = "Cohen";\r
+ cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";\r
+ cnSaraCohen.CommitChanges();\r
+\r
+ #endregion // R&D\r
+\r
+ #region DevQA\r
+\r
+ DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");\r
+ ouDevQA.Properties["objectClass"].Value = "organizationalUnit";\r
+ ouDevQA.Properties["ou"].Value = "DevQA";\r
+ ouDevQA.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielSmith.Properties["cn"].Value = "Daniel Smith";\r
+ cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";\r
+ cnDanielSmith.Properties["l"].Value = "Santa Clara";\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");\r
+ ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");\r
+ cnDanielSmith.Properties["sn"].Value = "Smith";\r
+ cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";\r
+ cnDanielSmith.CommitChanges();\r
+\r
+ DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";\r
+ cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");\r
+ ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");\r
+ cnDanielMorgan.Properties["sn"].Value = "Morgan";\r
+ cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";\r
+ cnDanielMorgan.CommitChanges();\r
+\r
+ #endregion // DevQA\r
+\r
+ #region Manager\r
+\r
+ DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");\r
+ cnManager.Properties["objectClass"].Value = "organizationalRole";\r
+ cnManager.Properties["cn"].Value = "Manager";\r
+ cnManager.CommitChanges();\r
+\r
+ DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");\r
+ cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";\r
+ cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");\r
+ ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");\r
+ cnUziCohen_.Properties["sn"].Value = "Cohen";\r
+ cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";\r
+ cnUziCohen_.CommitChanges();\r
+\r
+ #endregion // Manager\r
+\r
+ }\r
+\r
+\r
+ [TearDown]\r
+ public void TearDown()\r
+ {\r
+ ds = null;\r
+ de = null;\r
+\r
+ DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+ \r
+ foreach(DirectoryEntry child in root.Children) {\r
+ DeleteTree_DFS(child);\r
+ } \r
+ }\r
+\r
+ private void DeleteTree_DFS(DirectoryEntry de)\r
+ {\r
+ foreach(DirectoryEntry child in de.Children) {\r
+ DeleteTree_DFS(child);\r
+ }\r
+ de.DeleteTree();\r
+ de.CommitChanges();\r
+ }\r
+\r
+ #endregion //SetUp and TearDown\r
+\r
+ #region Tests\r
+\r
+ [Test]\r
+ public void SearchResult_Path()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de);\r
+\r
+ SearchResultCollection results = ds.FindAll();\r
+\r
+ Assert.AreEqual(results[0].Path,LDAPServerRoot + "dc=myhosting,dc=example");\r
+ Assert.AreEqual(results[0].Path,results[0].GetDirectoryEntry().Path);\r
+\r
+ Assert.AreEqual(results[1].Path,LDAPServerRoot + "ou=people,dc=myhosting,dc=example");\r
+ Assert.AreEqual(results[1].Path,results[1].GetDirectoryEntry().Path);\r
+\r
+ Assert.AreEqual(results[2].Path,LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ Assert.AreEqual(results[2].Path,results[2].GetDirectoryEntry().Path);\r
+\r
+ Assert.AreEqual(results[3].Path,LDAPServerRoot + "cn=John Smith,ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ Assert.AreEqual(results[3].Path,results[3].GetDirectoryEntry().Path);\r
+ }\r
+\r
+ [Test]\r
+ public void SearchResult_Properties()\r
+ {\r
+ de = new DirectoryEntry(LDAPServerConnectionString,\r
+ LDAPServerUsername,\r
+ LDAPServerPassword,\r
+ AuthenticationTypes.ServerBind);\r
+\r
+ ds = new DirectorySearcher(de);\r
+\r
+ ds.PropertiesToLoad.Add("cn");\r
+ ds.PropertiesToLoad.Add("ADsPath");\r
+ ds.PropertiesToLoad.Add("objectClass");\r
+\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("cn"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("ADsPath"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("objectClass"));\r
+\r
+ ds.Filter = "((objectClass=person))";\r
+ SearchResult result = ds.FindOne();\r
+\r
+ Assert.AreEqual(result.Properties.Count,3);\r
+ Assert.IsTrue(result.Properties.Contains("cn"));\r
+ Assert.IsTrue(result.Properties.Contains("objectClass"));\r
+ Assert.IsTrue(result.Properties.Contains("ADsPath"));\r
+\r
+ ds.PropertiesToLoad.Clear();\r
+\r
+ ds.PropertiesToLoad.Add("cn");\r
+ ds.PropertiesToLoad.Add("objectClass");\r
+ ds.PropertiesToLoad.Add("missingProperty");\r
+\r
+ Assert.AreEqual(ds.PropertiesToLoad.Count,3);\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("cn"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("objectClass"));\r
+ Assert.IsTrue(ds.PropertiesToLoad.Contains("missingProperty"));\r
+\r
+ ds.Filter = "((objectClass=person))";\r
+ result = ds.FindOne();\r
+\r
+ // Properties that does not exists are not loaded\r
+ Assert.AreEqual(result.Properties.Count,3);\r
+ Assert.IsTrue(result.Properties.Contains("cn"));\r
+ Assert.IsTrue(result.Properties.Contains("objectClass"));\r
+ Assert.IsTrue(result.Properties.Contains("ADsPath"));\r
+\r
+ Assert.AreEqual(((ResultPropertyValueCollection)result.Properties["cn"])[0],"Barak Tsabari");\r
+ Assert.AreEqual(((ResultPropertyValueCollection)result.Properties["objectClass"])[0],"person");\r
+ Assert.AreEqual(((ResultPropertyValueCollection)result.Properties["AdsPath"])[0],LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ }\r
+\r
+ #endregion Tests\r
+ }\r
+}\r