PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/System.DirectoryServices/Test/System.DirectoryServices/DirectoryServicesDirectoryEntryTest.cs

https://github.com/ztfuqingvip/mono
C# | 1900 lines | 1373 code | 401 blank | 126 comment | 70 complexity | 515d56f6b0cab2ffd3007124e396e5cb MD5 | raw file
Possible License(s): GPL-2.0, Unlicense, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. //
  2. // DirectoryServicesDirectoryEntryTest.cs -
  3. // NUnit Test Cases for DirectoryServices.DirectoryEntry
  4. //
  5. // Author:
  6. // Boris Kirzner <borisk@mainsoft.com>
  7. //
  8. using NUnit.Framework;
  9. using System;
  10. using System.DirectoryServices;
  11. namespace MonoTests.System.DirectoryServices
  12. {
  13. [TestFixture]
  14. [Category ("InetAccess")]
  15. public class DirectoryServicesDirectoryEntryTest
  16. {
  17. #region Fields
  18. static TestConfiguration configuration;
  19. static DirectoryEntry de;
  20. #endregion // Fields
  21. #region SetUp and TearDown
  22. [TestFixtureSetUp]
  23. public void TestFixtureSetUp()
  24. {
  25. de = null;
  26. configuration = new TestConfiguration ();
  27. }
  28. [TestFixtureTearDown]
  29. public void TestFixtureTearDown()
  30. {
  31. if (de != null)
  32. de.Dispose ();
  33. de = null;
  34. }
  35. [SetUp]
  36. public void SetUp()
  37. {
  38. TearDown();
  39. #region Initialize basics
  40. DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
  41. configuration.Username,
  42. configuration.Password,
  43. configuration.AuthenticationType);
  44. DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");
  45. ouPeople.Properties["objectClass"].Value = "organizationalUnit";
  46. ouPeople.Properties["description"].Value = "All people in organisation";
  47. ouPeople.Properties["ou"].Value = "people";
  48. ouPeople.CommitChanges();
  49. #endregion // Initialize basics
  50. #region Human Resources
  51. DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");
  52. ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";
  53. ouHumanResources.Properties["ou"].Value = "Human Resources";
  54. ouHumanResources.CommitChanges();
  55. DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");
  56. cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";
  57. cnJohnSmith.Properties["cn"].Value = "John Smith";
  58. cnJohnSmith.Properties["description"].Value = "Very clever person";
  59. cnJohnSmith.Properties["ou"].Value = "Human Resources";
  60. cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";
  61. cnJohnSmith.CommitChanges();
  62. DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");
  63. ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
  64. ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
  65. cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
  66. cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
  67. ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
  68. ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
  69. cnBarakTsabari.Properties["sn"].Value = "Tsabari";
  70. cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
  71. cnBarakTsabari.CommitChanges();
  72. #endregion // Human Resources
  73. #region R&D
  74. DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");
  75. ouRnD.Properties["objectClass"].Value = "organizationalUnit";
  76. ouRnD.Properties["ou"].Value = "R&D";
  77. ouRnD.CommitChanges();
  78. DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");
  79. ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");
  80. ((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");
  81. cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";
  82. cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";
  83. ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");
  84. ((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");
  85. cnYossiCohen.Properties["sn"].Value = "Cohen";
  86. cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";
  87. cnYossiCohen.CommitChanges();
  88. DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");
  89. ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");
  90. ((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");
  91. cnUziCohen.Properties["cn"].Value = "Uzi Cohen";
  92. cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";
  93. ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");
  94. ((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");
  95. cnUziCohen.Properties["sn"].Value = "Cohen";
  96. cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";
  97. cnUziCohen.CommitChanges();
  98. DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");
  99. ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");
  100. ((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");
  101. cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";
  102. cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";
  103. ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");
  104. ((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");
  105. cnDanielCohen.Properties["sn"].Value = "Cohen";
  106. cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";
  107. cnDanielCohen.CommitChanges();
  108. DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");
  109. ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");
  110. ((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");
  111. cnSaraCohen.Properties["cn"].Value = "Sara Cohen";
  112. cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";
  113. ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");
  114. ((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");
  115. cnSaraCohen.Properties["sn"].Value = "Cohen";
  116. cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";
  117. cnSaraCohen.CommitChanges();
  118. #endregion // R&D
  119. #region DevQA
  120. DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");
  121. ouDevQA.Properties["objectClass"].Value = "organizationalUnit";
  122. ouDevQA.Properties["ou"].Value = "DevQA";
  123. ouDevQA.CommitChanges();
  124. DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");
  125. ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");
  126. ((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");
  127. cnDanielSmith.Properties["cn"].Value = "Daniel Smith";
  128. cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";
  129. cnDanielSmith.Properties["l"].Value = "Santa Clara";
  130. ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");
  131. ((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");
  132. cnDanielSmith.Properties["sn"].Value = "Smith";
  133. cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";
  134. cnDanielSmith.CommitChanges();
  135. DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");
  136. ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");
  137. ((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");
  138. cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";
  139. cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";
  140. ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");
  141. ((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");
  142. cnDanielMorgan.Properties["sn"].Value = "Morgan";
  143. cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";
  144. cnDanielMorgan.CommitChanges();
  145. #endregion // DevQA
  146. #region Manager
  147. DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");
  148. cnManager.Properties["objectClass"].Value = "organizationalRole";
  149. cnManager.Properties["cn"].Value = "Manager";
  150. cnManager.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1238";
  151. cnManager.CommitChanges();
  152. DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");
  153. ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");
  154. ((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");
  155. cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";
  156. cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";
  157. ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");
  158. ((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");
  159. cnUziCohen_.Properties["sn"].Value = "Cohen";
  160. cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";
  161. cnUziCohen_.CommitChanges();
  162. #endregion // Manager
  163. cnJohnSmith.Dispose();
  164. cnBarakTsabari.Dispose();
  165. ouHumanResources.Dispose();
  166. cnUziCohen.Dispose();
  167. cnYossiCohen.Dispose();
  168. cnDanielCohen.Dispose();
  169. cnSaraCohen.Dispose();
  170. ouRnD.Dispose();
  171. cnDanielSmith.Dispose();
  172. cnDanielMorgan.Dispose();
  173. ouDevQA.Dispose();
  174. cnUziCohen_.Dispose();
  175. cnManager.Dispose();
  176. ouPeople.Dispose();
  177. root.Dispose();
  178. }
  179. [TearDown]
  180. public void TearDown()
  181. {
  182. if (de != null)
  183. de.Dispose ();
  184. de = null;
  185. using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
  186. configuration.Username,
  187. configuration.Password,
  188. configuration.AuthenticationType)) {
  189. foreach(DirectoryEntry child in root.Children) {
  190. DeleteTree_DFS(child);
  191. }
  192. }
  193. }
  194. private void DeleteTree_DFS(DirectoryEntry de)
  195. {
  196. foreach(DirectoryEntry child in de.Children) {
  197. DeleteTree_DFS(child);
  198. }
  199. de.DeleteTree();
  200. de.CommitChanges();
  201. }
  202. #endregion //SetUp and TearDown
  203. #region Tests
  204. [Test]
  205. public void DirectoryEntry_DirectoryEntry()
  206. {
  207. de = new DirectoryEntry();
  208. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
  209. #if !NET_2_0
  210. Assert.AreEqual (de.Password, null);
  211. #endif
  212. Assert.AreEqual(de.Path,String.Empty);
  213. Assert.AreEqual(de.UsePropertyCache,true);
  214. Assert.AreEqual(de.Username,null);
  215. }
  216. [Test]
  217. public void DirectoryEntry_DirectoryEntry_Str()
  218. {
  219. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {
  220. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
  221. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  222. #if !NET_2_0
  223. Assert.AreEqual(de.Password,null);
  224. #endif
  225. Assert.AreEqual(de.Path,configuration.ConnectionString);
  226. Assert.AreEqual(de.SchemaClassName,"organization");
  227. Assert.AreEqual(de.UsePropertyCache,true);
  228. Assert.AreEqual(de.Username,null);
  229. }
  230. }
  231. [Test]
  232. public void DirectoryEntry_DirectoryEntry_StrStrStrAuth()
  233. {
  234. if ((configuration.AuthenticationType != AuthenticationTypes.ServerBind) &&
  235. (configuration.AuthenticationType != AuthenticationTypes.None) &&
  236. (configuration.AuthenticationType != AuthenticationTypes.Anonymous))
  237. return;
  238. #region AuthenticationTypes.Anonymous
  239. using (DirectoryEntry de = new DirectoryEntry( configuration.ConnectionString,
  240. configuration.Username,
  241. configuration.Password,
  242. AuthenticationTypes.Anonymous)){
  243. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
  244. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  245. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  246. //Assert.AreEqual(de.NativeGuid,null);
  247. #if !NET_2_0
  248. Assert.AreEqual(de.Password,configuration.Password);
  249. #endif
  250. Assert.AreEqual(de.Path,configuration.ConnectionString);
  251. Assert.AreEqual(de.SchemaClassName,"organization");
  252. Assert.AreEqual(de.UsePropertyCache,true);
  253. Assert.AreEqual(de.Username,configuration.Username);
  254. }
  255. #endregion //AuthenticationTypes.Anonymous
  256. #region AuthenticationTypes.Delegation
  257. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  258. configuration.Username,
  259. configuration.Password,
  260. AuthenticationTypes.Delegation)){
  261. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
  262. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  263. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  264. //Assert.AreEqual(de.NativeGuid,null);
  265. #if !NET_2_0
  266. Assert.AreEqual(de.Password,configuration.Password);
  267. #endif
  268. Assert.AreEqual(de.Path,configuration.ConnectionString);
  269. Assert.AreEqual(de.SchemaClassName,"organization");
  270. Assert.AreEqual(de.UsePropertyCache,true);
  271. Assert.AreEqual(de.Username,configuration.Username);
  272. }
  273. #endregion //AuthenticationTypes.Delegation
  274. #region AuthenticationTypes.Encryption
  275. // de = new DirectoryEntry( configuration.ConnectionString,
  276. // configuration.Username,
  277. // configuration.Password,
  278. // AuthenticationTypes.Encryption);
  279. //
  280. // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
  281. // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  282. // Assert.AreEqual(de.Name,"dc=myhosting");
  283. // //Assert.AreEqual(de.NativeGuid,null);
  284. // Assert.AreEqual(de.Password,configuration.Password);
  285. // Assert.AreEqual(de.Path,configuration.ConnectionString);
  286. // Assert.AreEqual(de.SchemaClassName,"organization");
  287. // Assert.AreEqual(de.UsePropertyCache,true);
  288. // Assert.AreEqual(de.Username,configuration.Username);
  289. #endregion //AuthenticationTypes.Encryption
  290. #region AuthenticationTypes.FastBind
  291. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  292. configuration.Username,
  293. configuration.Password,
  294. AuthenticationTypes.FastBind)){
  295. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
  296. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  297. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  298. //Assert.AreEqual(de.NativeGuid,null);
  299. #if !NET_2_0
  300. Assert.AreEqual(de.Password,configuration.Password);
  301. #endif
  302. Assert.AreEqual(de.Path,configuration.ConnectionString);
  303. Assert.AreEqual(de.SchemaClassName,"organization");
  304. Assert.AreEqual(de.UsePropertyCache,true);
  305. Assert.AreEqual(de.Username,configuration.Username);
  306. }
  307. #endregion //AuthenticationTypes.FastBind
  308. #region AuthenticationTypes.None
  309. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  310. configuration.Username,
  311. configuration.Password,
  312. AuthenticationTypes.None)){
  313. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
  314. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  315. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  316. //Assert.AreEqual(de.NativeGuid,null);
  317. #if !NET_2_0
  318. Assert.AreEqual(de.Password,configuration.Password);
  319. #endif
  320. Assert.AreEqual(de.Path,configuration.ConnectionString);
  321. Assert.AreEqual(de.SchemaClassName,"organization");
  322. Assert.AreEqual(de.UsePropertyCache,true);
  323. Assert.AreEqual(de.Username,configuration.Username);
  324. }
  325. #endregion //AuthenticationTypes.None
  326. #region AuthenticationTypes.ReadonlyServer
  327. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  328. configuration.Username,
  329. configuration.Password,
  330. AuthenticationTypes.ReadonlyServer)){
  331. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
  332. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  333. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  334. //Assert.AreEqual(de.NativeGuid,null);
  335. #if !NET_2_0
  336. Assert.AreEqual(de.Password,configuration.Password);
  337. #endif
  338. Assert.AreEqual(de.Path,configuration.ConnectionString);
  339. Assert.AreEqual(de.SchemaClassName,"organization");
  340. Assert.AreEqual(de.UsePropertyCache,true);
  341. Assert.AreEqual(de.Username,configuration.Username);
  342. }
  343. #endregion //AuthenticationTypes.ReadonlyServer
  344. #region AuthenticationTypes.Sealing
  345. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  346. configuration.Username,
  347. configuration.Password,
  348. AuthenticationTypes.Sealing)){
  349. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
  350. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  351. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  352. //Assert.AreEqual(de.NativeGuid,null);
  353. #if !NET_2_0
  354. Assert.AreEqual(de.Password,configuration.Password);
  355. #endif
  356. Assert.AreEqual(de.Path,configuration.ConnectionString);
  357. Assert.AreEqual(de.SchemaClassName,"organization");
  358. Assert.AreEqual(de.UsePropertyCache,true);
  359. Assert.AreEqual(de.Username,configuration.Username);
  360. }
  361. #endregion //AuthenticationTypes.Sealing
  362. #region AuthenticationTypes.Secure
  363. // de = new DirectoryEntry(configuration.ConnectionString,
  364. // configuration.Username,
  365. // configuration.Password,
  366. // AuthenticationTypes.Secure);
  367. //
  368. // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
  369. // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  370. // Assert.AreEqual(de.Name,"dc=myhosting");
  371. // //Assert.AreEqual(de.NativeGuid,null);
  372. // Assert.AreEqual(de.Password,configuration.Password);
  373. // Assert.AreEqual(de.Path,configuration.ConnectionString);
  374. // Assert.AreEqual(de.SchemaClassName,"organization");
  375. // Assert.AreEqual(de.UsePropertyCache,true);
  376. // Assert.AreEqual(de.Username,configuration.Username);
  377. #endregion //AuthenticationTypes.Secure
  378. #region AuthenticationTypes.SecureSocketsLayer
  379. // de = new DirectoryEntry(configuration.ConnectionString,
  380. // configuration.Username,
  381. // configuration.Password,
  382. // AuthenticationTypes.SecureSocketsLayer);
  383. //
  384. // Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
  385. // //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  386. // Assert.AreEqual(de.Name,"dc=myhosting");
  387. // //Assert.AreEqual(de.NativeGuid,null);
  388. // Assert.AreEqual(de.Password,configuration.Password);
  389. // Assert.AreEqual(de.Path,configuration.ConnectionString);
  390. // Assert.AreEqual(de.SchemaClassName,"organization");
  391. // Assert.AreEqual(de.UsePropertyCache,true);
  392. // Assert.AreEqual(de.Username,configuration.Username);
  393. #endregion //AuthenticationTypes.SecureSocketsLayer
  394. #region AuthenticationTypes.ServerBind
  395. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  396. configuration.Username,
  397. configuration.Password,
  398. AuthenticationTypes.ServerBind)){
  399. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
  400. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  401. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  402. //Assert.AreEqual(de.NativeGuid,null);
  403. #if !NET_2_0
  404. Assert.AreEqual(de.Password,configuration.Password);
  405. #endif
  406. Assert.AreEqual(de.Path,configuration.ConnectionString);
  407. Assert.AreEqual(de.SchemaClassName,"organization");
  408. Assert.AreEqual(de.UsePropertyCache,true);
  409. Assert.AreEqual(de.Username,configuration.Username);
  410. }
  411. #endregion //AuthenticationTypes.ServerBind
  412. #region AuthenticationTypes.Signing
  413. using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
  414. configuration.Username,
  415. configuration.Password,
  416. AuthenticationTypes.Signing)){
  417. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
  418. //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
  419. Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
  420. //Assert.AreEqual(de.NativeGuid,null);
  421. #if !NET_2_0
  422. Assert.AreEqual(de.Password,configuration.Password);
  423. #endif
  424. Assert.AreEqual(de.Path,configuration.ConnectionString);
  425. Assert.AreEqual(de.SchemaClassName,"organization");
  426. Assert.AreEqual(de.UsePropertyCache,true);
  427. Assert.AreEqual(de.Username,configuration.Username);
  428. }
  429. #endregion //AuthenticationTypes.Signing
  430. }
  431. [Test]
  432. public void DirectoryEntry_Dispose()
  433. {
  434. using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,
  435. configuration.Username,
  436. configuration.Password,
  437. configuration.AuthenticationType)){
  438. DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");
  439. ouPeople.Properties["objectClass"].Value = "organizationalUnit";
  440. ouPeople.Properties["description"].Value = "All printers in organisation";
  441. ouPeople.Properties["ou"].Value = "printers";
  442. ouPeople.CommitChanges();
  443. ouPeople.Rename("ou=anotherPrinters");
  444. ouPeople.CommitChanges();
  445. Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));
  446. }
  447. }
  448. [Test]
  449. public void DirectoryEntry_AuthenticationType()
  450. {
  451. de = new DirectoryEntry();
  452. de.AuthenticationType = AuthenticationTypes.Anonymous;
  453. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
  454. de.AuthenticationType = AuthenticationTypes.Delegation;
  455. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
  456. de.AuthenticationType = AuthenticationTypes.Encryption;
  457. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
  458. de.AuthenticationType = AuthenticationTypes.FastBind;
  459. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
  460. de.AuthenticationType = AuthenticationTypes.None;
  461. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
  462. de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
  463. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
  464. de.AuthenticationType = AuthenticationTypes.Sealing;
  465. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
  466. de.AuthenticationType = AuthenticationTypes.Secure;
  467. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
  468. de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
  469. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
  470. de.AuthenticationType = AuthenticationTypes.ServerBind;
  471. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
  472. de.AuthenticationType = AuthenticationTypes.Signing;
  473. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
  474. de = new DirectoryEntry(configuration.ConnectionString);
  475. de.AuthenticationType = AuthenticationTypes.Anonymous;
  476. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
  477. de.AuthenticationType = AuthenticationTypes.Delegation;
  478. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
  479. de.AuthenticationType = AuthenticationTypes.Encryption;
  480. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
  481. de.AuthenticationType = AuthenticationTypes.FastBind;
  482. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
  483. de.AuthenticationType = AuthenticationTypes.None;
  484. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
  485. de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
  486. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
  487. de.AuthenticationType = AuthenticationTypes.Sealing;
  488. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
  489. de.AuthenticationType = AuthenticationTypes.Secure;
  490. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
  491. de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
  492. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
  493. de.AuthenticationType = AuthenticationTypes.ServerBind;
  494. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
  495. de.AuthenticationType = AuthenticationTypes.Signing;
  496. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
  497. de = new DirectoryEntry(configuration.ConnectionString,
  498. configuration.Username,
  499. configuration.Password,
  500. AuthenticationTypes.None);
  501. de.AuthenticationType = AuthenticationTypes.Anonymous;
  502. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
  503. de.AuthenticationType = AuthenticationTypes.Delegation;
  504. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
  505. de.AuthenticationType = AuthenticationTypes.Encryption;
  506. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
  507. de.AuthenticationType = AuthenticationTypes.FastBind;
  508. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
  509. de.AuthenticationType = AuthenticationTypes.None;
  510. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
  511. de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
  512. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
  513. de.AuthenticationType = AuthenticationTypes.Sealing;
  514. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
  515. de.AuthenticationType = AuthenticationTypes.Secure;
  516. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
  517. de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
  518. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
  519. de.AuthenticationType = AuthenticationTypes.ServerBind;
  520. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
  521. de.AuthenticationType = AuthenticationTypes.Signing;
  522. Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
  523. }
  524. [Test]
  525. public void DirectoryEntry_UsePropertyCache()
  526. {
  527. string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
  528. de = new DirectoryEntry(barakTsabariDN,
  529. configuration.Username,
  530. configuration.Password,
  531. configuration.AuthenticationType);
  532. // UsePropertyCache = true
  533. de.UsePropertyCache = true;
  534. Assert.AreEqual(de.UsePropertyCache,true);
  535. #region Check Properties
  536. // Properties changes are cached
  537. string oldTelephoneNumber = (string)de.Properties["telephoneNumber"].Value;
  538. string newTelephoneNumber = "+972-3-6572345";
  539. de.Properties["telephoneNumber"].Value = newTelephoneNumber;
  540. using (DirectoryEntry barakTsabariDE = new DirectoryEntry( barakTsabariDN,
  541. configuration.Username,
  542. configuration.Password,
  543. configuration.AuthenticationType)){
  544. Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
  545. de.CommitChanges();
  546. }
  547. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  548. configuration.Username,
  549. configuration.Password,
  550. configuration.AuthenticationType)){
  551. Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
  552. // restore object state
  553. de.Properties["telephoneNumber"].Value = oldTelephoneNumber;
  554. de.CommitChanges();
  555. }
  556. #endregion // Check Properties
  557. #region Check DeleteTree
  558. // DeleteTree is not cached
  559. de.DeleteTree();
  560. try {
  561. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  562. configuration.Username,
  563. configuration.Password,
  564. configuration.AuthenticationType)){
  565. barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
  566. barakTsabariDE.CommitChanges();
  567. Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
  568. }
  569. }
  570. catch(AssertionException ae) {
  571. throw ae;
  572. }
  573. catch (Exception e) {
  574. // do nothing
  575. }
  576. // restore object state
  577. using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  578. configuration.Username,
  579. configuration.Password,
  580. configuration.AuthenticationType)){
  581. using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
  582. ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
  583. ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
  584. cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
  585. cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
  586. ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
  587. ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
  588. cnBarakTsabari.Properties["sn"].Value = "Tsabari";
  589. cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
  590. cnBarakTsabari.CommitChanges();
  591. }
  592. }
  593. #endregion // Check DeleteTree
  594. #region Check MoveTo
  595. // Move to is not cached
  596. de = new DirectoryEntry(barakTsabariDN,
  597. configuration.Username,
  598. configuration.Password,
  599. configuration.AuthenticationType);
  600. using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  601. configuration.Username,
  602. configuration.Password,
  603. configuration.AuthenticationType)){
  604. de.MoveTo(ouRnD);
  605. try {
  606. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  607. configuration.Username,
  608. configuration.Password,
  609. configuration.AuthenticationType)){
  610. barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
  611. barakTsabariDE.CommitChanges();
  612. Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
  613. }
  614. }
  615. catch(AssertionException ae) {
  616. throw ae;
  617. }
  618. catch (Exception e) {
  619. // do nothing
  620. }
  621. }
  622. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  623. configuration.Username,
  624. configuration.Password,
  625. configuration.AuthenticationType)){
  626. Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
  627. }
  628. // restore object state
  629. using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  630. configuration.Username,
  631. configuration.Password,
  632. configuration.AuthenticationType)){
  633. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  634. configuration.Username,
  635. configuration.Password,
  636. configuration.AuthenticationType)){
  637. barakTsabariDE.MoveTo(ouHumanResources);
  638. barakTsabariDE.CommitChanges();
  639. }
  640. }
  641. #endregion // Check MoveTo
  642. #region Check Rename
  643. // Rename not chached
  644. de = new DirectoryEntry(barakTsabariDN,
  645. configuration.Username,
  646. configuration.Password,
  647. configuration.AuthenticationType);
  648. de.Rename("cn=MyUser");
  649. try {
  650. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  651. configuration.Username,
  652. configuration.Password,
  653. configuration.AuthenticationType)){
  654. barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
  655. barakTsabariDE.CommitChanges();
  656. Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
  657. }
  658. }
  659. catch(AssertionException ae) {
  660. throw ae;
  661. }
  662. catch (Exception e) {
  663. // do nothing
  664. }
  665. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  666. configuration.Username,
  667. configuration.Password,
  668. configuration.AuthenticationType)){
  669. Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
  670. }
  671. // restore object state
  672. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  673. configuration.Username,
  674. configuration.Password,
  675. configuration.AuthenticationType)){
  676. barakTsabariDE.Rename("cn=Barak Tsabari");
  677. barakTsabariDE.CommitChanges();
  678. }
  679. #endregion // Check Rename
  680. // UsePropertyCache = false
  681. de = new DirectoryEntry(barakTsabariDN,
  682. configuration.Username,
  683. configuration.Password,
  684. configuration.AuthenticationType);
  685. de.UsePropertyCache = false;
  686. Assert.AreEqual(de.UsePropertyCache,false);
  687. #region Check Properties
  688. // Properties changes not cached
  689. de.Properties["telephoneNumber"].Value = newTelephoneNumber;
  690. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  691. configuration.Username,
  692. configuration.Password,
  693. configuration.AuthenticationType)){
  694. }
  695. //Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
  696. #endregion // Check Properties
  697. #region Check DeleteTree
  698. // DeleteTree is not cached
  699. de.DeleteTree();
  700. try {
  701. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  702. configuration.Username,
  703. configuration.Password,
  704. configuration.AuthenticationType)){
  705. barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
  706. barakTsabariDE.CommitChanges();
  707. Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
  708. }
  709. }
  710. catch(AssertionException ae) {
  711. throw ae;
  712. }
  713. catch (Exception e) {
  714. // do nothing
  715. }
  716. // restore object state
  717. using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  718. configuration.Username,
  719. configuration.Password,
  720. configuration.AuthenticationType)){
  721. using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
  722. ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
  723. ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
  724. cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
  725. cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
  726. ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
  727. ((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
  728. cnBarakTsabari.Properties["sn"].Value = "Tsabari";
  729. cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
  730. cnBarakTsabari.CommitChanges();
  731. }
  732. }
  733. #endregion // Check DeleteTree
  734. #region Check MoveTo
  735. // Move to is not cached
  736. de = new DirectoryEntry(barakTsabariDN,
  737. configuration.Username,
  738. configuration.Password,
  739. configuration.AuthenticationType);
  740. using (DirectoryEntry ouRnD = new DirectoryEntry( configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  741. configuration.Username,
  742. configuration.Password,
  743. configuration.AuthenticationType)){
  744. de.MoveTo(ouRnD);
  745. }
  746. try {
  747. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  748. configuration.Username,
  749. configuration.Password,
  750. configuration.AuthenticationType)){
  751. barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
  752. barakTsabariDE.CommitChanges();
  753. Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
  754. }
  755. }
  756. catch(AssertionException ae) {
  757. throw ae;
  758. }
  759. catch (Exception e) {
  760. // do nothing
  761. }
  762. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  763. configuration.Username,
  764. configuration.Password,
  765. configuration.AuthenticationType)){
  766. Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
  767. }
  768. // restore object state
  769. using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  770. configuration.Username,
  771. configuration.Password,
  772. configuration.AuthenticationType)){
  773. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  774. configuration.Username,
  775. configuration.Password,
  776. configuration.AuthenticationType)){
  777. barakTsabariDE.MoveTo(ouHumanResources);
  778. barakTsabariDE.CommitChanges();
  779. }
  780. }
  781. #endregion // Check MoveTo
  782. #region Check Rename
  783. // Rename not chached
  784. de = new DirectoryEntry(barakTsabariDN,
  785. configuration.Username,
  786. configuration.Password,
  787. configuration.AuthenticationType);
  788. de.Rename("cn=MyUser");
  789. try {
  790. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
  791. configuration.Username,
  792. configuration.Password,
  793. configuration.AuthenticationType)){
  794. barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
  795. barakTsabariDE.CommitChanges();
  796. Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
  797. }
  798. }
  799. catch(AssertionException ae) {
  800. throw ae;
  801. }
  802. catch (Exception e) {
  803. // do nothing
  804. }
  805. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  806. configuration.Username,
  807. configuration.Password,
  808. configuration.AuthenticationType)){
  809. Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
  810. }
  811. // restore object state
  812. using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
  813. configuration.Username,
  814. configuration.Password,
  815. configuration.AuthenticationType)){
  816. barakTsabariDE.Rename("cn=Barak Tsabari");
  817. barakTsabariDE.CommitChanges();
  818. }
  819. #endregion // Check Rename
  820. }
  821. [Test]
  822. [Category("NotWorking")]
  823. public void DirectoryEntry_Children()
  824. {
  825. de = new DirectoryEntry();
  826. DirectoryEntries children = de.Children;
  827. //Assert.AreEqual(children.SchemaFilter.Count,0);
  828. de = new DirectoryEntry(configuration.ConnectionString);
  829. children = de.Children;
  830. //Assert.AreEqual(children.SchemaFilter.Count,0);
  831. int childrenCount = 0;
  832. foreach(DirectoryEntry childDe in children) {
  833. childrenCount++;
  834. }
  835. Assert.AreEqual(childrenCount,2);
  836. Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
  837. Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
  838. de = new DirectoryEntry(configuration.ConnectionString,
  839. configuration.Username,
  840. configuration.Password,
  841. configuration.AuthenticationType);
  842. children = de.Children;
  843. //Assert.AreEqual(children.SchemaFilter.Count,0);
  844. childrenCount = 0;
  845. foreach(DirectoryEntry childDe in children) {
  846. childrenCount++;
  847. }
  848. Assert.AreEqual(childrenCount,2);
  849. Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
  850. Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
  851. de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
  852. configuration.Username,
  853. configuration.Password,
  854. configuration.AuthenticationType);
  855. children = de.Children;
  856. Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");
  857. Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");
  858. }
  859. [Test]
  860. public void DirectoryEntry_Name()
  861. {
  862. de = new DirectoryEntry(configuration.ConnectionString);
  863. de = new DirectoryEntry(configuration.ConnectionString,
  864. configuration.Username,
  865. configuration.Password,
  866. configuration.AuthenticationType);
  867. de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
  868. configuration.Username,
  869. configuration.Password,
  870. configuration.AuthenticationType);
  871. Assert.AreEqual(de.Name,"ou=Human Resources");
  872. de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
  873. configuration.Username,
  874. configuration.Password,
  875. configuration.AuthenticationType);
  876. Assert.AreEqual(de.Name,"cn=Barak Tsabari");
  877. }
  878. [Test]
  879. public void DirectoryEntry_Parent()
  880. {
  881. de = new DirectoryEntry(configuration.ConnectionString);
  882. // MS works only with "LDAP" while RFC2255 states "ldap"
  883. Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
  884. de = new DirectoryEntry(configuration.ConnectionString,
  885. configuration.Username,
  886. configuration.Password,
  887. configuration.AuthenticationType);
  888. // MS works only with "LDAP" while RFC2255 states "ldap"
  889. Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
  890. de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
  891. configuration.Username,
  892. configuration.Password,
  893. configuration.AuthenticationType);
  894. // MS works only with "LDAP" while RFC2255 states "ldap"
  895. Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());
  896. }
  897. #if !NET_2_0
  898. [Test]
  899. public void DirectoryEntry_Password()
  900. {
  901. string wrongPassword = "some wrong password";
  902. de = new DirectoryEntry();
  903. Assert.AreEqual(de.Password,null);
  904. de.Password = configuration.Password;
  905. Assert.AreEqual(de.Password,configuration.Password);
  906. de.Password = "";
  907. Assert.AreEqual(de.Password,String.Empty);
  908. de.Password = wrongPassword;
  909. Assert.AreEqual(de.Password,wrongPassword);
  910. de = new DirectoryEntry(configuration.ConnectionString);
  911. de.Password = configuration.Password;
  912. Assert.AreEqual(de.Password,configuration.Password);
  913. de.Password = "";
  914. Assert.AreEqual(de.Password,String.Empty);
  915. de.Password = wrongPassword;
  916. Assert.AreEqual(de.Password,wrongPassword);
  917. de = new DirectoryEntry(configuration.ConnectionString,
  918. configuration.Username,
  919. configuration.Password,
  920. configuration.AuthenticationType);
  921. de.Password = configuration.Password;
  922. Assert.AreEqual(de.Password,configuration.Password);
  923. de.Password = "";
  924. Assert.AreEqual(de.Password,String.Empty);
  925. de.Password = wrongPassword;
  926. Assert.AreEqual(de.Password,wrongPassword);
  927. }
  928. #endif
  929. [Test]
  930. public void DirectoryEntry_Path()
  931. {
  932. string wrongPath = "something that is not LDAP path";
  933. de = new DirectoryEntry();
  934. Assert.AreEqual(de.Path,String.Empty);
  935. de.Path = configuration.ConnectionString;
  936. Assert.AreEqual(de.Path,configuration.ConnectionString);
  937. de.Path = "";
  938. Assert.AreEqual(de.Path,String.Empty);
  939. de.Path = wrongPath;
  940. Assert.AreEqual(de.Path,wrongPath);
  941. de = new DirectoryEntry(configuration.ConnectionString);
  942. de.Path = configuration.ConnectionString;
  943. Assert.AreEqual(de.Path,configuration.ConnectionString);
  944. de.Path = "";
  945. Assert.AreEqual(de.Path,String.Empty);
  946. de.Path = wrongPath;
  947. Assert.AreEqual(de.Path,wrongPath);
  948. de = new DirectoryEntry(configuration.ConnectionString,
  949. configuration.Username,
  950. configuration.Password,
  951. configuration.AuthenticationType);
  952. de.Path = configuration.ConnectionString;
  953. Assert.AreEqual(de.Path,configuration.ConnectionString);
  954. de.Path = "";
  955. Assert.AreEqual(de.Path,String.Empty);
  956. de.Path = wrongPath;
  957. Assert.AreEqual(de.Path,wrongPath);
  958. de = new DirectoryEntry("ldap://myhost:389/ou=people",null,null,AuthenticationTypes.None);
  959. Assert.AreEqual(de.Path,"ldap://myhost:389/ou=people");
  960. de.Path = null;
  961. Assert.AreEqual(de.Path,String.Empty);
  962. }
  963. [Test]
  964. public void DirectoryEntry_Properties1()
  965. {
  966. de = new DirectoryEntry(configuration.ConnectionString);
  967. Assert.AreEqual(de.Properties.Count,3);
  968. Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
  969. Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
  970. de = new DirectoryEntry(configuration.ConnectionString,
  971. configuration.Username,
  972. configuration.Password,
  973. configuration.AuthenticationType);
  974. Assert.AreEqual(de.Properties.Count,3);
  975. Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
  976. Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
  977. // ensure that properties are not accessible after removing an entry from the server
  978. string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
  979. de = new DirectoryEntry(barakTsabariDN,
  980. configuration.Username,
  981. configuration.Password,
  982. configuration.AuthenticationType);
  983. de.DeleteTree();
  984. try {
  985. int i = de.Properties.Count;
  986. Assert.Fail("Properties should not be accessible after deleting an entry from the server");
  987. }
  988. catch(AssertionException ae) {
  989. throw ae;
  990. }
  991. catch(Exception e) {
  992. // supress exception
  993. }
  994. try {
  995. string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;
  996. Assert.Fail("Properties should not be accessible after deleting an entry from the server");
  997. }
  998. catch(AssertionException ae) {
  999. throw ae;
  1000. }
  1001. catch(Exception e) {
  1002. // supress exception
  1003. }
  1004. }
  1005. [Test]
  1006. public void DirectoryEntry_Properties2()
  1007. {
  1008. // delete entry, create a new one (the same) and access properties of the old object
  1009. string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
  1010. de = new DirectoryEntry(barakTsabariDN,
  1011. configuration.Username,
  1012. configuration.Password,
  1013. configuration.AuthenticationType);
  1014. // cause to properties loading
  1015. Assert.AreEqual(de.Properties.Count,6);
  1016. Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
  1017. // delete entry
  1018. de.DeleteTree();
  1019. // the local property chache is still accessible
  1020. Assert.AreEqual(de.Properties.Count,6);
  1021. Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
  1022. de.CommitChanges();
  1023. // the local property chache is still accessible
  1024. ((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";
  1025. // create the entry back again
  1026. using (DirectoryEntry ouHumanResources = new DirectoryEntry( configuration.ServerRoot + "ou=Human Resources,ou=…

Large files files are truncated, but you can click here to view the full file