PasswordAuthenticationMethodTest.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. [TestCategory("integration")]
  60. [Description("Test whether IsConnected is false after disconnect.")]
  61. [Owner("Kenneth_aa")]
  62. public void Test_BaseClient_IsConnected_True_After_Disconnect()
  63. {
  64. // 2012-04-29 - Kenneth_aa
  65. // The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait
  66. // for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning
  67. // anything about Socket's either.
  68. var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD);
  69. using (SftpClient client = new SftpClient(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD))
  70. {
  71. client.Connect();
  72. Assert.AreEqual<bool>(true, client.IsConnected, "IsConnected is not true after Connect() was called.");
  73. client.Disconnect();
  74. Assert.AreEqual<bool>(false, client.IsConnected, "IsConnected is true after Disconnect() was called.");
  75. }
  76. }
  77. /// <summary>
  78. ///A test for Name
  79. ///</summary>
  80. [TestMethod]
  81. [Ignore] // placeholder for actual test
  82. public void NameTest()
  83. {
  84. string username = string.Empty; // TODO: Initialize to an appropriate value
  85. byte[] password = null; // TODO: Initialize to an appropriate value
  86. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value
  87. string actual;
  88. actual = target.Name;
  89. Assert.Inconclusive("Verify the correctness of this test method.");
  90. }
  91. /// <summary>
  92. ///A test for Dispose
  93. ///</summary>
  94. [TestMethod]
  95. [Ignore] // placeholder for actual test
  96. public void DisposeTest()
  97. {
  98. string username = string.Empty; // TODO: Initialize to an appropriate value
  99. byte[] password = null; // TODO: Initialize to an appropriate value
  100. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value
  101. target.Dispose();
  102. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  103. }
  104. /// <summary>
  105. ///A test for Authenticate
  106. ///</summary>
  107. [TestMethod]
  108. [Ignore] // placeholder for actual test
  109. public void AuthenticateTest()
  110. {
  111. string username = string.Empty; // TODO: Initialize to an appropriate value
  112. byte[] password = null; // TODO: Initialize to an appropriate value
  113. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value
  114. Session session = null; // TODO: Initialize to an appropriate value
  115. AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value
  116. AuthenticationResult actual;
  117. actual = target.Authenticate(session);
  118. Assert.AreEqual(expected, actual);
  119. Assert.Inconclusive("Verify the correctness of this test method.");
  120. }
  121. /// <summary>
  122. ///A test for PasswordAuthenticationMethod Constructor
  123. ///</summary>
  124. [TestMethod]
  125. [Ignore] // placeholder for actual test
  126. public void PasswordAuthenticationMethodConstructorTest()
  127. {
  128. string username = string.Empty; // TODO: Initialize to an appropriate value
  129. byte[] password = null; // TODO: Initialize to an appropriate value
  130. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password);
  131. Assert.Inconclusive("TODO: Implement code to verify target");
  132. }
  133. /// <summary>
  134. ///A test for PasswordAuthenticationMethod Constructor
  135. ///</summary>
  136. [TestMethod]
  137. [Ignore] // placeholder for actual test
  138. public void PasswordAuthenticationMethodConstructorTest1()
  139. {
  140. string username = string.Empty; // TODO: Initialize to an appropriate value
  141. string password = string.Empty; // TODO: Initialize to an appropriate value
  142. PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password);
  143. Assert.Inconclusive("TODO: Implement code to verify target");
  144. }
  145. }
  146. }