PasswordAuthenticationMethodTest.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Tests.Common;
  3. using Renci.SshNet.Tests.Properties;
  4. using System;
  5. namespace Renci.SshNet.Tests.Classes
  6. {
  7. /// <summary>
  8. /// Provides functionality to perform password authentication.
  9. /// </summary>
  10. [TestClass]
  11. public partial class PasswordAuthenticationMethodTest : TestBase
  12. {
  13. [TestMethod]
  14. [TestCategory("AuthenticationMethod")]
  15. [Owner("Kenneth_aa")]
  16. [Description("PasswordAuthenticationMethod: Pass null as username, \"valid\" as password.")]
  17. [ExpectedException(typeof(ArgumentException))]
  18. public void Password_Test_Pass_Null_Username()
  19. {
  20. new PasswordAuthenticationMethod(null, "valid");
  21. }
  22. [TestMethod]
  23. [TestCategory("AuthenticationMethod")]
  24. [Owner("Kenneth_aa")]
  25. [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, null as password.")]
  26. [ExpectedException(typeof(ArgumentNullException))]
  27. public void Password_Test_Pass_Null_Password()
  28. {
  29. new PasswordAuthenticationMethod("valid", (string)null);
  30. }
  31. [TestMethod]
  32. [TestCategory("AuthenticationMethod")]
  33. [Owner("Kenneth_aa")]
  34. [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, \"valid\" as password.")]
  35. public void Password_Test_Pass_Valid_Username_And_Password()
  36. {
  37. new PasswordAuthenticationMethod("valid", "valid");
  38. }
  39. [TestMethod]
  40. [TestCategory("AuthenticationMethod")]
  41. [Owner("Kenneth_aa")]
  42. [Description("PasswordAuthenticationMethod: Pass String.Empty as username, \"valid\" as password.")]
  43. [ExpectedException(typeof(ArgumentException))]
  44. public void Password_Test_Pass_Whitespace()
  45. {
  46. new PasswordAuthenticationMethod(string.Empty, "valid");
  47. }
  48. [TestMethod]
  49. [TestCategory("AuthenticationMethod")]
  50. [Owner("Kenneth_aa")]
  51. [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, String.Empty as password.")]
  52. public void Password_Test_Pass_Valid()
  53. {
  54. new PasswordAuthenticationMethod("valid", string.Empty);
  55. }
  56. [TestMethod]
  57. [WorkItem(1140)]
  58. [TestCategory("BaseClient")]
  59. [Description("Test whether IsConnected is false after disconnect.")]
  60. [Owner("Kenneth_aa")]
  61. public void Test_BaseClient_IsConnected_True_After_Disconnect()
  62. {
  63. // 2012-04-29 - Kenneth_aa
  64. // The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait
  65. // for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning
  66. // anything about Socket's either.
  67. var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD);
  68. using (SftpClient client = new SftpClient(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD))
  69. {
  70. client.Connect();
  71. Assert.AreEqual<bool>(true, client.IsConnected, "IsConnected is not true after Connect() was called.");
  72. client.Disconnect();
  73. Assert.AreEqual<bool>(false, client.IsConnected, "IsConnected is true after Disconnect() was called.");
  74. }
  75. }
  76. /// <summary>
  77. ///A test for Name
  78. ///</summary>
  79. [TestMethod()]
  80. public void NameTest()
  81. {
  82. string username = string.Empty; // TODO: Initialize to an appropriate value
  83. byte[] password = null; // TODO: Initialize to an appropriate value
  84. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value
  85. string actual;
  86. actual = target.Name;
  87. Assert.Inconclusive("Verify the correctness of this test method.");
  88. }
  89. /// <summary>
  90. ///A test for Dispose
  91. ///</summary>
  92. [TestMethod()]
  93. public void DisposeTest()
  94. {
  95. string username = string.Empty; // TODO: Initialize to an appropriate value
  96. byte[] password = null; // TODO: Initialize to an appropriate value
  97. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value
  98. target.Dispose();
  99. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  100. }
  101. /// <summary>
  102. ///A test for Authenticate
  103. ///</summary>
  104. [TestMethod()]
  105. public void AuthenticateTest()
  106. {
  107. string username = string.Empty; // TODO: Initialize to an appropriate value
  108. byte[] password = null; // TODO: Initialize to an appropriate value
  109. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value
  110. Session session = null; // TODO: Initialize to an appropriate value
  111. AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value
  112. AuthenticationResult actual;
  113. actual = target.Authenticate(session);
  114. Assert.AreEqual(expected, actual);
  115. Assert.Inconclusive("Verify the correctness of this test method.");
  116. }
  117. /// <summary>
  118. ///A test for PasswordAuthenticationMethod Constructor
  119. ///</summary>
  120. [TestMethod()]
  121. public void PasswordAuthenticationMethodConstructorTest()
  122. {
  123. string username = string.Empty; // TODO: Initialize to an appropriate value
  124. byte[] password = null; // TODO: Initialize to an appropriate value
  125. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password);
  126. Assert.Inconclusive("TODO: Implement code to verify target");
  127. }
  128. /// <summary>
  129. ///A test for PasswordAuthenticationMethod Constructor
  130. ///</summary>
  131. [TestMethod()]
  132. public void PasswordAuthenticationMethodConstructorTest1()
  133. {
  134. string username = string.Empty; // TODO: Initialize to an appropriate value
  135. string password = string.Empty; // TODO: Initialize to an appropriate value
  136. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password);
  137. Assert.Inconclusive("TODO: Implement code to verify target");
  138. }
  139. }
  140. }