Skip to content

Commit 0829fce

Browse files
committed
Use shared Data folder for client keys in integration tests
1 parent 1fc6360 commit 0829fce

20 files changed

+63
-177
lines changed

test/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ dotnet_diagnostic.S1854.severity = none
2828
# https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md
2929
dotnet_diagnostic.MA0089.severity = suggestion
3030

31+
#MA0136 - Raw String contains an implicit end of line character
32+
dotnet_diagnostic.MA0136.severity = none
33+
3134
#### StyleCop rules ####
3235

3336
# SA1202: Elements must be ordered by access

test/Data/Key.DSA.pub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-dss AAAAB3NzaC1kc3MAAACBALVl3fae2O4qwsAK95SUShX0KMUNP+yl/uT3lGH9T/ZptnHSlrTxnTWXCl0g91KEeCaEnDDhLxm4aCv1Ag4B/yvcM4u34qkmaNLy2LiAxiqdobZcNG61Pqwqd5IDkp38LBsn8tmb12xu9NalpUfOiSEB1cyCr4zFZMrm0wtdyJQVAAAAFQCu+iNkqf/YOAYjYrHSCHFmWAfEYQAAAIAOVJ434UAR3Hn6lA5nWNfFOuUVH3W7nJaP0FQJiIPx7GUbdxO9qtDNTbWkWL3c9qx5+B7Ole4xM7cvyXPrNQUYDHCFlS+Ue2x3IeJrkdfZkH9ePP25y5A0J4/c+8XXvQaj4zA5nfw13oy5Ptyd7d3Kq5tEDM8KiVdIhwkXjUA3PQAAAIEAm8IGZQatS7M6AfNITNWG4TI7Z2aRQjLb9/MWJIID7c/VQ4zdTZdG3kpk0Gj9n4xreopK5NmYAdj8rtFfPBgmXltsLqt+bBcXkpxW//7WC29WOXW3t90ySTh+cWuWfr9fV7mf4Ql/6u/ZIgpQNvnNYezazt3fK8EXjI1dAXEuQxE=

test/Renci.SshNet.IntegrationTests/AuthenticationMethodFactory.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,63 @@ public PasswordAuthenticationMethod CreatePowerUserPasswordAuthenticationMethod(
1010

1111
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethod()
1212
{
13-
var privateKeyFile = GetPrivateKey("resources.client.id_rsa");
13+
var privateKeyFile = GetPrivateKey("Data.Key.RSA.txt");
1414
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
1515
}
1616

1717
public PrivateKeyAuthenticationMethod CreateRegularUserMultiplePrivateKeyAuthenticationMethod()
1818
{
19-
var privateKeyFile1 = GetPrivateKey("resources.client.id_rsa");
20-
var privateKeyFile2 = GetPrivateKey("resources.client.id_rsa");
19+
var privateKeyFile1 = GetPrivateKey("Data.Key.RSA.txt");
20+
var privateKeyFile2 = GetPrivateKey("Data.Key.RSA.txt");
2121
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile1, privateKeyFile2);
2222
}
2323

2424
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithPassPhraseAuthenticationMethod()
2525
{
26-
var privateKeyFile = GetPrivateKey("resources.client.id_rsa_with_pass", "tester");
26+
var privateKeyFile = GetPrivateKey("Data.Key.RSA.Encrypted.Aes.256.CBC.12345.txt", "12345");
2727
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
2828
}
2929

3030
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithEmptyPassPhraseAuthenticationMethod()
3131
{
32-
var privateKeyFile = GetPrivateKey("resources.client.id_rsa_with_pass", null);
32+
var privateKeyFile = GetPrivateKey("Data.Key.RSA.Encrypted.Aes.256.CBC.12345.txt", null);
3333
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
3434
}
3535

