Skip to content

Commit

Permalink
Move Integration tests (#1173)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
WojciechNagorski authored Sep 12, 2023
1 parent 9f1699b commit 9593e87
Show file tree
Hide file tree
Showing 117 changed files with 15,542 additions and 2,973 deletions.
1 change: 1 addition & 0 deletions src/Renci.SshNet.IntegrationTests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestResults/
23 changes: 23 additions & 0 deletions src/Renci.SshNet.IntegrationTests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<trace autoflush="true"/>
<sources>
<source name="SshNet.Logging" switchName="SshNetSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<!--<add name="SshDotNetTraceFile" />-->
<!--<add name="Console"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="SshNetSwitch" value="Verbose"/>
</switches>
<sharedListeners>
<add name="SshDotNetTraceFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="SshNetTrace.log">
<!--<filter type="System.Diagnostics.EventTypeFilter" initializeData="Warning" />-->
</add>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener" traceOutputOptions="DateTime,Timestamp,ThreadId"/>
</sharedListeners>
</system.diagnostics>
</configuration>
84 changes: 84 additions & 0 deletions src/Renci.SshNet.IntegrationTests/AuthenticationMethodFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace Renci.SshNet.IntegrationTests
{
public class AuthenticationMethodFactory
{
public PasswordAuthenticationMethod CreatePowerUserPasswordAuthenticationMethod()
{
var user = Users.Admin;
return new PasswordAuthenticationMethod(user.UserName, user.Password);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethod()
{
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PrivateKeyAuthenticationMethod CreateRegularUserMultiplePrivateKeyAuthenticationMethod()
{
var privateKeyFile1 = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa");
var privateKeyFile2 = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile1, privateKeyFile2);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithPassPhraseAuthenticationMethod()
{
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa_with_pass", "tester");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyWithEmptyPassPhraseAuthenticationMethod()
{
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_rsa_with_pass", null);
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PrivateKeyAuthenticationMethod CreateRegularUserPrivateKeyAuthenticationMethodWithBadKey()
{
var privateKeyFile = GetPrivateKey("Renci.SshNet.IntegrationTests.resources.client.id_noaccess.rsa");
return new PrivateKeyAuthenticationMethod(Users.Regular.UserName, privateKeyFile);
}

public PasswordAuthenticationMethod CreateRegulatUserPasswordAuthenticationMethod()
{
return new PasswordAuthenticationMethod(Users.Regular.UserName, Users.Regular.Password);
}

public PasswordAuthenticationMethod CreateRegularUserPasswordAuthenticationMethodWithBadPassword()
{
return new PasswordAuthenticationMethod(Users.Regular.UserName, "xxx");
}

public KeyboardInteractiveAuthenticationMethod CreateRegularUserKeyboardInteractiveAuthenticationMethod()
{
var keyboardInteractive = new KeyboardInteractiveAuthenticationMethod(Users.Regular.UserName);
keyboardInteractive.AuthenticationPrompt += (sender, args) =>
{
foreach (var authenticationPrompt in args.Prompts)
{
authenticationPrompt.Response = Users.Regular.Password;
}
};
return keyboardInteractive;
}

private PrivateKeyFile GetPrivateKey(string resourceName, string passPhrase = null)
{
using (var stream = GetResourceStream(resourceName))
{
return new PrivateKeyFile(stream, passPhrase);
}
}

private Stream GetResourceStream(string resourceName)
{
var type = GetType();
var resourceStream = type.Assembly.GetManifestResourceStream(resourceName);
if (resourceStream == null)
{
throw new ArgumentException($"Resource '{resourceName}' not found in assembly '{type.Assembly.FullName}'.", nameof(resourceName));
}
return resourceStream;
}
}
}
Loading

0 comments on commit 9593e87

Please sign in to comment.