HmacTests.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Renci.SshNet.IntegrationTests.Common;
  2. using Renci.SshNet.TestTools.OpenSSH;
  3. namespace Renci.SshNet.IntegrationTests
  4. {
  5. [TestClass]
  6. public class HmacTests : IntegrationTestBase
  7. {
  8. private IConnectionInfoFactory _connectionInfoFactory;
  9. private RemoteSshdConfig _remoteSshdConfig;
  10. [TestInitialize]
  11. public void SetUp()
  12. {
  13. _connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
  14. _remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig();
  15. }
  16. [TestCleanup]
  17. public void TearDown()
  18. {
  19. _remoteSshdConfig?.Reset();
  20. }
  21. [TestMethod]
  22. public void HmacMd5()
  23. {
  24. DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5);
  25. }
  26. [TestMethod]
  27. public void HmacMd5_96()
  28. {
  29. DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5_96);
  30. }
  31. [TestMethod]
  32. public void HmacSha1()
  33. {
  34. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1);
  35. }
  36. [TestMethod]
  37. public void HmacSha1_96()
  38. {
  39. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1_96);
  40. }
  41. [TestMethod]
  42. public void HmacSha2_256()
  43. {
  44. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256);
  45. }
  46. [TestMethod]
  47. public void HmacSha2_512()
  48. {
  49. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512);
  50. }
  51. private void DoTest(MessageAuthenticationCodeAlgorithm macAlgorithm)
  52. {
  53. _remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms()
  54. .AddMessageAuthenticationCodeAlgorithm(macAlgorithm)
  55. .Update()
  56. .Restart();
  57. using (var client = new SshClient(_connectionInfoFactory.Create()))
  58. {
  59. client.Connect();
  60. client.Disconnect();
  61. }
  62. }
  63. }
  64. }