SessionTest_Connected_ServerIdentificationReceived.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Connection;
  3. namespace Renci.SshNet.Tests.Classes
  4. {
  5. [TestClass]
  6. public class SessionTest_Connected_ServerIdentificationReceived : SessionTest_ConnectedBase
  7. {
  8. protected override void SetupData()
  9. {
  10. base.SetupData();
  11. CallSessionConnectWhenArrange = false;
  12. Session.ServerIdentificationReceived += (s, e) =>
  13. {
  14. if ((e.SshIdentification.SoftwareVersion.StartsWith("OpenSSH_6.5", System.StringComparison.Ordinal) || e.SshIdentification.SoftwareVersion.StartsWith("OpenSSH_6.6", System.StringComparison.Ordinal))
  15. && !e.SshIdentification.SoftwareVersion.StartsWith("OpenSSH_6.6.1", System.StringComparison.Ordinal))
  16. {
  17. _ = ConnectionInfo.KeyExchangeAlgorithms.Remove("curve25519-sha256");
  18. _ = ConnectionInfo.KeyExchangeAlgorithms.Remove("curve25519-sha256@libssh.org");
  19. }
  20. };
  21. }
  22. protected override void Act()
  23. {
  24. }
  25. [TestMethod]
  26. [DataRow("OpenSSH_6.5")]
  27. [DataRow("OpenSSH_6.5p1")]
  28. [DataRow("OpenSSH_6.5 PKIX")]
  29. [DataRow("OpenSSH_6.6")]
  30. [DataRow("OpenSSH_6.6p1")]
  31. [DataRow("OpenSSH_6.6 PKIX")]
  32. public void ShouldExcludeCurve25519KexWhenServerIs(string softwareVersion)
  33. {
  34. ServerIdentification = new SshIdentification("2.0", softwareVersion);
  35. Session.Connect();
  36. Assert.IsFalse(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256"));
  37. Assert.IsFalse(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256@libssh.org"));
  38. }
  39. [TestMethod]
  40. [DataRow("OpenSSH_6.6.1")]
  41. [DataRow("OpenSSH_6.6.1p1")]
  42. [DataRow("OpenSSH_6.6.1 PKIX")]
  43. [DataRow("OpenSSH_6.7")]
  44. [DataRow("OpenSSH_6.7p1")]
  45. [DataRow("OpenSSH_6.7 PKIX")]
  46. public void ShouldIncludeCurve25519KexWhenServerIs(string softwareVersion)
  47. {
  48. ServerIdentification = new SshIdentification("2.0", softwareVersion);
  49. Session.Connect();
  50. Assert.IsTrue(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256"));
  51. Assert.IsTrue(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256@libssh.org"));
  52. }
  53. }
  54. }