Skip to content

Commit 889f4f6

Browse files
authored
Enable all net48 integration tests (#1456)
* Enable all net48 integration tests * Skip ECDsa in net48 integration tests * Stabilise tests * Stabilise tests * Stabilise tests * Stabilise tests * Spelling
1 parent 58c85ee commit 889f4f6

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for:
2828
- 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
2929
- sh: echo "Run integration tests"
3030
- 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
31-
- 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
31+
- 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
3232

3333
-
3434
matrix:

test/Renci.SshNet.IntegrationTests/SshTests.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,32 @@ public void Ssh_RemotePortForwarding()
655655
var endpoint1 = new IPEndPoint(ipv4HostAddress, 10000);
656656
var endpoint2 = new IPEndPoint(ipv4HostAddress, 10001);
657657

658+
var areBytesReceivedOnListener1 = false;
659+
var areBytesReceivedOnListener2 = false;
660+
658661
var bytesReceivedOnListener1 = new List<byte>();
659662
var bytesReceivedOnListener2 = new List<byte>();
660663

661664
using (var socketListener1 = new AsyncSocketListener(endpoint1))
662665
using (var socketListener2 = new AsyncSocketListener(endpoint2))
666+
using (var bytesReceivedEventOnListener1 = new AutoResetEvent(false))
667+
using (var bytesReceivedEventOnListener2 = new AutoResetEvent(false))
663668
using (var client = new SshClient(_connectionInfoFactory.Create()))
664669
{
665-
socketListener1.BytesReceived += (received, socket) => bytesReceivedOnListener1.AddRange(received);
670+
socketListener1.BytesReceived += (received, socket) =>
671+
{
672+
bytesReceivedOnListener1.AddRange(received);
673+
bytesReceivedEventOnListener1.Set();
674+
};
675+
666676
socketListener1.Start();
667677

668-
socketListener2.BytesReceived += (received, socket) => bytesReceivedOnListener2.AddRange(received);
678+
socketListener2.BytesReceived += (received, socket) =>
679+
{
680+
bytesReceivedOnListener2.AddRange(received);
681+
bytesReceivedEventOnListener2.Set();
682+
};
683+
669684
socketListener2.Start();
670685

671686
client.Connect();
@@ -706,10 +721,16 @@ public void Ssh_RemotePortForwarding()
706721
s.Close();
707722
}
708723

724+
areBytesReceivedOnListener1 = bytesReceivedEventOnListener1.WaitOne(1000);
725+
areBytesReceivedOnListener2 = bytesReceivedEventOnListener2.WaitOne(1000);
726+
709727
forwardedPort1.Stop();
710728
forwardedPort2.Stop();
711729
}
712730

731+
Assert.IsTrue(areBytesReceivedOnListener1);
732+
Assert.IsTrue(areBytesReceivedOnListener2);
733+
713734
var textReceivedOnListener1 = Encoding.ASCII.GetString(bytesReceivedOnListener1.ToArray());
714735
Assert.AreEqual("ABC\r\n", textReceivedOnListener1);
715736

