2
0

HmacTests.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. [TestMethod]
  52. public void HmacMd5_Etm()
  53. {
  54. DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5Etm);
  55. }
  56. [TestMethod]
  57. public void HmacMd5_96_Etm()
  58. {
  59. DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5_96_Etm);
  60. }
  61. [TestMethod]
  62. public void HmacSha1_Etm()
  63. {
  64. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1Etm);
  65. }
  66. [TestMethod]
  67. public void HmacSha1_96_Etm()
  68. {
  69. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1_96_Etm);
  70. }
  71. [TestMethod]
  72. public void HmacSha2_256_Etm()
  73. {
  74. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256_Etm);
  75. }
  76. [TestMethod]
  77. public void HmacSha2_512_Etm()
  78. {
  79. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512_Etm);
  80. }
  81. private void DoTest(MessageAuthenticationCodeAlgorithm macAlgorithm)
  82. {
  83. _remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms()
  84. .AddMessageAuthenticationCodeAlgorithm(macAlgorithm)
  85. .Update()
  86. .Restart();
  87. using (var client = new SshClient(_connectionInfoFactory.Create()))
  88. {
  89. client.Connect();
  90. client.Disconnect();
  91. }
  92. }
  93. }
  94. }