/TestSuites/MS-AZOD/src/Adapter/AzodTestConfig.cs

https://github.com/microsoft/WindowsProtocolTestSuites · C# · 477 lines · 295 code · 60 blank · 122 comment · 2 complexity · 21b744b1a4882355d16a5ecebb0c2f6d MD5 · raw file

  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using Microsoft.Protocol.TestSuites.Azod.Adapter.Util;
  4. using Microsoft.Protocols.TestTools;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Text.RegularExpressions;
  9. namespace Microsoft.Protocol.TestSuites.Azod.Adapter
  10. {
  11. /// <summary>
  12. /// Test settings read from PTF config file
  13. /// </summary>
  14. public class AzodTestConfig
  15. {
  16. #region Ptf TestSite
  17. public ITestSite TestSite
  18. {
  19. get;
  20. private set;
  21. }
  22. #endregion
  23. #region Global Configuration
  24. /// <summary>
  25. ///Get the KDC domain name from PTF config file
  26. /// </summary>
  27. public string KdcDomainName
  28. {
  29. get;
  30. private set;
  31. }
  32. /// <summary>
  33. ///Get the KDC domain netbios from KDC domain name
  34. /// </summary>
  35. public string KdcDomainNetbios
  36. {
  37. get;
  38. private set;
  39. }
  40. /// <summary>
  41. ///Get KDC domain controller name from PTF config file
  42. /// </summary>
  43. public string KdcName
  44. {
  45. get;
  46. private set;
  47. }
  48. /// <summary>
  49. /// Get KDC domain controller IP from PTF config file
  50. /// </summary>
  51. public string KDCIP
  52. {
  53. get;
  54. private set;
  55. }
  56. /// <summary>
  57. /// Get the KDC domain administrator username from PTF config file
  58. /// </summary>
  59. public string KdcAdminUser
  60. {
  61. get;
  62. private set;
  63. }
  64. /// <summary>
  65. /// Get the KDC domain administrator password from PTF config file
  66. /// </summary>
  67. public string KdcAdminPwd
  68. {
  69. get;
  70. private set;
  71. }
  72. /// <summary>
  73. /// Get the KDC domain claim user username from PTF config file
  74. /// </summary>
  75. public string KdcClaimUser
  76. {
  77. get;
  78. private set;
  79. }
  80. /// <summary>
  81. ///Get the KDC domain claim user password from PTF config file
  82. /// </summary>
  83. public string KdcClaimUserPwd
  84. {
  85. get;
  86. private set;
  87. }
  88. /// <summary>
  89. ///Get the application server name from PTF config file
  90. /// </summary>
  91. public string ApplicationServerName
  92. {
  93. get;
  94. private set;
  95. }
  96. /// <summary>
  97. /// Get the application server name from PTF config file
  98. /// </summary>
  99. public string ApplicationServerIP
  100. {
  101. get;
  102. private set;
  103. }
  104. /// <summary>
  105. /// Get the client computer name from PTF config file
  106. /// </summary>
  107. public string ClientComputerName
  108. {
  109. get;
  110. private set;
  111. }
  112. /// <summary>
  113. /// Get the client local administrator username from PTF config file
  114. /// </summary>
  115. public string ClientAdminUser
  116. {
  117. get;
  118. private set;
  119. }
  120. /// <summary>
  121. /// Get the client local administrator password from PTF config file
  122. /// </summary>
  123. public string ClientAdminPwd
  124. {
  125. get;
  126. private set;
  127. }
  128. /// <summary>
  129. /// Get the client computer IP
  130. /// </summary>
  131. public string ClientComputerIp
  132. {
  133. get;
  134. private set;
  135. }
  136. /// <summary>
  137. /// Get the cross forest name from PTF config file
  138. /// </summary>
  139. public string CrossForestName
  140. {
  141. get;
  142. private set;
  143. }
  144. /// <summary>
  145. /// Get the cross forest DC name from PTF config
  146. /// </summary>
  147. public string CrossForestDCName
  148. {
  149. get;
  150. private set;
  151. }
  152. /// <summary>
  153. /// Get the cross forest DC IP from PTF config
  154. /// </summary>
  155. public string CrossForestDCIP
  156. {
  157. get;
  158. private set;
  159. }
  160. /// <summary>
  161. /// Get the cross forest administrator username from PTF config
  162. /// </summary>
  163. public string CrossForestAdminUser
  164. {
  165. get;
  166. private set;
  167. }
  168. /// <summary>
  169. /// Get the cross forest administrator password from PTF config
  170. /// </summary>
  171. public string CrossForestAdminPwd
  172. {
  173. get;
  174. private set;
  175. }
  176. /// <summary>
  177. /// Get the cross forest application server name from PTF config
  178. /// </summary>
  179. public string CrossForestApplicationServerName
  180. {
  181. get;
  182. private set;
  183. }
  184. /// <summary>
  185. /// Get the cross forest application server IP from PTF config
  186. /// </summary>
  187. public string CrossForestApplicationServerIP
  188. {
  189. get;
  190. private set;
  191. }
  192. /// <summary>
  193. /// Get the cross forest application server share folder from PTF config
  194. /// </summary>
  195. public string CrossForestApplicationServerShareFolder
  196. {
  197. get;
  198. private set;
  199. }
  200. /// <summary>
  201. /// Get Max SMB2 Dialect version supported
  202. /// </summary>
  203. public string MaxSMB2DialectSupported
  204. {
  205. get;
  206. private set;
  207. }
  208. /// <summary>
  209. /// Get the ScriptPath from PTF config file
  210. /// </summary>
  211. public string ScriptPath
  212. {
  213. get;
  214. private set;
  215. }
  216. /// <summary>
  217. /// Get the SiteName from PTF config file
  218. /// </summary>
  219. public string SiteName
  220. {
  221. get;
  222. private set;
  223. }
  224. /// <summary>
  225. /// Get the UNC path
  226. /// </summary>
  227. public string UncPath
  228. {
  229. get;
  230. private set;
  231. }
  232. /// <summary>
  233. /// Get the FQDN UNC path
  234. /// </summary>
  235. public string FQDNUncPath
  236. {
  237. get;
  238. private set;
  239. }
  240. #endregion
  241. #region Case Level MA Capture Configuration
  242. /// <summary>
  243. /// Get the local expected frames path
  244. /// </summary>
  245. public string ExpectedSequenceFilePath
  246. {
  247. get;
  248. set;
  249. }
  250. /// <summary>
  251. /// Get the local netmon capture file path
  252. /// </summary>
  253. public string LocalCapFilePath
  254. {
  255. get;
  256. set;
  257. }
  258. /// <summary>
  259. /// Get the log files folder
  260. /// </summary>
  261. public string DriverLogPath
  262. {
  263. get;
  264. set;
  265. }
  266. /// <summary>
  267. /// Get Central Access Policies to be tested
  268. /// </summary>
  269. public string[] CentralAccessPolicyNames
  270. {
  271. get;
  272. set;
  273. }
  274. /// <summary>
  275. /// Get Central Access Rules to be tested
  276. /// </summary>
  277. public string[] CentralAccessRuleNames
  278. {
  279. get;
  280. set;
  281. }
  282. /// <summary>
  283. /// Get Resource property to be tested
  284. /// </summary>
  285. public string[] ResourcepropertyNames
  286. {
  287. get;
  288. set;
  289. }
  290. #endregion
  291. public AzodTestConfig(ITestSite testSite)
  292. {
  293. this.TestSite = testSite;
  294. this.ScriptPath = testSite.Properties["ScriptPath"];
  295. this.KdcDomainName = testSite.Properties["kdcDomainName"];
  296. this.KdcDomainNetbios = KdcDomainName.Split('.')[0];
  297. this.KdcName = testSite.Properties["kdcName"];
  298. this.KDCIP = testSite.Properties["KDCIP"];
  299. this.KdcAdminUser = testSite.Properties["KdcAdminUser"];
  300. this.KdcAdminPwd = testSite.Properties["KdcAdminPwd"];
  301. this.KdcClaimUser = testSite.Properties["KdcClaimUser"];
  302. this.KdcClaimUserPwd = testSite.Properties["KdcClaimUserPwd"];
  303. this.ApplicationServerName = testSite.Properties["ApplicationServerName"];
  304. this.ApplicationServerIP = testSite.Properties["ApplicationServerIP"];
  305. this.ClientComputerName = testSite.Properties["ClientComputerName"];
  306. this.ClientAdminUser = testSite.Properties["ClientAdminUser"];
  307. this.ClientAdminPwd = testSite.Properties["ClientAdminPwd"];
  308. this.ClientComputerIp = testSite.Properties["ClientComputerIp"];
  309. this.CrossForestName = testSite.Properties["CrossForestName"];
  310. this.CrossForestAdminUser = testSite.Properties["CrossForestAdminUser"];
  311. this.CrossForestAdminPwd = testSite.Properties["CrossForestAdminPwd"];
  312. this.CrossForestDCName = testSite.Properties["CrossForestDCName"];
  313. this.CrossForestDCIP = testSite.Properties["CrossForestDCIP"];
  314. this.CrossForestApplicationServerName = testSite.Properties["CrossForestApplicationServerName"];
  315. this.CrossForestApplicationServerIP = testSite.Properties["CrossForestApplicationServerIP"];
  316. this.CrossForestApplicationServerShareFolder = testSite.Properties["CrossForestApplicationServerShareFolder"];
  317. this.MaxSMB2DialectSupported = testSite.Properties["MaxSMB2DialectSupported"];
  318. this.SiteName = testSite.Properties["SiteName"];
  319. this.UncPath = testSite.Properties["UncPath"];
  320. this.FQDNUncPath = testSite.Properties["FQDNUncPath"];
  321. this.LocalCapFilePath = testSite.Properties["LocalCapFilePath"];
  322. this.ExpectedSequenceFilePath = testSite.Properties["ExpectedSequenceFilePath"];
  323. this.DriverLogPath = testSite.Properties["DriverLogPath"];
  324. this.CentralAccessPolicyNames = TestSite.Properties["CentralAccessPolicyNames"].Replace(" ", "").Split(',');
  325. this.CentralAccessRuleNames = TestSite.Properties["CentralAccessRuleNames"].Replace(" ", "").Split(',');
  326. this.ResourcepropertyNames = TestSite.Properties["ResourcepropertyNames"].Replace(" ", "").Split(',');
  327. }
  328. /// <summary>
  329. /// Get the expected message sequence file by test case name
  330. /// </summary>
  331. /// <param name="caseName">Test case name</param>
  332. public string GetMAExpectedSequenceFile(string caseName)
  333. {
  334. string expectFile = string.Format("{0}-ExpectedFrames.xml", caseName);
  335. return expectFile;
  336. }
  337. /// <summary>
  338. ///update the expected message files according to the PTF config file
  339. ///replace the variables in the xml file
  340. /// </summary>
  341. /// <param name="filename"></param>
  342. public void UpdateExpectedSequenceFile(string filename)
  343. {
  344. StreamReader reader = new StreamReader(filename);
  345. string content = reader.ReadToEnd();
  346. reader.Close();
  347. foreach (var property in this.GetType().GetProperties())
  348. {
  349. if (property.GetValue(this, null) is string[])
  350. {
  351. string[] stringValues = (string[])property.GetValue(this, null);
  352. for (int i = 0; i < stringValues.Length; i++ )
  353. {
  354. //for the properties are denfined with multiple values, split these values by ",".
  355. string[] arrayValues = stringValues[i].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
  356. //replace the expect sequence file with splicted values by the index
  357. //for example: {CentralAccessPolicyNames[0]} will be replaced by the first value of the property CentralAccessPolicyNames in ptfconfig file
  358. content = content.Replace("{" + property.Name + "[" + i + "]}", stringValues[i]);
  359. }
  360. }
  361. else
  362. {
  363. content = Regex.Replace(content, "{" + property.Name + "}", property.GetValue(this, null).ToString());
  364. }
  365. }
  366. StreamWriter writer = new StreamWriter(filename, false);
  367. writer.Write(content);
  368. writer.Close();
  369. }
  370. /// <summary>
  371. /// Get computer roles defined in PTF config file
  372. /// The returned dictionary will be the input for MA Adapter.
  373. /// The MA adapter can map the computer IP and computer name by the dictionary.
  374. /// </summary>
  375. /// <returns></returns>
  376. public Dictionary<string, EndpointRole> GetEndpointRoles()
  377. {
  378. Dictionary<string, EndpointRole> endpointRoles =new Dictionary<string, EndpointRole>();
  379. EndpointRole clientRole = new EndpointRole();
  380. clientRole.Role = ClientComputerName;
  381. clientRole.ComputerName = ClientComputerName;
  382. clientRole.Ipv4 = ClientComputerIp;
  383. clientRole.Ipv6 = null;
  384. clientRole.MAC = null;
  385. EndpointRole APRole = new EndpointRole();
  386. APRole.Role = ApplicationServerName;
  387. APRole.ComputerName = ApplicationServerName;
  388. APRole.Ipv4 = ApplicationServerIP;
  389. APRole.Ipv6 = null;
  390. APRole.MAC = null;
  391. EndpointRole KDCRole = new EndpointRole();
  392. KDCRole.Role = KdcName;
  393. KDCRole.ComputerName = KdcName;
  394. KDCRole.Ipv4 = KDCIP;
  395. KDCRole.Ipv6 = null;
  396. KDCRole.MAC = null;
  397. EndpointRole CrossForestDCRole = new EndpointRole();
  398. CrossForestDCRole.Role = CrossForestDCName;
  399. CrossForestDCRole.ComputerName = CrossForestDCName;
  400. CrossForestDCRole.Ipv4 = CrossForestDCIP;
  401. CrossForestDCRole.Ipv6 = null;
  402. CrossForestDCRole.MAC = null;
  403. EndpointRole CrossForestAPRole = new EndpointRole();
  404. CrossForestAPRole.Role = CrossForestApplicationServerName;
  405. CrossForestAPRole.ComputerName = CrossForestApplicationServerName;
  406. CrossForestAPRole.Ipv4 = CrossForestApplicationServerIP;
  407. CrossForestAPRole.Ipv6 = null;
  408. CrossForestAPRole.MAC = null;
  409. endpointRoles.Add(clientRole.Role, clientRole);
  410. endpointRoles.Add(APRole.Role, APRole);
  411. endpointRoles.Add(KDCRole.Role, KDCRole);
  412. endpointRoles.Add(CrossForestDCRole.Role, CrossForestDCRole);
  413. endpointRoles.Add(CrossForestAPRole.Role, CrossForestAPRole);
  414. return endpointRoles;
  415. }
  416. }
  417. }