3636
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethodWithBadKey()
3737
{
38-
var privateKeyFile = GetPrivateKey("resources.client.id_noaccess.rsa");
39-
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
38+
string unauthorizedKey = """
39+
-----BEGIN RSA PRIVATE KEY-----
40+
MIIEpAIBAAKCAQEAuK3OhcrEnQbbE1+WaE57tUCcTz1yqdE2AwvMfs3of1nyfGcS
41+
Rz9vzAFYU+3uEEApk0QOsIeWCyB2DIlPnlQHyjVWRYPqiTtQ7GmdzbF0ISa7dr23
42+
EHJKgtJxSm3O/sb5F9JyqlxFMhKpz5NVgnN7NFcej93opHZN6h9LaP8cHgJIepWV
43+
IkZqhcv8v6SpAgei0muoPHB+ZA6Rycnv+2//WUBzu+3AJu0PiHUkTTVC8M5svMRV
44+
Ah8CnLsCkAAx7ld4AH7McRlFjymmkwxTSewFJYkloI/OqDOjsmuW03Gmx+eytPWa
45+
HEPGeRhcz1kZ6eOmqrPMlTaLPV1MbFn86nauAQIDAQABAoIBAGEiWauZOMx2nKeV
46+
8SAvl3V/5DbxVOvotAXqIMbZOl4xSw8Pj1eWEBE26+RJEpvNg5CHjUpgJhT4H978
47+
Ibpe7DH418V8WtGPN0MBUhSsLy54lsUfh7fIxVQFp7zEAMmUkdNrxw+/tE1f75zU
48+
G3efkb+3ysVUrFZEOzrW9uzksT8+gm2Ll/IKuDy2r5k9mJr2cX5OYKxXjtNo5duO
49+
UK+M3jW9Sk1k23Jzpq2GwuJGTTjgtI41ND6CDkrY7COdRQdIx3eQ0uQSXosKNREe
50+
lv0VTlboVyh8JXt+G1tkfA6+Al77/mzycaZVX26C8Io7Y/S7JVG7TT1p1RsFGZM8
51+
kcqvpBkCgYEA7vD3S+6T+8Ql8U877nDi/Ttf16NEUUQllgjWgCP+DiWcqQGWaiaB
52+
JTYyM4Ydb4jy2jAcAdf3HfImE4QO3+u/wyuQrdlvWByHo2NqOxYMdyqKqwGh7qhU
53+
zZFbGfHRD/gV4hWXfzj65wA8uMBVc5J3/ug7nmkTWywiDH/SsPdbxmcCgYEAxd0c
54+
EbJ3dlIyK5Ul1Gw5dASyE91Nx/NHAvB+5QHH5rIe/IqbtxbXmEMKcxwEPN8hvpzs
55+
g487TQFkNPze6X8vZkiuaNLUq9vwRlQwr/LIdjLLKOA69wKfFDSkei8LEMgEz7Wg
56+
ZEm8ifJP75hGozx31bW4dYX2o2X75SbXneMVF1cCgYEAo4h8WJXC5o9KwKtQA1Nz
57+
p4lZgUaW3V/csaD+3djEan5HiEwz3BbaUNOU7DqgLtP2EmrW4FQlJ3Oxp628WHkL
58+
V9KbRMEKOa3dD3BdJm9ivLR7D6sgXy0KTV9skIc2ZM2QfJn2g/ZFkpBQ/sl0MpNO
59+
WUIse7DCtKWx8AgT9VZ2k4UCgYB1G8JSQyPrtwiUvQkP6iIzJdhUY4Z20ulztu4U
60+
EvLC+yfV5x/0xKNELmHP8YQclyA81loyH6NEl488wXIaFznxuxDnX+mZ8moK5ieO
61+
7A5zzuppvhWIP1fyOJok6xUMkKYwXdqZoP7jUrS3JZShZteyeIS9olVxLpphbZTu
62+
kQnZrwKBgQDhO2+iGXwNLS+OFKwEiyUgvi6jb5OrIsdwWgqaqQarm6h0QWtxrCs6
63+
CMFFEusswZEGRo83J6lQxtcXvhWzTkVPu69J8YvTQqcKlvUSA9TEG2iX9bwXSWzy
64+
LeGb5NjBZ3szfzp9l5Utnj5GuAGoDDDKpf7M6S95Lg6F58Mhd/tCFA==
65+
-----END RSA PRIVATE KEY-----
66+
""";
67+
68+
using MemoryStream memoryStream = new(Encoding.UTF8.GetBytes(unauthorizedKey));
69+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, new PrivateKeyFile(memoryStream));
4070
}
4171

4272
public PasswordAuthenticationMethod CreateRegulatUserPasswordAuthenticationMethod()

test/Renci.SshNet.IntegrationTests/PrivateKeyAuthenticationTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,71 +25,71 @@ public void TearDown()
2525
[TestMethod]
2626
public void SshDss()
2727
{
28-
DoTest(PublicKeyAlgorithm.SshDss, "id_dsa");
28+
DoTest(PublicKeyAlgorithm.SshDss, "Data.Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt", "12345");
2929
}
3030

3131
[TestMethod]
3232
public void SshRsa()
3333
{
34-
DoTest(PublicKeyAlgorithm.SshRsa, "id_rsa");
34+
DoTest(PublicKeyAlgorithm.SshRsa, "Data.Key.RSA.txt");
3535
}
3636

3737
[TestMethod]
3838
public void SshRsaSha256()
3939
{
40-
DoTest(PublicKeyAlgorithm.RsaSha2256, "id_rsa");
40+
DoTest(PublicKeyAlgorithm.RsaSha2256, "Data.Key.RSA.txt");
4141
}
4242

