PasswordConnectionInfoTest.cs 23 KB

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