PasswordConnectionInfoTest.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Common;
  3. using Renci.SshNet.Tests.Common;
  4. using Renci.SshNet.Tests.Properties;
  5. using System;
  6. using System.Net;
  7. namespace Renci.SshNet.Tests.Classes
  8. {
  9. /// <summary>
  10. /// Provides connection information when password authentication method is used
  11. /// </summary>
  12. [TestClass]
  13. public class PasswordConnectionInfoTest : TestBase
  14. {
  15. [TestMethod]
  16. [TestCategory("PasswordConnectionInfo")]
  17. public void Test_PasswordConnectionInfo()
  18. {
  19. var host = Resources.HOST;
  20. var username = Resources.USERNAME;
  21. var password = Resources.PASSWORD;
  22. #region Example PasswordConnectionInfo
  23. var connectionInfo = new PasswordConnectionInfo(host, username, password);
  24. using (var client = new SftpClient(connectionInfo))
  25. {
  26. client.Connect();
  27. // Do something here
  28. client.Disconnect();
  29. }
  30. #endregion
  31. Assert.AreEqual(connectionInfo.Host, Resources.HOST);
  32. Assert.AreEqual(connectionInfo.Username, Resources.USERNAME);
  33. }
  34. [TestMethod]
  35. [TestCategory("PasswordConnectionInfo")]
  36. public void Test_PasswordConnectionInfo_PasswordExpired()
  37. {
  38. var host = Resources.HOST;
  39. var username = Resources.USERNAME;
  40. var password = Resources.PASSWORD;
  41. #region Example PasswordConnectionInfo PasswordExpired
  42. var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
  43. var encoding = new Renci.SshNet.Common.ASCIIEncoding();
  44. connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e)
  45. {
  46. e.NewPassword = encoding.GetBytes("123456");
  47. };
  48. using (var client = new SshClient(connectionInfo))
  49. {
  50. client.Connect();
  51. client.Disconnect();
  52. }
  53. #endregion
  54. Assert.Inconclusive();
  55. }
  56. [TestMethod]
  57. [TestCategory("PasswordConnectionInfo")]
  58. public void Test_PasswordConnectionInfo_AuthenticationBanner()
  59. {
  60. var host = Resources.HOST;
  61. var username = Resources.USERNAME;
  62. var password = Resources.PASSWORD;
  63. #region Example PasswordConnectionInfo AuthenticationBanner
  64. var connectionInfo = new PasswordConnectionInfo(host, username, password);
  65. connectionInfo.AuthenticationBanner += delegate(object sender, AuthenticationBannerEventArgs e)
  66. {
  67. Console.WriteLine(e.BannerMessage);
  68. };
  69. using (var client = new SftpClient(connectionInfo))
  70. {
  71. client.Connect();
  72. // Do something here
  73. client.Disconnect();
  74. }
  75. #endregion
  76. Assert.AreEqual(connectionInfo.Host, Resources.HOST);
  77. Assert.AreEqual(connectionInfo.Username, Resources.USERNAME);
  78. }
  79. [WorkItem(703), TestMethod]
  80. [TestCategory("PasswordConnectionInfo")]
  81. [ExpectedException(typeof(ArgumentException))]
  82. public void Test_ConnectionInfo_Host_Is_Null()
  83. {
  84. var connectionInfo = new PasswordConnectionInfo(null, Resources.USERNAME, Resources.PASSWORD);
  85. }
  86. [WorkItem(703), TestMethod]
  87. [TestCategory("PasswordConnectionInfo")]
  88. [ExpectedException(typeof(ArgumentException))]
  89. public void Test_ConnectionInfo_Username_Is_Null()
  90. {
  91. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD);
  92. }
  93. [WorkItem(703), TestMethod]
  94. [TestCategory("PasswordConnectionInfo")]
  95. [ExpectedException(typeof(ArgumentNullException))]
  96. public void Test_ConnectionInfo_Password_Is_Null()
  97. {
  98. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null);
  99. }
  100. [TestMethod]
  101. [TestCategory("PasswordConnectionInfo")]
  102. [Description("Test passing whitespace to host parameter.")]
  103. [ExpectedException(typeof(ArgumentException))]
  104. public void Test_ConnectionInfo_Host_Is_Whitespace()
  105. {
  106. var connectionInfo = new PasswordConnectionInfo(" ", Resources.USERNAME, Resources.PASSWORD);
  107. }
  108. [TestMethod]
  109. [TestCategory("PasswordConnectionInfo")]
  110. [Description("Test passing whitespace to username parameter.")]
  111. [ExpectedException(typeof(ArgumentException))]
  112. public void Test_ConnectionInfo_Username_Is_Whitespace()
  113. {
  114. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD);
  115. }
  116. [WorkItem(703), TestMethod]
  117. [TestCategory("PasswordConnectionInfo")]
  118. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  119. public void Test_ConnectionInfo_SmallPortNumber()
  120. {
  121. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD);
  122. }
  123. [WorkItem(703), TestMethod]
  124. [TestCategory("PasswordConnectionInfo")]
  125. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  126. public void Test_ConnectionInfo_BigPortNumber()
  127. {
  128. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD);
  129. }
  130. [TestMethod]
  131. [Owner("Kenneth_aa")]
  132. [Description("Test connect to remote server via a SOCKS4 proxy server.")]
  133. [TestCategory("Proxy")]
  134. public void Test_Ssh_Connect_Via_Socks4()
  135. {
  136. var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks4, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
  137. using (var client = new SshClient(connInfo))
  138. {
  139. client.Connect();
  140. var ret = client.RunCommand("ls -la");
  141. client.Disconnect();
  142. }
  143. }
  144. [TestMethod]
  145. [Owner("Kenneth_aa")]
  146. [Description("Test connect to remote server via a TCP SOCKS5 proxy server.")]
  147. [TestCategory("Proxy")]
  148. public void Test_Ssh_Connect_Via_TcpSocks5()
  149. {
  150. var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks5, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
  151. using (var client = new SshClient(connInfo))
  152. {
  153. client.Connect();
  154. var ret = client.RunCommand("ls -la");
  155. client.Disconnect();
  156. }
  157. }
  158. [TestMethod]
  159. [Owner("Kenneth_aa")]
  160. [Description("Test connect to remote server via a HTTP proxy server.")]
  161. [TestCategory("Proxy")]
  162. public void Test_Ssh_Connect_Via_HttpProxy()
  163. {
  164. var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Http, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
  165. using (var client = new SshClient(connInfo))
  166. {
  167. client.Connect();
  168. var ret = client.RunCommand("ls -la");
  169. client.Disconnect();
  170. }
  171. }
  172. /// <summary>
  173. ///A test for Dispose
  174. ///</summary>
  175. [TestMethod()]
  176. public void DisposeTest()
  177. {
  178. string host = string.Empty; // TODO: Initialize to an appropriate value
  179. string username = string.Empty; // TODO: Initialize to an appropriate value
  180. byte[] password = null; // TODO: Initialize to an appropriate value
  181. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); // TODO: Initialize to an appropriate value
  182. target.Dispose();
  183. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  184. }
  185. /// <summary>
  186. ///A test for PasswordConnectionInfo Constructor
  187. ///</summary>
  188. [TestMethod()]
  189. public void PasswordConnectionInfoConstructorTest()
  190. {
  191. string host = string.Empty; // TODO: Initialize to an appropriate value
  192. int port = 0; // TODO: Initialize to an appropriate value
  193. string username = string.Empty; // TODO: Initialize to an appropriate value
  194. byte[] password = null; // TODO: Initialize to an appropriate value
  195. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  196. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  197. int proxyPort = 0; // TODO: Initialize to an appropriate value
  198. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  199. string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value
  200. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword);
  201. Assert.Inconclusive("TODO: Implement code to verify target");
  202. }
  203. /// <summary>
  204. ///A test for PasswordConnectionInfo Constructor
  205. ///</summary>
  206. [TestMethod()]
  207. public void PasswordConnectionInfoConstructorTest1()
  208. {
  209. string host = string.Empty; // TODO: Initialize to an appropriate value
  210. string username = string.Empty; // TODO: Initialize to an appropriate value
  211. byte[] password = null; // TODO: Initialize to an appropriate value
  212. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  213. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  214. int proxyPort = 0; // TODO: Initialize to an appropriate value
  215. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  216. string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value
  217. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword);
  218. Assert.Inconclusive("TODO: Implement code to verify target");
  219. }
  220. /// <summary>
  221. ///A test for PasswordConnectionInfo Constructor
  222. ///</summary>
  223. [TestMethod()]
  224. public void PasswordConnectionInfoConstructorTest2()
  225. {
  226. string host = string.Empty; // TODO: Initialize to an appropriate value
  227. string username = string.Empty; // TODO: Initialize to an appropriate value
  228. byte[] password = null; // TODO: Initialize to an appropriate value
  229. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  230. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  231. int proxyPort = 0; // TODO: Initialize to an appropriate value
  232. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  233. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername);
  234. Assert.Inconclusive("TODO: Implement code to verify target");
  235. }
  236. /// <summary>
  237. ///A test for PasswordConnectionInfo Constructor
  238. ///</summary>
  239. [TestMethod()]
  240. public void PasswordConnectionInfoConstructorTest3()
  241. {
  242. string host = string.Empty; // TODO: Initialize to an appropriate value
  243. string username = string.Empty; // TODO: Initialize to an appropriate value
  244. byte[] password = null; // TODO: Initialize to an appropriate value
  245. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  246. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  247. int proxyPort = 0; // TODO: Initialize to an appropriate value
  248. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort);
  249. Assert.Inconclusive("TODO: Implement code to verify target");
  250. }
  251. /// <summary>
  252. ///A test for PasswordConnectionInfo Constructor
  253. ///</summary>
  254. [TestMethod()]
  255. public void PasswordConnectionInfoConstructorTest4()
  256. {
  257. string host = string.Empty; // TODO: Initialize to an appropriate value
  258. int port = 0; // TODO: Initialize to an appropriate value
  259. string username = string.Empty; // TODO: Initialize to an appropriate value
  260. byte[] password = null; // TODO: Initialize to an appropriate value
  261. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  262. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  263. int proxyPort = 0; // TODO: Initialize to an appropriate value
  264. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  265. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername);
  266. Assert.Inconclusive("TODO: Implement code to verify target");
  267. }
  268. /// <summary>
  269. ///A test for PasswordConnectionInfo Constructor
  270. ///</summary>
  271. [TestMethod()]
  272. public void PasswordConnectionInfoConstructorTest5()
  273. {
  274. string host = string.Empty; // TODO: Initialize to an appropriate value
  275. int port = 0; // TODO: Initialize to an appropriate value
  276. string username = string.Empty; // TODO: Initialize to an appropriate value
  277. byte[] password = null; // TODO: Initialize to an appropriate value
  278. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  279. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  280. int proxyPort = 0; // TODO: Initialize to an appropriate value
  281. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort);
  282. Assert.Inconclusive("TODO: Implement code to verify target");
  283. }
  284. /// <summary>
  285. ///A test for PasswordConnectionInfo Constructor
  286. ///</summary>
  287. [TestMethod()]
  288. public void PasswordConnectionInfoConstructorTest6()
  289. {
  290. string host = string.Empty; // TODO: Initialize to an appropriate value
  291. int port = 0; // TODO: Initialize to an appropriate value
  292. string username = string.Empty; // TODO: Initialize to an appropriate value
  293. byte[] password = null; // TODO: Initialize to an appropriate value
  294. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password);
  295. Assert.Inconclusive("TODO: Implement code to verify target");
  296. }
  297. /// <summary>
  298. ///A test for PasswordConnectionInfo Constructor
  299. ///</summary>
  300. [TestMethod()]
  301. public void PasswordConnectionInfoConstructorTest7()
  302. {
  303. string host = string.Empty; // TODO: Initialize to an appropriate value
  304. string username = string.Empty; // TODO: Initialize to an appropriate value
  305. byte[] password = null; // TODO: Initialize to an appropriate value
  306. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password);
  307. Assert.Inconclusive("TODO: Implement code to verify target");
  308. }
  309. /// <summary>
  310. ///A test for PasswordConnectionInfo Constructor
  311. ///</summary>
  312. [TestMethod()]
  313. public void PasswordConnectionInfoConstructorTest8()
  314. {
  315. string host = string.Empty; // TODO: Initialize to an appropriate value
  316. string username = string.Empty; // TODO: Initialize to an appropriate value
  317. string password = string.Empty; // TODO: Initialize to an appropriate value
  318. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  319. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  320. int proxyPort = 0; // TODO: Initialize to an appropriate value
  321. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  322. string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value
  323. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword);
  324. Assert.Inconclusive("TODO: Implement code to verify target");
  325. }
  326. /// <summary>
  327. ///A test for PasswordConnectionInfo Constructor
  328. ///</summary>
  329. [TestMethod()]
  330. public void PasswordConnectionInfoConstructorTest9()
  331. {
  332. string host = string.Empty; // TODO: Initialize to an appropriate value
  333. string username = string.Empty; // TODO: Initialize to an appropriate value
  334. string password = string.Empty; // TODO: Initialize to an appropriate value
  335. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  336. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  337. int proxyPort = 0; // TODO: Initialize to an appropriate value
  338. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  339. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername);
  340. Assert.Inconclusive("TODO: Implement code to verify target");
  341. }
  342. /// <summary>
  343. ///A test for PasswordConnectionInfo Constructor
  344. ///</summary>
  345. [TestMethod()]
  346. public void PasswordConnectionInfoConstructorTest10()
  347. {
  348. string host = string.Empty; // TODO: Initialize to an appropriate value
  349. string username = string.Empty; // TODO: Initialize to an appropriate value
  350. string password = string.Empty; // TODO: Initialize to an appropriate value
  351. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  352. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  353. int proxyPort = 0; // TODO: Initialize to an appropriate value
  354. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort);
  355. Assert.Inconclusive("TODO: Implement code to verify target");
  356. }
  357. /// <summary>
  358. ///A test for PasswordConnectionInfo Constructor
  359. ///</summary>
  360. [TestMethod()]
  361. public void PasswordConnectionInfoConstructorTest11()
  362. {
  363. string host = string.Empty; // TODO: Initialize to an appropriate value
  364. int port = 0; // TODO: Initialize to an appropriate value
  365. string username = string.Empty; // TODO: Initialize to an appropriate value
  366. string password = string.Empty; // TODO: Initialize to an appropriate value
  367. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  368. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  369. int proxyPort = 0; // TODO: Initialize to an appropriate value
  370. string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value
  371. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername);
  372. Assert.Inconclusive("TODO: Implement code to verify target");
  373. }
  374. /// <summary>
  375. ///A test for PasswordConnectionInfo Constructor
  376. ///</summary>
  377. [TestMethod()]
  378. public void PasswordConnectionInfoConstructorTest12()
  379. {
  380. string host = string.Empty; // TODO: Initialize to an appropriate value
  381. int port = 0; // TODO: Initialize to an appropriate value
  382. string username = string.Empty; // TODO: Initialize to an appropriate value
  383. string password = string.Empty; // TODO: Initialize to an appropriate value
  384. ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value
  385. string proxyHost = string.Empty; // TODO: Initialize to an appropriate value
  386. int proxyPort = 0; // TODO: Initialize to an appropriate value
  387. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort);
  388. Assert.Inconclusive("TODO: Implement code to verify target");
  389. }
  390. /// <summary>
  391. ///A test for PasswordConnectionInfo Constructor
  392. ///</summary>
  393. [TestMethod()]
  394. public void PasswordConnectionInfoConstructorTest13()
  395. {
  396. string host = string.Empty; // TODO: Initialize to an appropriate value
  397. int port = 0; // TODO: Initialize to an appropriate value
  398. string username = string.Empty; // TODO: Initialize to an appropriate value
  399. string password = string.Empty; // TODO: Initialize to an appropriate value
  400. PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password);
  401. Assert.Inconclusive("TODO: Implement code to verify target");
  402. }
  403. /// <summary>
  404. ///A test for PasswordConnectionInfo Constructor
  405. ///</summary>
  406. [TestMethod()]
  407. public void PasswordConnectionInfoConstructorTest14()
  408. {
  409. string host = string.Empty; // TODO: Initialize to an appropriate value
  410. string username = string.Empty; // TODO: Initialize to an appropriate value
  411. string password = string.Empty; // TODO: Initialize to an appropriate value
  412. PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password);
  413. Assert.Inconclusive("TODO: Implement code to verify target");
  414. }
  415. }
  416. }