Skip to content

Commit

Permalink
Use shared Data folder for client keys in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-Hague committed Oct 26, 2023
1 parent d73c56b commit 2eca6f6
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 171 deletions.
1 change: 1 addition & 0 deletions test/Data/Key.DSA.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-dss AAAAB3NzaC1kc3MAAACBALVl3fae2O4qwsAK95SUShX0KMUNP+yl/uT3lGH9T/ZptnHSlrTxnTWXCl0g91KEeCaEnDDhLxm4aCv1Ag4B/yvcM4u34qkmaNLy2LiAxiqdobZcNG61Pqwqd5IDkp38LBsn8tmb12xu9NalpUfOiSEB1cyCr4zFZMrm0wtdyJQVAAAAFQCu+iNkqf/YOAYjYrHSCHFmWAfEYQAAAIAOVJ434UAR3Hn6lA5nWNfFOuUVH3W7nJaP0FQJiIPx7GUbdxO9qtDNTbWkWL3c9qx5+B7Ole4xM7cvyXPrNQUYDHCFlS+Ue2x3IeJrkdfZkH9ePP25y5A0J4/c+8XXvQaj4zA5nfw13oy5Ptyd7d3Kq5tEDM8KiVdIhwkXjUA3PQAAAIEAm8IGZQatS7M6AfNITNWG4TI7Z2aRQjLb9/MWJIID7c/VQ4zdTZdG3kpk0Gj9n4xreopK5NmYAdj8rtFfPBgmXltsLqt+bBcXkpxW//7WC29WOXW3t90ySTh+cWuWfr9fV7mf4Ql/6u/ZIgpQNvnNYezazt3fK8EXjI1dAXEuQxE=
File renamed without changes.
44 changes: 37 additions & 7 deletions test/Renci.SshNet.IntegrationTests/AuthenticationMethodFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,63 @@ public PasswordAuthenticationMethod CreatePowerUserPasswordAuthenticationMethod(

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethod()
{
var privateKeyFile = GetPrivateKey("resources.client.id_rsa");
var privateKeyFile = GetPrivateKey("data.Key.RSA.txt");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PrivateKeyAuthenticationMethod CreateRegularUserMultiplePrivateKeyAuthenticationMethod()
{
var privateKeyFile1 = GetPrivateKey("resources.client.id_rsa");
var privateKeyFile2 = GetPrivateKey("resources.client.id_rsa");
var privateKeyFile1 = GetPrivateKey("data.Key.RSA.txt");
var privateKeyFile2 = GetPrivateKey("data.Key.RSA.txt");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile1, privateKeyFile2);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithPassPhraseAuthenticationMethod()
{
var privateKeyFile = GetPrivateKey("resources.client.id_rsa_with_pass", "tester");
var privateKeyFile = GetPrivateKey("data.Key.RSA.Encrypted.Aes.256.CBC.12345.txt", "12345");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithEmptyPassPhraseAuthenticationMethod()
{
var privateKeyFile = GetPrivateKey("resources.client.id_rsa_with_pass", null);
var privateKeyFile = GetPrivateKey("data.Key.RSA.Encrypted.Aes.256.CBC.12345.txt", null);
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethodWithBadKey()
{
var privateKeyFile = GetPrivateKey("resources.client.id_noaccess.rsa");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
string unauthorizedKey = """
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAuK3OhcrEnQbbE1+WaE57tUCcTz1yqdE2AwvMfs3of1nyfGcS
Rz9vzAFYU+3uEEApk0QOsIeWCyB2DIlPnlQHyjVWRYPqiTtQ7GmdzbF0ISa7dr23
EHJKgtJxSm3O/sb5F9JyqlxFMhKpz5NVgnN7NFcej93opHZN6h9LaP8cHgJIepWV
IkZqhcv8v6SpAgei0muoPHB+ZA6Rycnv+2//WUBzu+3AJu0Pi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vLC+yfV5x/0xKNELmHP8YQclyA81loyH6NEl488wXIaFznxuxDnX+mZ8moK5ieO
7A5zzuppvhWIP1fyOJok6xUMkKYwXdqZoP7jUrS3JZShZteyeIS9olVxLpphbZTu
kQnZrwKBgQDhO2+iGXwNLS+OFKwEiyUgvi6jb5OrIsdwWgqaqQarm6h0QWtxrCs6
CMFFEusswZEGRo83J6lQxtcXvhWzTkVPu69J8YvTQqcKlvUSA9TEG2iX9bwXSWzy
LeGb5NjBZ3szfzp9l5Utnj5GuAGoDDDKpf7M6S95Lg6F58Mhd/tCFA==
-----END RSA PRIVATE KEY-----
""";

using MemoryStream memoryStream = new(Encoding.UTF8.GetBytes(unauthorizedKey));
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, new PrivateKeyFile(memoryStream));
}

public PasswordAuthenticationMethod CreateRegulatUserPasswordAuthenticationMethod()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,49 @@ public void TearDown()
[TestMethod]
public void SshDss()
{
DoTest(PublicKeyAlgorithm.SshDss, "id_dsa");
DoTest(PublicKeyAlgorithm.SshDss, "data.Key.DSA.txt");
}

[TestMethod]
public void SshRsa()
{
DoTest(PublicKeyAlgorithm.SshRsa, "id_rsa");
DoTest(PublicKeyAlgorithm.SshRsa, "data.Key.RSA.txt");
}

[TestMethod]
public void SshRsaSha256()
{
DoTest(PublicKeyAlgorithm.RsaSha2256, "id_rsa");
DoTest(PublicKeyAlgorithm.RsaSha2256, "data.Key.RSA.txt");
}

[TestMethod]
public void SshRsaSha512()
{
DoTest(PublicKeyAlgorithm.RsaSha2512, "id_rsa");
DoTest(PublicKeyAlgorithm.RsaSha2512, "data.Key.RSA.txt");
}

[TestMethod]
public void Ecdsa256()
{
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp256, "key_ecdsa_256_openssh");
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp256, "data.Key.OPENSSH.ECDSA.txt");
}

[TestMethod]
public void Ecdsa384()
{
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp384, "key_ecdsa_384_openssh");
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp384, "data.Key.OPENSSH.ECDSA384.txt");
}

