Skip to content

Bump test dependencies #1583

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 13 commits into from
Feb 4, 2025
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
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,17 @@ MA0053.class_with_virtual_member_shoud_be_sealed = true
# This rule is disabled by default, hence we need to explicitly enable it.
dotnet_diagnostic.MA0112.severity = error

# MA0165: Make interpolated string
dotnet_diagnostic.MA0165.severity = none

#### MSTest rules ####

# MSTEST0015: Test method should not be ignored
dotnet_diagnostic.MSTEST0015.severity = suggestion

# MSTEST0032: Assertion condition is always true
dotnet_diagnostic.MSTEST0032.severity = suggestion

#### .NET Compiler Platform code quality rules ####

# CA1002: Do not expose generic lists
Expand Down
18 changes: 11 additions & 7 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ updates:
- package-ecosystem: "docker"
directory: "/test/Renci.SshNet.IntegrationTests/"
schedule:
interval: "weekly"
interval: "monthly"

- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: "weekly"
ignore:
# AsyncInterface must stay at 1.0.0 because of https://github.com/sshnet/SSH.NET/pull/1288
interval: "monthly"
ignore: # See justifications in Directory.Packages.props
- dependency-name: "Microsoft.Bcl.AsyncInterfaces"
# These should stay on LTS .NET Releases

- dependency-name: "System.Formats.Asn1"
update-types: ["version-update:semver-major"]
- dependency-name: "Microsoft.Extensions.Logging.*"

- dependency-name: "Microsoft.Extensions.Logging.Abstractions"
update-types: ["version-update:semver-major"]
groups:
dependencies:
patterns:
- "*"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
28 changes: 16 additions & 12 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.5.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.163" />
<!-- Must be kept at version 1.0.0 or higher, see https://github.com/sshnet/SSH.NET/pull/1288 for details. -->
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.186" />

<!-- Must be kept at version 1.0.0, see https://github.com/sshnet/SSH.NET/pull/1288 for details. -->
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />

<!-- No reason to require later than 6.0.0 at this time. -->
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.2" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.7.3" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.77-alpha" /> <!-- can use stable once 3.7 is released -->
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.6.0.109712" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />

<!-- Should stay on LTS .NET releases. -->
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="Testcontainers" Version="4.0.0" />
<PackageVersion Include="Testcontainers" Version="4.1.0" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Renci.SshNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.AotCompatibilityTestApp", "test\Renci.SshNet.AotCompatibilityTestApp\Renci.SshNet.AotCompatibilityTestApp.csproj", "{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{05229079-6738-42CE-8F73-F4E182929B03}"
ProjectSection(SolutionItems) = preProject
.github\dependabot.yml = .github\dependabot.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{95F25B1A-2B14-4745-9087-43C00CD90EE0}"
ProjectSection(SolutionItems) = preProject
Expand Down
19 changes: 11 additions & 8 deletions src/Renci.SshNet/SshMessageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;

#if NET9_0_OR_GREATER
using System.Threading;
#endif
Expand All @@ -19,7 +22,7 @@ internal sealed class SshMessageFactory
private readonly bool[] _activatedMessagesById;
private readonly Lock _lock = new Lock();

internal static readonly MessageMetadata[] AllMessages = new MessageMetadata[]
private static readonly MessageMetadata[] AllMessages = new MessageMetadata[]
{
new MessageMetadata<KeyExchangeInitMessage>(0, "SSH_MSG_KEXINIT", 20),
new MessageMetadata<NewKeysMessage>(1, "SSH_MSG_NEWKEYS", 21),
Expand Down Expand Up @@ -55,24 +58,22 @@ internal sealed class SshMessageFactory
new MessageMetadata<KeyExchangeEcdhReplyMessage>(31, "SSH_MSG_KEX_ECDH_REPLY", 31),
new MessageMetadata<KeyExchangeHybridReplyMessage>(32, "SSH_MSG_KEX_HYBRID_REPLY", 31)
};

private static readonly Dictionary<string, MessageMetadata> MessagesByName = CreateMessagesByNameMapping();

/// <summary>
/// Defines the highest message number that is currently supported.
/// </summary>
internal const byte HighestMessageNumber = 100;

/// <summary>
/// Defines the total number of supported messages.
/// </summary>
internal const int TotalMessageCount = 33;

/// <summary>
/// Initializes a new instance of the <see cref="SshMessageFactory"/> class.
/// </summary>
public SshMessageFactory()
{
_activatedMessagesById = new bool[TotalMessageCount];
Debug.Assert(AllMessages.Max(m => m.Number) == HighestMessageNumber);

_activatedMessagesById = new bool[AllMessages.Length];
_enabledMessagesByNumber = new MessageMetadata[HighestMessageNumber + 1];
}

Expand Down Expand Up @@ -289,7 +290,9 @@ public MessageMetadata(byte id, string name, byte number)

public override Message Create()
{
return new T();
var message = new T();
Debug.Assert(message.MessageNumber == Number);
return message;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ public void KeyboardInteractive_PasswordExpired()
// Password expired, retype new password
authenticationPrompt.Response = Users.Regular.Password;
break;
default:
break;
}

authenticationPromptCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,61 +100,12 @@ public void Test_PortForwarding_Local_Stop_Hangs_On_Wait()
}