test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ protected override void SetupMocks()
6161
{
6262
new Thread(() =>
6363
{
64+
_closeTimer.Start();
6465
Thread.Sleep(100);
6566
// raise ChannelCloseReceived event to set waithandle for receiving
6667
// SSH_MSG_CHANNEL_CLOSE message from server which is waited on after
6768
// sending the SSH_MSG_CHANNEL_CLOSE message to the server
6869
SessionMock.Raise(s => s.ChannelCloseReceived += null,
6970
new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
7071
}).Start();
71-
_closeTimer.Start();
7272
try
7373
{
7474
waitHandle.WaitOne();

test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected override void SetupMocks()
6666
{
6767
new Thread(() =>
6868
{
69+
_closeTimer.Start();
6970
Thread.Sleep(100);
7071
// raise ChannelCloseReceived event to set waithandle for receiving
7172
// SSH_MSG_CHANNEL_CLOSE message from server which is waited on after
@@ -74,7 +75,6 @@ protected override void SetupMocks()
7475
new MessageEventArgs<ChannelCloseMessage>(
7576
new ChannelCloseMessage(_localChannelNumber)));
7677
}).Start();
77-
_closeTimer.Start();
7878
try
7979
{
8080
w.WaitOne();

test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void ClientVersionIsRenciSshNet()
4141
[TestMethod]
4242
public void IncludeStrictKexPseudoAlgorithmInInitKex()
4343
{
44+
Assert.IsTrue(FirstKexReceived.Wait(1000));
4445
Assert.IsTrue(ServerBytesReceivedRegister.Count > 0);
4546

4647
var kexInitMessage = new KeyExchangeInitMessage();
@@ -51,7 +52,9 @@ public void IncludeStrictKexPseudoAlgorithmInInitKex()
5152
[TestMethod]
5253
public void ShouldNotIncludeStrictKexPseudoAlgorithmInSubsequentKex()
5354
{
54-
using var kexReceived = new ManualResetEventSlim();
55+
Assert.IsTrue(FirstKexReceived.Wait(1000));
56+
57+
using var subsequentKexReceived = new ManualResetEventSlim();
5558
bool kexContainsPseudoAlg = true;
5659

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

7174
Session.SendMessage(Session.ClientInitMessage);
7275

73-
Assert.IsTrue(kexReceived.Wait(1000));
76+
Assert.IsTrue(subsequentKexReceived.Wait(1000));
7477
Assert.IsFalse(kexContainsPseudoAlg);
7578

7679
ServerListener.BytesReceived -= ServerListener_BytesReceived;

test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Net;
55
using System.Net.Sockets;
66
using System.Security.Cryptography;
7+
using System.Threading;
78

89
using Microsoft.VisualStudio.TestTools.UnitTesting;
910

@@ -43,6 +44,7 @@ public abstract class SessionTest_ConnectedBase
4344
protected IList<ExceptionEventArgs> ErrorOccurredRegister { get; private set; }
4445
protected AsyncSocketListener ServerListener { get; private set; }
4546
protected IList<byte[]> ServerBytesReceivedRegister { get; private set; }
47+
protected ManualResetEventSlim FirstKexReceived { get; private set; }
4648
protected Session Session { get; private set; }
4749
protected Socket ClientSocket { get; private set; }
4850
protected Socket ServerSocket { get; private set; }
@@ -87,6 +89,12 @@ public void TearDown()
8789
ClientSocket.Shutdown(SocketShutdown.Both);
8890
ClientSocket.Dispose();
8991
}
92+
93+
if (FirstKexReceived != null)
94+
{
95+
FirstKexReceived.Dispose();
96+
FirstKexReceived = null;
97+
}
9098
}
9199

92100
protected virtual void SetupData()
@@ -107,6 +115,7 @@ protected virtual void SetupData()
107115
DisconnectReceivedRegister = new List<MessageEventArgs<DisconnectMessage>>();
108116
ErrorOccurredRegister = new List<ExceptionEventArgs>();
109117
ServerBytesReceivedRegister = new List<byte[]>();
118+
FirstKexReceived = new ManualResetEventSlim();
110119
ServerIdentification = new SshIdentification("2.0", "OurServerStub");
111120
_authenticationStarted = false;
112121
_socketFactory = new SocketFactory();
@@ -151,11 +160,16 @@ protected virtual void SetupData()
151160
{
152161
ServerBytesReceivedRegister.Add(received);
153162

154-
if (WaitForClientKeyExchangeInit && received.Length > 5 && received[5] == 20)
163+
if (received.Length > 5 && received[5] == 20)
155164
{
156-
// This is the KEXINIT. Send one back.
157-
SendKeyExchangeInit();
158-
WaitForClientKeyExchangeInit = false;
165+
if (WaitForClientKeyExchangeInit)
166+
{
167+
// This is the KEXINIT. Send one back.
168+
SendKeyExchangeInit();
169+
WaitForClientKeyExchangeInit = false;
170+
}
171+
172+
FirstKexReceived.Set();
159173
}
160174
};
161175
ServerListener.Start();

0 commit comments

Comments
 (0)