[TestMethod]
public void Ecdsa521()
{
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp521, "key_ecdsa_521_openssh");
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp521, "data.Key.OPENSSH.ECDSA521.txt");
}

[TestMethod]
public void Ed25519()
{
DoTest(PublicKeyAlgorithm.SshEd25519, "key_ed25519_openssh");
DoTest(PublicKeyAlgorithm.SshEd25519, "data.Key.OPENSSH.ED25519.txt");
}

private void DoTest(PublicKeyAlgorithm publicKeyAlgorithm, string keyResource)
Expand All @@ -87,7 +87,7 @@ private void DoTest(PublicKeyAlgorithm publicKeyAlgorithm, string keyResource)

private PrivateKeyAuthenticationMethod CreatePrivateKeyAuthenticationMethod(string keyResource)
{
using (var stream = GetData($"resources.client.{keyResource}"))
using (var stream = GetData(keyResource))
{
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, new PrivateKeyFile(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="resources\client\id_dsa" />
<EmbeddedResource Include="resources\client\id_dsa.ppk" />
<EmbeddedResource Include="resources\client\id_noaccess.rsa" />
<EmbeddedResource Include="resources\client\id_rsa" />
<EmbeddedResource Include="resources\client\id_rsa_with_pass" />
<EmbeddedResource Include="resources\client\key_ecdsa_256_openssh" />
<EmbeddedResource Include="resources\client\key_ecdsa_384_openssh" />
<EmbeddedResource Include="resources\client\key_ecdsa_521_openssh" />
<EmbeddedResource Include="resources\client\key_ed25519_openssh" />
<EmbeddedResource Include="..\Data\*" LinkBase="Data" />
<EmbeddedResource Include="resources\issue #70.png" />
</ItemGroup>
</Project>
17 changes: 0 additions & 17 deletions test/Renci.SshNet.IntegrationTests/resources/client/id_dsa.ppk

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions test/Renci.SshNet.IntegrationTests/resources/client/id_rsa

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2eca6f6

Please sign in to comment.