[TestMethod]
[ExpectedException(typeof(SshConnectionException))]
public void Test_PortForwarding_Local_Without_Connecting()
{
using (var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
using var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80);
client.AddForwardedPort(port1);
port1.Exception += delegate (object sender, ExceptionEventArgs e)
{
Assert.Fail(e.Exception.ToString());
};
port1.Start();

var test = Parallel.For(0,
100,
counter =>
{
var start = DateTime.Now;

#if NET6_0_OR_GREATER
var httpClient = new HttpClient();
using (var response = httpClient.GetAsync("http://localhost:8084").GetAwaiter().GetResult())
{
var data = ReadStream(response.Content.ReadAsStream());
#else
var request = (HttpWebRequest)WebRequest.Create("http://localhost:8084");
using (var response = (HttpWebResponse)request.GetResponse())
{
var data = ReadStream(response.GetResponseStream());
#endif // NET6_0_OR_GREATER
var end = DateTime.Now;

Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, end - start, counter));
}
});
}
}

private static byte[] ReadStream(Stream stream)
{
var buffer = new byte[1024];
using (var ms = new MemoryStream())
{
while (true)
{
var read = stream.Read(buffer, 0, buffer.Length);
if (read > 0)
{
ms.Write(buffer, 0, read);
}
else
{
return ms.ToArray();
}
}
Assert.ThrowsException<SshConnectionException>(() => client.AddForwardedPort(port1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ where CalculateMD5(file) == CalculateMD5(string.Format("{0}.down", file))

scp.Disconnect();

Assert.IsTrue(result.Count() == uploadFilenames.Length);
Assert.AreEqual(uploadFilenames.Length, result.Count());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,97 +9,97 @@ public partial class SftpClientTest : IntegrationTestBase
{
[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public void Test_Sftp_ChangeDirectory_Root_Dont_Exists()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
sftp.Connect();
sftp.ChangeDirectory("/asdasd");
Assert.ThrowsException<SftpPathNotFoundException>(() => sftp.ChangeDirectory("/asdasd"));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public async Task Test_Sftp_ChangeDirectory_Root_Dont_ExistsAsync()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
await sftp.ChangeDirectoryAsync("/asdasd", CancellationToken.None).ConfigureAwait(false);

await Assert.ThrowsExceptionAsync<SftpPathNotFoundException>(
() => sftp.ChangeDirectoryAsync("/asdasd", CancellationToken.None));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public void Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_Exists()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
sftp.Connect();
sftp.ChangeDirectory("/asdasd/");
Assert.ThrowsException<SftpPathNotFoundException>(() => sftp.ChangeDirectory("/asdasd/"));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public async Task Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_ExistsAsync()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
await sftp.ChangeDirectoryAsync("/asdasd/", CancellationToken.None).ConfigureAwait(false);

await Assert.ThrowsExceptionAsync<SftpPathNotFoundException>(
() => sftp.ChangeDirectoryAsync("/asdasd/", CancellationToken.None));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public void Test_Sftp_ChangeDirectory_Subfolder_Dont_Exists()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
sftp.Connect();
sftp.ChangeDirectory("/asdasd/sssddds");
Assert.ThrowsException<SftpPathNotFoundException>(() => sftp.ChangeDirectory("/asdasd/sssddds"));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public async Task Test_Sftp_ChangeDirectory_Subfolder_Dont_ExistsAsync()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
await sftp.ChangeDirectoryAsync("/asdasd/sssddds", CancellationToken.None).ConfigureAwait(false);

await Assert.ThrowsExceptionAsync<SftpPathNotFoundException>(
() => sftp.ChangeDirectoryAsync("/asdasd/sssddds", CancellationToken.None));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public void Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
sftp.Connect();
sftp.ChangeDirectory("/asdasd/sssddds/");
Assert.ThrowsException<SftpPathNotFoundException>(() => sftp.ChangeDirectory("/asdasd/sssddds/"));
}
}

[TestMethod]
[TestCategory("Sftp")]
[ExpectedException(typeof(SftpPathNotFoundException))]
public async Task Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_ExistsAsync()
{
using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
{
await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
await sftp.ChangeDirectoryAsync("/asdasd/sssddds/", CancellationToken.None).ConfigureAwait(false);

await Assert.ThrowsExceptionAsync<SftpPathNotFoundException>(
() => sftp.ChangeDirectoryAsync("/asdasd/sssddds/", CancellationToken.None));
}
}

Expand Down
Loading