2
0

SessionTest_Connecting_ServerSendsDisconnectMessageAfterKexInit_StrictKex.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_ServerSendsDisconnectMessageAfterKexInit_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 disconnectMessage = new DisconnectMessage(DisconnectReason.TooManyConnections, "too many connections");
  20. var disconnect = disconnectMessage.GetPacket(8, null);
  21. // Server sends disconnect message to client
  22. _ = ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None);
  23. ServerOutboundPacketSequence++;
  24. }
  25. [TestMethod]
  26. public void DisconnectIsAllowedDuringStrictKex()
  27. {
  28. var exception = Assert.ThrowsException<SshConnectionException>(Session.Connect);
  29. Assert.AreEqual(DisconnectReason.TooManyConnections, exception.DisconnectReason);
  30. }
  31. }
  32. }