Skip to content

Commit 70f58b7

Browse files
Add/migrate hmac+cipher integration tests (#1189)
* Add/migrate hmac+cipher integration tests * fix integration tests --------- Co-authored-by: Wojciech Nagórski <[email protected]>
1 parent 5803ada commit 70f58b7

File tree

8 files changed

+171
-266
lines changed

8 files changed

+171
-266
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using Renci.SshNet.IntegrationTests.Common;
2+
using Renci.SshNet.TestTools.OpenSSH;
3+
4+
namespace Renci.SshNet.IntegrationTests
5+
{
6+
[TestClass]
7+
public class CipherTests : IntegrationTestBase
8+
{
9+
private IConnectionInfoFactory _connectionInfoFactory;
10+
private RemoteSshdConfig _remoteSshdConfig;
11+
12+
[TestInitialize]
13+
public void SetUp()
14+
{
15+
_connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
16+
_remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig();
17+
}
18+
19+
[TestCleanup]
20+
public void TearDown()
21+
{
22+
_remoteSshdConfig?.Reset();
23+
}
24+
25+
[TestMethod]
26+
public void TripledesCbc()
27+
{
28+
DoTest(Cipher.TripledesCbc);
29+
}
30+
31+
[TestMethod]
32+
public void Aes128Cbc()
33+
{
34+
DoTest(Cipher.Aes128Cbc);
35+
}
36+
37+
[TestMethod]
38+
public void Aes192Cbc()
39+
{
40+
DoTest(Cipher.Aes192Cbc);
41+
}
42+
43+
[TestMethod]
44+
public void Aes256Cbc()
45+
{
46+
DoTest(Cipher.Aes256Cbc);
47+
}
48+
49+
[TestMethod]
50+
public void Aes128Ctr()
51+
{
52+
DoTest(Cipher.Aes128Ctr);
53+
}
54+
55+
[TestMethod]
56+
public void Aes192Ctr()
57+
{
58+
DoTest(Cipher.Aes192Ctr);
59+
}
60+
61+
[TestMethod]
62+
public void Aes256Ctr()
63+
{
64+
DoTest(Cipher.Aes256Ctr);
65+
}
66+
67+
private void DoTest(Cipher cipher)
68+
{
69+
_remoteSshdConfig.ClearCiphers()
70+
.AddCipher(cipher)
71+
.Update()
72+
.Restart();
73+
74+
using (var client = new SshClient(_connectionInfoFactory.Create()))
75+
{
76+
client.Connect();
77+
client.Disconnect();
78+
}
79+
}
80+
}
81+
}

src/Renci.SshNet.IntegrationTests/Common/RemoteSshdConfigExtensions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static void Reset(this RemoteSshdConfig remoteSshdConfig)
2121
.ClearKeyExchangeAlgorithms()
2222
.ClearHostKeyAlgorithms()
2323
.ClearPublicKeyAcceptedAlgorithms()
24+
.ClearMessageAuthenticationCodeAlgorithms()
2425
.WithUsePAM(true)
2526
.Update()
2627
.Restart();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Renci.SshNet.IntegrationTests.Common;
2+
using Renci.SshNet.TestTools.OpenSSH;
3+
4+
namespace Renci.SshNet.IntegrationTests
5+
{
6+
[TestClass]
7+
public class HmacTests : IntegrationTestBase
8+
{
9+
private IConnectionInfoFactory _connectionInfoFactory;
10+
private RemoteSshdConfig _remoteSshdConfig;
11+
12+
[TestInitialize]
13+
public void SetUp()
14+
{
15+
_connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
16+
_remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig();
17+
}
18+
19+
[TestCleanup]
20+
public void TearDown()
21+
{
22+
_remoteSshdConfig?.Reset();
23+
}
24+
25+
[TestMethod]
26+
public void HmacMd5()
27+
{
28+
DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5);
29+
}
30+
31+
[TestMethod]
32+
public void HmacMd5_96()
33+
{
34+
DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5_96);
35+
}
36+
37+
[TestMethod]
38+
public void HmacSha1()
39+
{
40+
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1);
41+
}
42+
43+
[TestMethod]
44+
public void HmacSha1_96()
45+
{
46+
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1_96);
47+
}
48+
49+
[TestMethod]
50+
public void HmacSha2_256()
51+
{
52+
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256);
53+
}
54+
55+
[TestMethod]
56+
public void HmacSha2_512()
57+
{
58+
DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512);
59+
}
60+
61+
private void DoTest(MessageAuthenticationCodeAlgorithm macAlgorithm)
62+
{
63+
_remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms()
64+
.AddMessageAuthenticationCodeAlgorithm(macAlgorithm)
65+
.Update()
66+
.Restart();
67+
68+
using (var client = new SshClient(_connectionInfoFactory.Create()))
69+
{
70+
client.Connect();
71+
client.Disconnect();
72+
}
73+
}
74+
}
75+
}

src/Renci.SshNet.IntegrationTests/OldIntegrationTests/AesCipherTests.cs

-147
This file was deleted.

src/Renci.SshNet.IntegrationTests/OldIntegrationTests/HMacTest.cs

-67
This file was deleted.

0 commit comments

Comments
 (0)