SessionTest_Connecting_ServerSendsIgnoreMessageAfterKexInit_StrictKex.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Net.Sockets;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Messages.Transport;
  5. namespace Renci.SshNet.Tests.Classes
  6. {
  7. [TestClass]
  8. public class SessionTest_Connecting_ServerSendsIgnoreMessageAfterKexInit_StrictKex : SessionTest_ConnectingBase
  9. {
  10. protected override bool ServerSupportsStrictKex
  11. {
  12. get
  13. {
  14. return true;
  15. }
  16. }
  17. protected override void ActionAfterKexInit()
  18. {
  19. var ignoreMessage = new IgnoreMessage();
  20. var ignore = ignoreMessage.GetPacket(8, null);
  21. // MitM sends ignore message to client
  22. _ = ServerSocket.Send(ignore, 4, ignore.Length - 4, SocketFlags.None);
  23. // MitM drops server message
  24. ServerOutboundPacketSequence++;
  25. }
  26. [TestMethod]
  27. public void ShouldThrowSshException()
  28. {
  29. var message = Assert.ThrowsException<SshException>(Session.Connect).Message;
  30. Assert.AreEqual("Message type 2 is not valid in the current context.", message);
  31. }
  32. }
  33. }