4343
[TestMethod]
4444
public void SshRsaSha512()
4545
{
46-
DoTest(PublicKeyAlgorithm.RsaSha2512, "id_rsa");
46+
DoTest(PublicKeyAlgorithm.RsaSha2512, "Data.Key.RSA.txt");
4747
}
4848

4949
[TestMethod]
5050
public void Ecdsa256()
5151
{
52-
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp256, "key_ecdsa_256_openssh");
52+
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp256, "Data.Key.ECDSA.Encrypted.txt", "12345");
5353
}
5454

5555
[TestMethod]
5656
public void Ecdsa384()
5757
{
58-
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp384, "key_ecdsa_384_openssh");
58+
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp384, "Data.Key.OPENSSH.ECDSA384.Encrypted.txt", "12345");
5959
}
6060

6161
[TestMethod]
6262
public void Ecdsa521()
6363
{
64-
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp521, "key_ecdsa_521_openssh");
64+
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp521, "Data.Key.OPENSSH.ECDSA521.Encrypted.txt", "12345");
6565
}
6666

6767
[TestMethod]
6868
public void Ed25519()
6969
{
70-
DoTest(PublicKeyAlgorithm.SshEd25519, "key_ed25519_openssh");
70+
DoTest(PublicKeyAlgorithm.SshEd25519, "Data.Key.OPENSSH.ED25519.Encrypted.txt", "12345");
7171
}
7272

73-
private void DoTest(PublicKeyAlgorithm publicKeyAlgorithm, string keyResource)
73+
private void DoTest(PublicKeyAlgorithm publicKeyAlgorithm, string keyResource, string passPhrase = null)
7474
{
7575
_remoteSshdConfig.ClearPublicKeyAcceptedAlgorithms()
7676
.AddPublicKeyAcceptedAlgorithm(publicKeyAlgorithm)
7777
.Update()
7878
.Restart();
7979

80-
var connectionInfo = _connectionInfoFactory.Create(CreatePrivateKeyAuthenticationMethod(keyResource));
80+
var connectionInfo = _connectionInfoFactory.Create(CreatePrivateKeyAuthenticationMethod(keyResource, passPhrase));
8181

8282
using (var client = new SshClient(connectionInfo))
8383
{
8484
client.Connect();
8585
}
8686
}
8787

88-
private PrivateKeyAuthenticationMethod CreatePrivateKeyAuthenticationMethod(string keyResource)
88+
private static PrivateKeyAuthenticationMethod CreatePrivateKeyAuthenticationMethod(string keyResource, string passPhrase)
8989
{
90-
using (var stream = GetData($"resources.client.{keyResource}"))
90+
using (var stream = GetData(keyResource))
9191
{
92-
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, new PrivateKeyFile(stream));
92+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, new PrivateKeyFile(stream, passPhrase));
9393
}
9494
}
9595
}

test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@
3939
</ItemGroup>
4040

4141
<ItemGroup>
42-
<EmbeddedResource Include="resources\client\id_dsa" />
43-
<EmbeddedResource Include="resources\client\id_dsa.ppk" />
44-
<EmbeddedResource Include="resources\client\id_noaccess.rsa" />
45-
<EmbeddedResource Include="resources\client\id_rsa" />
46-
<EmbeddedResource Include="resources\client\id_rsa_with_pass" />
47-
<EmbeddedResource Include="resources\client\key_ecdsa_256_openssh" />
48-
<EmbeddedResource Include="resources\client\key_ecdsa_384_openssh" />
49-
<EmbeddedResource Include="resources\client\key_ecdsa_521_openssh" />
50-
<EmbeddedResource Include="resources\client\key_ed25519_openssh" />
42+
<EmbeddedResource Include="..\Data\*" LinkBase="Data" />
5143
<EmbeddedResource Include="resources\issue #70.png" />
5244
</ItemGroup>
5345
</Project>

test/Renci.SshNet.IntegrationTests/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal static Stream GetData(string name)
7171
string resourceName = $"Renci.SshNet.IntegrationTests.{name}";
7272

7373
return typeof(TestBase).Assembly.GetManifestResourceStream(resourceName)
74-
?? throw new ArgumentException($"Resource '{resourceName}' not found in assembly '{typeof(TestBase).Assembly.FullName}'.", nameof(resourceName));
74+
?? throw new ArgumentException($"Resource '{resourceName}' not found in assembly '{typeof(TestBase).Assembly.FullName}'.", nameof(name));
7575
}
7676
}
7777
}

test/Renci.SshNet.IntegrationTests/resources/client/id_dsa.ppk

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/Renci.SshNet.IntegrationTests/resources/client/id_noaccess.rsa

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/Renci.SshNet.IntegrationTests/resources/client/id_rsa

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)