Skip to content

Enable all net48 integration tests and stabilise tests #1456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for:
- sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_unit_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_unit_test_net_8_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- sh: echo "Run integration tests"
- sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_8_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
- sh: dotnet test -f net48 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_48_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_48_coverage.xml --filter "Name=ChaCha20Poly1305|Name~Ecdh|Name~Zlib" test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
- sh: dotnet test -f net48 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_48_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_48_coverage.xml --filter Name\!~ECDsa test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

-
matrix:
Expand Down
25 changes: 23 additions & 2 deletions test/Renci.SshNet.IntegrationTests/SshTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,32 @@ public void Ssh_RemotePortForwarding()
var endpoint1 = new IPEndPoint(ipv4HostAddress, 10000);
var endpoint2 = new IPEndPoint(ipv4HostAddress, 10001);

var areBytesReceivedOnListener1 = false;
var areBytesReceivedOnListener2 = false;

var bytesReceivedOnListener1 = new List<byte>();
var bytesReceivedOnListener2 = new List<byte>();

using (var socketListener1 = new AsyncSocketListener(endpoint1))
using (var socketListener2 = new AsyncSocketListener(endpoint2))
using (var bytesReceivedEventOnListener1 = new AutoResetEvent(false))
using (var bytesReceivedEventOnListener2 = new AutoResetEvent(false))
using (var client = new SshClient(_connectionInfoFactory.Create()))
{
socketListener1.BytesReceived += (received, socket) => bytesReceivedOnListener1.AddRange(received);
socketListener1.BytesReceived += (received, socket) =>
{
bytesReceivedOnListener1.AddRange(received);
bytesReceivedEventOnListener1.Set();
};

socketListener1.Start();

socketListener2.BytesReceived += (received, socket) => bytesReceivedOnListener2.AddRange(received);
socketListener2.BytesReceived += (received, socket) =>
{
bytesReceivedOnListener2.AddRange(received);
bytesReceivedEventOnListener2.Set();
};

socketListener2.Start();

client.Connect();
Expand Down Expand Up @@ -706,10 +721,16 @@ public void Ssh_RemotePortForwarding()
s.Close();
}

areBytesReceivedOnListener1 = bytesReceivedEventOnListener1.WaitOne(1000);
areBytesReceivedOnListener2 = bytesReceivedEventOnListener2.WaitOne(1000);

forwardedPort1.Stop();
forwardedPort2.Stop();
}

Assert.IsTrue(areBytesReceivedOnListener1);
Assert.IsTrue(areBytesReceivedOnListener2);

var textReceivedOnListener1 = Encoding.ASCII.GetString(bytesReceivedOnListener1.ToArray());
Assert.AreEqual("ABC\r\n", textReceivedOnListener1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ protected override void SetupMocks()
{
new Thread(() =>
{
_closeTimer.Start();
Thread.Sleep(100);
// raise ChannelCloseReceived event to set waithandle for receiving
// SSH_MSG_CHANNEL_CLOSE message from server which is waited on after
// sending the SSH_MSG_CHANNEL_CLOSE message to the server
SessionMock.Raise(s => s.ChannelCloseReceived += null,
new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
}).Start();
_closeTimer.Start();
try
{
waitHandle.WaitOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected override void SetupMocks()
{
new Thread(() =>
{
_closeTimer.Start();
Thread.Sleep(100);
// raise ChannelCloseReceived event to set waithandle for receiving
// SSH_MSG_CHANNEL_CLOSE message from server which is waited on after
Expand All @@ -74,7 +75,6 @@ protected override void SetupMocks()
new MessageEventArgs<ChannelCloseMessage>(
new ChannelCloseMessage(_localChannelNumber)));
}).Start();
_closeTimer.Start();
try
{
w.WaitOne();
Expand Down
9 changes: 6 additions & 3 deletions test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void ClientVersionIsRenciSshNet()
[TestMethod]
public void IncludeStrictKexPseudoAlgorithmInInitKex()
{
Assert.IsTrue(FirstKexReceived.Wait(1000));
Assert.IsTrue(ServerBytesReceivedRegister.Count > 0);

var kexInitMessage = new KeyExchangeInitMessage();
Expand All @@ -51,7 +52,9 @@ public void IncludeStrictKexPseudoAlgorithmInInitKex()
[TestMethod]
public void ShouldNotIncludeStrictKexPseudoAlgorithmInSubsequentKex()
{
using var kexReceived = new ManualResetEventSlim();
Assert.IsTrue(FirstKexReceived.Wait(1000));

using var subsequentKexReceived = new ManualResetEventSlim();
bool kexContainsPseudoAlg = true;

ServerListener.BytesReceived += ServerListener_BytesReceived;
Expand All @@ -64,13 +67,13 @@ void ServerListener_BytesReceived(byte[] bytesReceived, System.Net.Sockets.Socke
var kexInitMessage = new KeyExchangeInitMessage();
kexInitMessage.Load(bytesReceived, 6, bytesReceived.Length - 6);
kexContainsPseudoAlg = kexInitMessage.KeyExchangeAlgorithms.Contains("[email protected]");
kexReceived.Set();
subsequentKexReceived.Set();
}
}

Session.SendMessage(Session.ClientInitMessage);

Assert.IsTrue(kexReceived.Wait(1000));
Assert.IsTrue(subsequentKexReceived.Wait(1000));
Assert.IsFalse(kexContainsPseudoAlg);

ServerListener.BytesReceived -= ServerListener_BytesReceived;
Expand Down
22 changes: 18 additions & 4 deletions test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Threading;

using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -43,6 +44,7 @@ public abstract class SessionTest_ConnectedBase
protected IList<ExceptionEventArgs> ErrorOccurredRegister { get; private set; }
protected AsyncSocketListener ServerListener { get; private set; }
protected IList<byte[]> ServerBytesReceivedRegister { get; private set; }
protected ManualResetEventSlim FirstKexReceived { get; private set; }
protected Session Session { get; private set; }
protected Socket ClientSocket { get; private set; }
protected Socket ServerSocket { get; private set; }
Expand Down Expand Up @@ -87,6 +89,12 @@ public void TearDown()
ClientSocket.Shutdown(SocketShutdown.Both);
ClientSocket.Dispose();
}

if (FirstKexReceived != null)
{
FirstKexReceived.Dispose();
FirstKexReceived = null;
}
}

protected virtual void SetupData()
Expand All @@ -107,6 +115,7 @@ protected virtual void SetupData()
DisconnectReceivedRegister = new List<MessageEventArgs<DisconnectMessage>>();
ErrorOccurredRegister = new List<ExceptionEventArgs>();
ServerBytesReceivedRegister = new List<byte[]>();
FirstKexReceived = new ManualResetEventSlim();
ServerIdentification = new SshIdentification("2.0", "OurServerStub");
_authenticationStarted = false;
_socketFactory = new SocketFactory();
Expand Down Expand Up @@ -151,11 +160,16 @@ protected virtual void SetupData()
{
ServerBytesReceivedRegister.Add(received);

if (WaitForClientKeyExchangeInit && received.Length > 5 && received[5] == 20)
if (received.Length > 5 && received[5] == 20)
{
// This is the KEXINIT. Send one back.
SendKeyExchangeInit();
WaitForClientKeyExchangeInit = false;
if (WaitForClientKeyExchangeInit)
{
// This is the KEXINIT. Send one back.
SendKeyExchangeInit();
WaitForClientKeyExchangeInit = false;
}

FirstKexReceived.Set();
}
};
ServerListener.Start();
Expand Down