Skip to content
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

Add/migrate hmac+cipher integration tests #1189

Merged
merged 3 commits into from
Sep 29, 2023
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
81 changes: 81 additions & 0 deletions src/Renci.SshNet.IntegrationTests/CipherTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Renci.SshNet.IntegrationTests.Common;
using Renci.SshNet.TestTools.OpenSSH;

namespace Renci.SshNet.IntegrationTests
{
[TestClass]
public class CipherTests : IntegrationTestBase
{
private IConnectionInfoFactory _connectionInfoFactory;
private RemoteSshdConfig _remoteSshdConfig;

[TestInitialize]
public void SetUp()
{
_connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
_remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig();
}

[TestCleanup]
public void TearDown()
{
_remoteSshdConfig?.Reset();
}

[TestMethod]
public void TripledesCbc()
{
DoTest(Cipher.TripledesCbc);
}

[TestMethod]
public void Aes128Cbc()
{
DoTest(Cipher.Aes128Cbc);
}

[TestMethod]
public void Aes192Cbc()
{
DoTest(Cipher.Aes192Cbc);
}

[TestMethod]
public void Aes256Cbc()
{
DoTest(Cipher.Aes256Cbc);
}

[TestMethod]
public void Aes128Ctr()
{
DoTest(Cipher.Aes128Ctr);
}

[TestMethod]
public void Aes192Ctr()
{
DoTest(Cipher.Aes192Ctr);
}

[TestMethod]
public void Aes256Ctr()
{
DoTest(Cipher.Aes256Ctr);
}

private void DoTest(Cipher cipher)
{
_remoteSshdConfig.ClearCiphers()
.AddCipher(cipher)
.Update()
.Restart();

using (var client = new SshClient(_connectionInfoFactory.Create()))
{
client.Connect();
client.Disconnect();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void Reset(this RemoteSshdConfig remoteSshdConfig)
.ClearKeyExchangeAlgorithms()
.ClearHostKeyAlgorithms()
.ClearPublicKeyAcceptedAlgorithms()
.ClearMessageAuthenticationCodeAlgorithms()
.WithUsePAM(true)
.Update()
.Restart();
Expand Down
75 changes: 75 additions & 0 deletions src/Renci.SshNet.IntegrationTests/HmacTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Renci.SshNet.IntegrationTests.Common;
using Renci.SshNet.TestTools.OpenSSH;

namespace Renci.SshNet.IntegrationTests
{
[TestClass]
public class HmacTests : IntegrationTestBase
{
private IConnectionInfoFactory _connectionInfoFactory;
private RemoteSshdConfig _remoteSshdConfig;

[TestInitialize]
public void SetUp()
{
_connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
_remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig();
}

[TestCleanup]
public void TearDown()
{
_remoteSshdConfig?.Reset();
}

[TestMethod]
public void HmacMd5()
{
DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5);
}

[TestMethod]
public void HmacMd5_96()
{
DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5_96);
}

[TestMethod]
public void HmacSha1()
{
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1);
}

[TestMethod]
public void HmacSha1_96()
{
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1_96);
}

[TestMethod]
public void HmacSha2_256()
{
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256);
}

[TestMethod]
public void HmacSha2_512()
{
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512);
}

private void DoTest(MessageAuthenticationCodeAlgorithm macAlgorithm)
{
_remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms()
.AddMessageAuthenticationCodeAlgorithm(macAlgorithm)
.Update()
.Restart();

using (var client = new SshClient(_connectionInfoFactory.Create()))
{
client.Connect();
client.Disconnect();
}
}
}
}

This file was deleted.

This file was deleted.

Loading