Skip to content

Commit 9593e87

Browse files
Move Integration tests (#1173)
* Renci.SshNet.IntegrationTests * Renci.SshNet.TestTools.OpenSSH * Move integration tests to main repo * Move old tests to new integration tests * Move old integration tests to new integration tests * Move more tests * Move authentication tests * Move SshClientTests * Fix some tests * Remove duplicated test * Poc of ProcessDisruptor * Rename * Some fixes * Remove performance tests * Small improvements
1 parent 9f1699b commit 9593e87

File tree

117 files changed

+15542
-2973
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+15542
-2973
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TestResults/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<system.diagnostics>
4+
<trace autoflush="true"/>
5+
<sources>
6+
<source name="SshNet.Logging" switchName="SshNetSwitch" switchType="System.Diagnostics.SourceSwitch">
7+
<listeners>
8+
<!--<add name="SshDotNetTraceFile" />-->
9+
<!--<add name="Console"/>-->
10+
</listeners>
11+
</source>
12+
</sources>
13+
<switches>
14+
<add name="SshNetSwitch" value="Verbose"/>
15+
</switches>
16+
<sharedListeners>
17+
<add name="SshDotNetTraceFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="SshNetTrace.log">
18+
<!--<filter type="System.Diagnostics.EventTypeFilter" initializeData="Warning" />-->
19+
</add>
20+
<add name="Console" type="System.Diagnostics.ConsoleTraceListener" traceOutputOptions="DateTime,Timestamp,ThreadId"/>
21+
</sharedListeners>
22+
</system.diagnostics>
23+
</configuration>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace Renci.SshNet.IntegrationTests
2+
{
3+
public class AuthenticationMethodFactory
4+
{
5+
public PasswordAuthenticationMethod CreatePowerUserPasswordAuthenticationMethod()
6+
{
7+
var user = Users.Admin;
8+
return new PasswordAuthenticationMethod(user.UserName, user.Password);
9+
}
10+
11+
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethod()
12+
{
13+
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa");
14+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
15+
}
16+
17+
public PrivateKeyAuthenticationMethod CreateRegularUserMultiplePrivateKeyAuthenticationMethod()
18+
{
19+
var privateKeyFile1 = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa");
20+
var privateKeyFile2 = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa");
21+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile1, privateKeyFile2);
22+
}
23+
24+
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithPassPhraseAuthenticationMethod()
25+
{
26+
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa_with_pass", "tester");
27+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
28+
}
29+
30+
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithEmptyPassPhraseAuthenticationMethod()
31+
{
32+
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa_with_pass", null);
33+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
34+
}
35+
36+
public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethodWithBadKey()
37+
{
38+
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_noaccess.rsa");
39+
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
40+
}
41+
42+
public PasswordAuthenticationMethod CreateRegulatUserPasswordAuthenticationMethod()
43+
{
44+
return new PasswordAuthenticationMethod(Users.Regular.UserName, Users.Regular.Password);
45+
}
46+
47+
public PasswordAuthenticationMethod CreateRegularUserPasswordAuthenticationMethodWithBadPassword()
48+
{
49+
return new PasswordAuthenticationMethod(Users.Regular.UserName, "xxx");
50+
}
51+
52+
public KeyboardInteractiveAuthenticationMethod CreateRegularUserKeyboardInteractiveAuthenticationMethod()
53+
{
54+
var keyboardInteractive = new KeyboardInteractiveAuthenticationMethod(Users.Regular.UserName);
55+
keyboardInteractive.AuthenticationPrompt += (sender, args) =>
56+
{
57+
foreach (var authenticationPrompt in args.Prompts)
58+
{
59+
authenticationPrompt.Response = Users.Regular.Password;
60+
}
61+
};
62+
return keyboardInteractive;
63+
}
64+
65+
private PrivateKeyFile GetPrivateKey(string resourceName, string passPhrase = null)
66+
{
67+
using (var stream = GetResourceStream(resourceName))
68+
{
69+
return new PrivateKeyFile(stream, passPhrase);
70+
}
71+
}
72+
73+
private Stream GetResourceStream(string resourceName)
74+
{
75+
var type = GetType();
76+
var resourceStream = type.Assembly.GetManifestResourceStream(resourceName);
77+
if (resourceStream == null)
78+
{
79+
throw new ArgumentException($"Resource '{resourceName}' not found in assembly '{type.Assembly.FullName}'.", nameof(resourceName));
80+
}
81+
return resourceStream;
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)