mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-11 01:36:39 +00:00
Delete unused files
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
public partial class TestPortForwarding
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
public partial class TestSshCommand
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class AuthenticationMethodDerivativesTest
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("KeyboardInteractiveAuthenticationMethod: Pass null as username.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Keyboard_Test_Pass_Null()
|
||||
{
|
||||
new KeyboardInteractiveAuthenticationMethod(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("KeyboardInteractiveAuthenticationMethod: Pass String.Empty as username.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Keyboard_Test_Pass_Whitespace()
|
||||
{
|
||||
new KeyboardInteractiveAuthenticationMethod(string.Empty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("NoneAuthenticationMethod: Pass null as username.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void None_Test_Pass_Null()
|
||||
{
|
||||
new NoneAuthenticationMethod(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("NoneAuthenticationMethod: Pass String.Empty as username.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void None_Test_Pass_Whitespace()
|
||||
{
|
||||
new NoneAuthenticationMethod(string.Empty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PasswordAuthenticationMethod: Pass null as username, \"valid\" as password.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Password_Test_Pass_Null_Username()
|
||||
{
|
||||
new PasswordAuthenticationMethod(null, "valid");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PasswordAuthenticationMethod: Pass \"valid\" as username, null as password.")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Password_Test_Pass_Null_Password()
|
||||
{
|
||||
new PasswordAuthenticationMethod("valid", (string)null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PasswordAuthenticationMethod: Pass \"valid\" as username, \"valid\" as password.")]
|
||||
public void Password_Test_Pass_Valid_Username_And_Password()
|
||||
{
|
||||
new PasswordAuthenticationMethod("valid", "valid");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PasswordAuthenticationMethod: Pass String.Empty as username, \"valid\" as password.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Password_Test_Pass_Whitespace()
|
||||
{
|
||||
new PasswordAuthenticationMethod(string.Empty, "valid");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PasswordAuthenticationMethod: Pass \"valid\" as username, String.Empty as password.")]
|
||||
public void Password_Test_Pass_Valid()
|
||||
{
|
||||
new PasswordAuthenticationMethod("valid", string.Empty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PrivateKeyAuthenticationMethod: Pass null as username, null as password.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void PrivateKey_Test_Pass_Null()
|
||||
{
|
||||
new PrivateKeyAuthenticationMethod(null, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("AuthenticationMethod")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("PrivateKeyAuthenticationMethod: Pass String.Empty as username, null as password.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void PrivateKey_Test_Pass_Whitespace()
|
||||
{
|
||||
new PrivateKeyAuthenticationMethod(string.Empty, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
using Renci.SshNet.Common;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Renci.SshNet.Tests.Common
|
||||
{
|
||||
[TestClass()]
|
||||
public class DerDataTest
|
||||
{
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
// TODO: Restore those tests
|
||||
|
||||
//[TestMethod]
|
||||
//[TestCategory("DER")]
|
||||
//[Description("Long form, test example given in 8.1.3.5")]
|
||||
//[Owner("Kenneth_aa")]
|
||||
//[DeploymentItem("Renci.SshNet.dll")]
|
||||
//public void Test_Der_GetLength_LongForm_MustNotFail()
|
||||
//{
|
||||
// // Taken from example in 8.1.3.5
|
||||
// // L = 201 can be encoded as:
|
||||
// // 1 0 0 0 0 0 0 1
|
||||
// // 1 1 0 0 1 0 0 1
|
||||
// int length = 201;
|
||||
// byte[] expected = new byte[2]
|
||||
// {
|
||||
// 0x81, // 1 0 0 0 0 0 0 1
|
||||
// 0xC9 // 1 1 0 0 1 0 0 1
|
||||
// };
|
||||
|
||||
// byte[] actual = Helper_GetLength(length);
|
||||
// Helper_CompareByteArray(expected, actual);
|
||||
// Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
//}
|
||||
|
||||
//[TestMethod]
|
||||
//[TestCategory("DER")]
|
||||
//[Description("Short form, test example given in 8.1.3.5")]
|
||||
//[Owner("Kenneth_aa")]
|
||||
//[DeploymentItem("Renci.SshNet.dll")]
|
||||
//public void Test_Der_GetLength_ShortForm_MustNotFail()
|
||||
//{
|
||||
// int length = 127;
|
||||
// byte[] expected = new byte[1]
|
||||
// {
|
||||
// 0x7F // 0 1 1 1 1 1 1 1
|
||||
// };
|
||||
|
||||
// byte[] actual = Helper_GetLength(length);
|
||||
// Helper_CompareByteArray(expected, actual);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Compares 2 byte arrays.
|
||||
/// </summary>
|
||||
/// <param name="expected">Expected result.</param>
|
||||
/// <param name="actual">Actual result.</param>
|
||||
void Helper_CompareByteArray(byte[] expected, byte[] actual)
|
||||
{
|
||||
Assert.AreEqual(expected.Length, actual.Length, "Length mismatch: Expected.Length = {0} - Actual.Length = {1}", expected.Length, actual.Length);
|
||||
|
||||
for (int i = 0; i < expected.Length; i++)
|
||||
Assert.AreEqual<byte>(expected[i], actual[i], "Byte mismatch at index {0}", i);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Wrapper for calling DerData.GetLength()
|
||||
///// </summary>
|
||||
//byte[] Helper_GetLength(int length)
|
||||
//{
|
||||
// DerData_Accessor target = new DerData_Accessor();
|
||||
// return target.GetLength(length);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Tests.Common
|
||||
{
|
||||
[TestClass]
|
||||
public class PipeStreamTest
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("PipeStream")]
|
||||
public void Test_PipeStream_Write_Read_Buffer()
|
||||
{
|
||||
var testBuffer = new byte[1024];
|
||||
new Random().NextBytes(testBuffer);
|
||||
|
||||
var outputBuffer = new byte[1024];
|
||||
|
||||
using (var stream = new PipeStream())
|
||||
{
|
||||
stream.Write(testBuffer, 0, testBuffer.Length);
|
||||
|
||||
Assert.AreEqual(stream.Length, testBuffer.Length);
|
||||
|
||||
stream.Read(outputBuffer, 0, outputBuffer.Length);
|
||||
|
||||
Assert.AreEqual(stream.Length, 0);
|
||||
|
||||
Assert.IsTrue(testBuffer.IsEqualTo(outputBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("PipeStream")]
|
||||
public void Test_PipeStream_Write_Read_Byte()
|
||||
{
|
||||
var testBuffer = new byte[1024];
|
||||
new Random().NextBytes(testBuffer);
|
||||
|
||||
var outputBuffer = new byte[1024];
|
||||
|
||||
using (var stream = new PipeStream())
|
||||
{
|
||||
stream.Write(testBuffer, 0, testBuffer.Length);
|
||||
|
||||
Assert.AreEqual(stream.Length, testBuffer.Length);
|
||||
|
||||
stream.ReadByte();
|
||||
|
||||
Assert.AreEqual(stream.Length, testBuffer.Length - 1);
|
||||
|
||||
stream.ReadByte();
|
||||
|
||||
Assert.AreEqual(stream.Length, testBuffer.Length - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.IO;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.Security.Authentication;
|
||||
using Renci.SshNet.Common;
|
||||
using System.Net;
|
||||
|
||||
namespace Renci.SshNet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ConnectionTest
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Using_Correct_Password()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
[ExpectedException(typeof(SshAuthenticationException))]
|
||||
public void Test_Connect_Using_Invalid_Password()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password"))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Using_Rsa_Key_Without_PassPhrase()
|
||||
{
|
||||
MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS));
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Using_RsaKey_With_PassPhrase()
|
||||
{
|
||||
MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS));
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD)))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
[ExpectedException(typeof(SshPassPhraseNullOrEmptyException))]
|
||||
public void Test_Connect_Using_Key_With_Empty_PassPhrase()
|
||||
{
|
||||
MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS));
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, null)))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Using_DsaKey_Without_PassPhrase()
|
||||
{
|
||||
MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS));
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Using_DsaKey_With_PassPhrase()
|
||||
{
|
||||
MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS));
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD)))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
[ExpectedException(typeof(SshAuthenticationException))]
|
||||
public void Test_Connect_Using_Invalid_PrivateKey()
|
||||
{
|
||||
MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY));
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Using_Multiple_PrivateKeys()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME,
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY))),
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)), Resources.PASSWORD),
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)), Resources.PASSWORD),
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS))),
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS)))
|
||||
))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Authentication")]
|
||||
public void Test_Connect_Then_Reconnect()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_Host_Is_Null()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(null, Resources.USERNAME, Resources.PASSWORD);
|
||||
}
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_Username_Is_Null()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD);
|
||||
}
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_ConnectionInfo_Password_Is_Null()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[Description("Test passing whitespace to host parameter.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_Host_Is_Whitespace()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(" ", Resources.USERNAME,Resources.PASSWORD);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[Description("Test passing whitespace to username parameter.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_Username_Is_Whitespace()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD);
|
||||
}
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_ConnectionInfo_SmallPortNumber()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD);
|
||||
}
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[TestCategory("PasswordConnectionInfo")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_ConnectionInfo_BigPortNumber()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass null as proxy host.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_ProxyHost_Null()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, null, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass String.Empty as proxy host.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_ProxyHost_Empty()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, string.Empty, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass too large proxy port.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_ConnectionInfo_ProxyPort_Large()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.MaxValue, Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass too small proxy port.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_ConnectionInfo_ProxyPort_Small()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.MinValue, Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass a valid proxy port.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
public void Test_ConnectionInfo_ProxyPort_Valid()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass null as host.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_Host_Null()
|
||||
{
|
||||
new ConnectionInfo(null, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass String.Empty as host.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_ConnectionInfo_Host_Empty()
|
||||
{
|
||||
new ConnectionInfo(string.Empty, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass a valid host.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
public void Test_ConnectionInfo_Host_Valid()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass too large port.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_ConnectionInfo_Port_Large()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.MaxValue, Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass too small port.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_ConnectionInfo_Port_Small()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.MinValue, Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass a valid port.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
public void Test_ConnectionInfo_Port_Valid()
|
||||
{
|
||||
new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ConnectionInfo")]
|
||||
[Description("Pass null as session.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_ConnectionInfo_Authenticate_Null()
|
||||
{
|
||||
var ret = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
|
||||
ret.Authenticate(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[WorkItem(1140)]
|
||||
[TestCategory("BaseClient")]
|
||||
[Description("Test whether IsConnected is false after disconnect.")]
|
||||
[Owner("Kenneth_aa")]
|
||||
public void Test_BaseClient_IsConnected_True_After_Disconnect()
|
||||
{
|
||||
// 2012-04-29 - Kenneth_aa
|
||||
// The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait
|
||||
// for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning
|
||||
// anything about Socket's either.
|
||||
|
||||
var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD);
|
||||
|
||||
using (SftpClient client = new SftpClient(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
Assert.AreEqual<bool>(true, client.IsConnected, "IsConnected is not true after Connect() was called.");
|
||||
|
||||
client.Disconnect();
|
||||
|
||||
Assert.AreEqual<bool>(false, client.IsConnected, "IsConnected is true after Disconnect() was called.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Tests.ScpClientTests
|
||||
{
|
||||
public partial class UploadDownloadTest
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_File_20_Parallel_Upload_Download()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
var uploadFilenames = new string[20];
|
||||
for (int i = 0; i < uploadFilenames.Length; i++)
|
||||
{
|
||||
uploadFilenames[i] = Path.GetTempFileName();
|
||||
this.CreateTestFile(uploadFilenames[i], 1);
|
||||
}
|
||||
|
||||
Parallel.ForEach(uploadFilenames,
|
||||
(filename) =>
|
||||
{
|
||||
scp.Upload(new FileInfo(filename), Path.GetFileName(filename));
|
||||
});
|
||||
|
||||
Parallel.ForEach(uploadFilenames,
|
||||
(filename) =>
|
||||
{
|
||||
scp.Download(Path.GetFileName(filename), new FileInfo(string.Format("{0}.down", filename)));
|
||||
});
|
||||
|
||||
var result = from file in uploadFilenames
|
||||
where
|
||||
CalculateMD5(file) == CalculateMD5(string.Format("{0}.down", file))
|
||||
select file;
|
||||
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.IsTrue(result.Count() == uploadFilenames.Length);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_File_Upload_Download_Events()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
var uploadFilenames = new string[10];
|
||||
|
||||
for (int i = 0; i < uploadFilenames.Length; i++)
|
||||
{
|
||||
uploadFilenames[i] = Path.GetTempFileName();
|
||||
this.CreateTestFile(uploadFilenames[i], 1);
|
||||
}
|
||||
|
||||
var uploadedFiles = uploadFilenames.ToDictionary((filename) => Path.GetFileName(filename), (filename) => 0L);
|
||||
var downloadedFiles = uploadFilenames.ToDictionary((filename) => string.Format("{0}.down", Path.GetFileName(filename)), (filename) => 0L);
|
||||
|
||||
scp.Uploading += delegate(object sender, ScpUploadEventArgs e)
|
||||
{
|
||||
uploadedFiles[e.Filename] = e.Uploaded;
|
||||
};
|
||||
|
||||
scp.Downloading += delegate(object sender, ScpDownloadEventArgs e)
|
||||
{
|
||||
downloadedFiles[string.Format("{0}.down", e.Filename)] = e.Downloaded;
|
||||
};
|
||||
|
||||
|
||||
Parallel.ForEach(uploadFilenames,
|
||||
(filename) =>
|
||||
{
|
||||
scp.Upload(new FileInfo(filename), Path.GetFileName(filename));
|
||||
});
|
||||
|
||||
Parallel.ForEach(uploadFilenames,
|
||||
(filename) =>
|
||||
{
|
||||
scp.Download(Path.GetFileName(filename), new FileInfo(string.Format("{0}.down", filename)));
|
||||
});
|
||||
|
||||
var result = from uf in uploadedFiles
|
||||
from df in downloadedFiles
|
||||
where
|
||||
string.Format("{0}.down", uf.Key) == df.Key
|
||||
&& uf.Value == df.Value
|
||||
select uf;
|
||||
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.IsTrue(result.Count() == uploadFilenames.Length && uploadFilenames.Length == uploadedFiles.Count && uploadedFiles.Count == downloadedFiles.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Tests.ScpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public partial class UploadDownloadTest
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_File_Upload_Download()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string downloadedFileName = Path.GetTempFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 1);
|
||||
|
||||
scp.Upload(new FileInfo(uploadedFileName), Path.GetFileName(uploadedFileName));
|
||||
|
||||
scp.Download(Path.GetFileName(uploadedFileName), new FileInfo(downloadedFileName));
|
||||
|
||||
// Calculate MD5 value
|
||||
var uploadedHash = CalculateMD5(uploadedFileName);
|
||||
var downloadedHash = CalculateMD5(downloadedFileName);
|
||||
|
||||
File.Delete(uploadedFileName);
|
||||
File.Delete(downloadedFileName);
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.AreEqual(uploadedHash, downloadedHash);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_Stream_Upload_Download()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string downloadedFileName = Path.GetTempFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 1);
|
||||
|
||||
// Calculate has value
|
||||
using (var stream = File.OpenRead(uploadedFileName))
|
||||
{
|
||||
scp.Upload(stream, Path.GetFileName(uploadedFileName));
|
||||
}
|
||||
|
||||
using (var stream = File.OpenWrite(downloadedFileName))
|
||||
{
|
||||
scp.Download(Path.GetFileName(uploadedFileName), stream);
|
||||
}
|
||||
|
||||
// Calculate MD5 value
|
||||
var uploadedHash = CalculateMD5(uploadedFileName);
|
||||
var downloadedHash = CalculateMD5(downloadedFileName);
|
||||
|
||||
File.Delete(uploadedFileName);
|
||||
File.Delete(downloadedFileName);
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.AreEqual(uploadedHash, downloadedHash);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_10MB_File_Upload_Download()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string downloadedFileName = Path.GetTempFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 10);
|
||||
|
||||
scp.Upload(new FileInfo(uploadedFileName), Path.GetFileName(uploadedFileName));
|
||||
|
||||
scp.Download(Path.GetFileName(uploadedFileName), new FileInfo(downloadedFileName));
|
||||
|
||||
// Calculate MD5 value
|
||||
var uploadedHash = CalculateMD5(uploadedFileName);
|
||||
var downloadedHash = CalculateMD5(downloadedFileName);
|
||||
|
||||
File.Delete(uploadedFileName);
|
||||
File.Delete(downloadedFileName);
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.AreEqual(uploadedHash, downloadedHash);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_10MB_Stream_Upload_Download()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string downloadedFileName = Path.GetTempFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 10);
|
||||
|
||||
// Calculate has value
|
||||
using (var stream = File.OpenRead(uploadedFileName))
|
||||
{
|
||||
scp.Upload(stream, Path.GetFileName(uploadedFileName));
|
||||
}
|
||||
|
||||
using (var stream = File.OpenWrite(downloadedFileName))
|
||||
{
|
||||
scp.Download(Path.GetFileName(uploadedFileName), stream);
|
||||
}
|
||||
|
||||
// Calculate MD5 value
|
||||
var uploadedHash = CalculateMD5(uploadedFileName);
|
||||
var downloadedHash = CalculateMD5(downloadedFileName);
|
||||
|
||||
File.Delete(uploadedFileName);
|
||||
File.Delete(downloadedFileName);
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.AreEqual(uploadedHash, downloadedHash);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scp")]
|
||||
public void Test_Scp_Directory_Upload_Download()
|
||||
{
|
||||
using (var scp = new ScpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
scp.Connect();
|
||||
|
||||
var uploadDirectory = Directory.CreateDirectory(string.Format("{0}\\{1}", Path.GetTempPath(), Path.GetRandomFileName()));
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var subfolder = Directory.CreateDirectory(string.Format(@"{0}\folder_{1}", uploadDirectory.FullName, i));
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
this.CreateTestFile(string.Format(@"{0}\file_{1}", subfolder.FullName, j), 1);
|
||||
}
|
||||
this.CreateTestFile(string.Format(@"{0}\file_{1}", uploadDirectory.FullName, i), 1);
|
||||
}
|
||||
|
||||
scp.Upload(uploadDirectory, "uploaded_dir");
|
||||
|
||||
var downloadDirectory = Directory.CreateDirectory(string.Format("{0}\\{1}", Path.GetTempPath(), Path.GetRandomFileName()));
|
||||
|
||||
scp.Download("uploaded_dir", downloadDirectory);
|
||||
|
||||
var uploadedFiles = uploadDirectory.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
|
||||
var downloadFiles = downloadDirectory.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
var result = from f1 in uploadedFiles
|
||||
from f2 in downloadFiles
|
||||
where
|
||||
f1.FullName.Substring(uploadDirectory.FullName.Length) == f2.FullName.Substring(downloadDirectory.FullName.Length)
|
||||
&& CalculateMD5(f1.FullName) == CalculateMD5(f2.FullName)
|
||||
select f1;
|
||||
|
||||
var counter = result.Count();
|
||||
|
||||
scp.Disconnect();
|
||||
|
||||
Assert.IsTrue(counter == uploadedFiles.Length && uploadedFiles.Length == downloadFiles.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the test file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">Name of the file.</param>
|
||||
/// <param name="size">Size in megabytes.</param>
|
||||
private void CreateTestFile(string fileName, int size)
|
||||
{
|
||||
using (var testFile = File.Create(fileName))
|
||||
{
|
||||
|
||||
var random = new Random();
|
||||
for (int i = 0; i < 1024 * size; i++)
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
random.NextBytes(buffer);
|
||||
testFile.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static string CalculateMD5(string fileName)
|
||||
{
|
||||
using (FileStream file = new FileStream(fileName, FileMode.Open))
|
||||
{
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
byte[] retVal = md5.ComputeHash(file);
|
||||
file.Close();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < retVal.Length; i++)
|
||||
{
|
||||
sb.Append(retVal[i].ToString("x2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Renci.SshNet.Tests.Security.Cryptography
|
||||
{
|
||||
[TestClass]
|
||||
public class Ciphers
|
||||
{
|
||||
[TestMethod]
|
||||
public void Test_Cipher_AES_128_CBC()
|
||||
{
|
||||
var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
|
||||
var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 };
|
||||
var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 };
|
||||
var output = new byte[] { 0x19, 0x7f, 0x80, 0xd8, 0xc9, 0x89, 0xc4, 0xa7, 0xc6, 0xc6, 0x3f, 0x9f, 0x1e, 0x00, 0x1f, 0x72, 0xa7, 0x5e, 0xde, 0x40, 0x88, 0xa2, 0x72, 0xf2, 0xed, 0x3f, 0x81, 0x45, 0xb6, 0xbd, 0x45, 0x87, 0x15, 0xa5, 0x10, 0x92, 0x4a, 0x37, 0x9e, 0xa9, 0x80, 0x1c, 0x14, 0x83, 0xa3, 0x39, 0x45, 0x28 };
|
||||
var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.AesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
|
||||
var r = testCipher.Encrypt(input);
|
||||
|
||||
if (!r.SequenceEqual(output))
|
||||
Assert.Fail("Invalid encryption");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Cipher_3DES_CBC()
|
||||
{
|
||||
var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 };
|
||||
var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 };
|
||||
var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 };
|
||||
var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b };
|
||||
var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
|
||||
var r = testCipher.Encrypt(input);
|
||||
|
||||
if (!r.SequenceEqual(output))
|
||||
Assert.Fail("Invalid encryption");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Cipher_AES_128_CTR()
|
||||
{
|
||||
var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 };
|
||||
var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 };
|
||||
var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 };
|
||||
var output = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d };
|
||||
var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.AesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CtrCipherMode(iv), null);
|
||||
|
||||
var r = testCipher.Encrypt(input);
|
||||
|
||||
if (!r.SequenceEqual(output))
|
||||
Assert.Fail("Invalid encryption");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Cipher_Blowfish_128_CBC()
|
||||
{
|
||||
var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
|
||||
var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 };
|
||||
var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 };
|
||||
var output = new byte[] { 0x50, 0x49, 0xe0, 0xce, 0x98, 0x93, 0x8b, 0xec, 0x82, 0x7d, 0x14, 0x1b, 0x3e, 0xdc, 0xca, 0x63, 0xef, 0x36, 0x20, 0x67, 0x58, 0x63, 0x1f, 0x9c, 0xd2, 0x12, 0x6b, 0xca, 0xea, 0xd0, 0x78, 0x8b, 0x61, 0x50, 0x4f, 0xc4, 0x5b, 0x32, 0x91, 0xd6, 0x65, 0xcb, 0x74, 0xe5, 0x6e, 0xf5, 0xde, 0x14 };
|
||||
var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
|
||||
var r = testCipher.Encrypt(input);
|
||||
|
||||
if (!r.SequenceEqual(output))
|
||||
Assert.Fail("Invalid encryption");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Cipher_CastCipher_128_CBC()
|
||||
{
|
||||
var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
|
||||
var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 };
|
||||
var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 };
|
||||
var output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d };
|
||||
var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
|
||||
var r = testCipher.Encrypt(input);
|
||||
|
||||
if (!r.SequenceEqual(output))
|
||||
Assert.Fail("Invalid encryption");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Security;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using Renci.SshNet.Security.Cryptography.Ciphers;
|
||||
using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
|
||||
|
||||
namespace Renci.SshNet.Tests.Security
|
||||
{
|
||||
[TestClass]
|
||||
public class TestCipher
|
||||
{
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_TripleDESCBC_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_AEes128CBC_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_Aes192CBC_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_Aes256CBC_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_Aes128CTR_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_Aes192CTR_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_Aes256CTR_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_BlowfishCBC_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => { return new BlowfishCipher(key, new CbcCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Cipher")]
|
||||
public void Test_Cipher_Cast128CBC_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.Encryptions.Clear();
|
||||
connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); }));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Security;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using Renci.SshNet.Security.Cryptography;
|
||||
|
||||
namespace Renci.SshNet.Tests.Security
|
||||
{
|
||||
[TestClass]
|
||||
public class TestHMac
|
||||
{
|
||||
[TestMethod]
|
||||
public void Test_HMac_MD5_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.HmacAlgorithms.Clear();
|
||||
connectionInfo.HmacAlgorithms.Add("hmac-md5", (key) => { return new HMac<MD5Hash>(key.Take(16).ToArray());});
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_HMac_Sha1_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.HmacAlgorithms.Clear();
|
||||
connectionInfo.HmacAlgorithms.Add("hmac-sha1", (key) => { return new HMac<SHA1Hash>(key.Take(20).ToArray()); });
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Security;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using Renci.SshNet.Security.Cryptography;
|
||||
|
||||
namespace Renci.SshNet.Tests.Security
|
||||
{
|
||||
[TestClass]
|
||||
public class TestHostKey
|
||||
{
|
||||
[TestMethod]
|
||||
public void Test_HostKey_SshRsa_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.HostKeyAlgorithms.Clear();
|
||||
connectionInfo.HostKeyAlgorithms.Add("ssh-rsa", (data) => { return new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data); });
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_HostKey_SshDss_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.HostKeyAlgorithms.Clear();
|
||||
connectionInfo.HostKeyAlgorithms.Add("ssh-dss", (data) => { return new KeyHostAlgorithm("ssh-dss", new DsaKey(), data); });
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Security;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
|
||||
namespace Renci.SshNet.Tests.Security
|
||||
{
|
||||
[TestClass]
|
||||
public class TestKeyExchange
|
||||
{
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Key Exchange")]
|
||||
public void Test_KeyExchange_GroupExchange_Sha1_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.KeyExchangeAlgorithms.Clear();
|
||||
connectionInfo.KeyExchangeAlgorithms.Add("diffie-hellman-group-exchange-sha1", typeof(KeyExchangeDiffieHellmanGroupExchangeSha1));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Key Exchange")]
|
||||
public void Test_KeyExchange_Group14_Sha1_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.KeyExchangeAlgorithms.Clear();
|
||||
connectionInfo.KeyExchangeAlgorithms.Add("diffie-hellman-group14-sha1", typeof(KeyExchangeDiffieHellmanGroup14Sha1));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Key Exchange")]
|
||||
public void Test_KeyExchange_Group1_Sha1_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.KeyExchangeAlgorithms.Clear();
|
||||
connectionInfo.KeyExchangeAlgorithms.Add("diffie-hellman-group1-sha1", typeof(KeyExchangeDiffieHellmanGroup1Sha1));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Key Exchange")]
|
||||
public void Test_KeyExchange_GroupExchange_Sha256_Connection()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
connectionInfo.KeyExchangeAlgorithms.Clear();
|
||||
connectionInfo.KeyExchangeAlgorithms.Add("diffie-hellman-group-exchange-sha256", typeof(KeyExchangeDiffieHellmanGroupExchangeSha256));
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("Key Exchange")]
|
||||
public void Test_KeyExchange_Rekeying()
|
||||
{
|
||||
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
|
||||
|
||||
using (var client = new SshClient(connectionInfo))
|
||||
{
|
||||
client.Connect();
|
||||
// TODO: Add test to test re-keying
|
||||
Assert.Inconclusive();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.Security
|
||||
{
|
||||
[TestClass]
|
||||
public class TestPrivateKeyFile
|
||||
{
|
||||
[WorkItem(703), TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_PrivateKeyFile_EmptyFileName()
|
||||
{
|
||||
string fileName = string.Empty;
|
||||
var keyFile = new PrivateKeyFile(fileName);
|
||||
}
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_PrivateKeyFile_StreamIsNull()
|
||||
{
|
||||
Stream stream = null;
|
||||
var keyFile = new PrivateKeyFile(stream);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA()
|
||||
{
|
||||
var key = @"-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAoWv7yqk9zX9O5dG/+wOQbUnU8vlpwrfc/EFTKvOUY4GHOJ93
|
||||
AodLRJshNxI0fQZnPWwSEdsFlB5y3NoJg13uGNWBikMlgj01Zzz6QTfnmpmvgWD2
|
||||
30A5/METbBIIbXNk4Fx9jo9vMhpxn+yTOOq0grMicMfXaBL6xabUBogHVwpOmi50
|
||||
cxYQuK3lXvYgYtctQOE+ZlZJY48HVUaSDGWLIRxIvJnP5r1fn+7fWlxt91mfq+qx
|
||||
lE+HLOoaXMcoPAErZ5acGLiwKXl+iP9a6hi5LSQjxhXhQCUvjsvyNbCuyILyqkjE
|
||||
opCkU+YSqAa2uBB0bKXuIIqkUBX+NNo36+BCqwIDAQABAoIBAECq8Pl0qbS8zs/V
|
||||
ItMdz2tpC623a749SIOqa/YmFQl0J8bwY44Yw3edqkXUvkBkI1IBDJAorWh0dlGx
|
||||
6+O76pn6VuYcFlfBy7YrQJqGGfvem+f5/4zavyBZ/TzrUIMAmqYjh41oOwTYgTKv
|
||||
ZR+FL4G44BBMjyg7iklKl2ByeHZOoMGEpky8SBrt5RSOz+LrzXzEp9PmATrVTU38
|
||||
Dpph8pk6JcrpS5qPrJyHYdLJ5KKnEe+++T/Kzc53dQSicMDcRlaIoYUSghANIOs4
|
||||
3Z0kN3zkXuITYT2/fA7qn6EEQrHhIWW47gSf0ITv/DYvbqUVlmX/wPnScpuwpKhN
|
||||
ucbwXHkCgYEA07Qw7/UODfO1zh5hsxWteejxJ9HQnImD5MbLwSllP9RYbHyKIe/M
|
||||
+mFmrnU6bZ1O5pRYcqJu6keWxB9gmbKaOjlIS5Bz2tlm2cEujVm6zxBEB/VvxG2k
|
||||
+2mpi1vaoQFnyXMB6Q7LUKmuR6qcSHadUABmBfnrWC1bwBzKpI8voo0CgYEAwzJ1
|
||||
r02YQvl8RNJhY20+wfk1yfSEiHveJQzGVnlvxaXRr7gR4M4j4GaxyIYWZOTQcDpr
|
||||
p0Iaq+E1T27ey+TSn/15wK0MLm/WkixQ/qXjTibweOOhbeMKVN0ou/n8FWu51B1i
|
||||
ziU2FJnXhkk6wxSG32SnCdLU9cie1xcIhnSlSBcCgYEAhsi5Q3z0lsNsI6/KKheK
|
||||
HAzHxL9bnt4agARlYzS0xr+uEFv2IgcnrN1oX3g5W+KEgl8+NLXgAf7UKUeE3DYO
|
||||
5TTlJ17vtA0n40mQFuRjAEPt3FdR8nCQUpUCIby4ZDud1W8Ib1ZA8bkmQXCJEcWb
|
||||
AH1Qd0uXn8s5GAX8qmqTPF0CgYAAiT7xgFEOvgitV7aUw1QMzFZte5JxnYV6rJJO
|
||||
4n6AGHh+9w51g5ttnlqWpmehV0+LP13UU8Ym+rNeyHssLDC358ZR1SfXaM86D40Z
|
||||
ZfM937WBX36uApWgrgrSmVkr5ePYxUvkLQ38+H8zCzhyGLhWHLyotj+HfUmSZanM
|
||||
VL2veQKBgDpWFdCFgdE6ucaQuOSj4PbVCT2hTHuhuArP0NfSklcfeeGQedJfVupV
|
||||
baH2S2V/3qOgcLO8pEZTSzEeX/QbcJzqjMz0yj0KQssGDxkbmlYltk2ZEM2DRM0B
|
||||
Q4K/6SzJfIzSl/oYoB8xT0LY58qtBEurTZE81mmmiHV/gw6w+fQW
|
||||
-----END RSA PRIVATE KEY-----";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA_DES_CBC()
|
||||
{
|
||||
var key = @"-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-CBC,BD35E157CDD07CAD
|
||||
|
||||
VU1aEcNJaFe1bhZ+sEzv70KQB94Pu2H+VoemLXtyIVzEQJV9+cymnRYjkgzykJ5d
|
||||
s4J0vJMdiGtMH5lYRYEPQRNroOzJMwLngNyPiV8yLZARMR7tINdQyM7JBUFL4GfA
|
||||
+0Jl/e7cZaCRJKAKQZu5L5DGuP6488tG7bKY9Rhzys21hPF+ck/8Gzfp1vC91AxF
|
||||
zuy71e8ihEERF55DB5Ai1/lvEN15GUvkx14s0Oonfarxueu3dp/ch4P4PhzkY9Ci
|
||||
7/ONnlpfrBR7bLajcXUq2XAO21ftDZejk5m6y0Z0bl0L+HpbJk2zFJGtwM+B+T3h
|
||||
WkZqEK+RyTER67KUeecoKl297sh2YQtbxbdoTseUxktCb2/BSkpOHV5cgS64c3Ys
|
||||
zGbk4dUmKv4HFs4VJ7HD3Ix6qAhMJyGQXOqze1c7ky9NoU2e05HdfgI/9We0EZQJ
|
||||
PbequZZ4GOKnj4f70EbIEFyJldsJgijNCLKCafRYtygIs8zZkj/oE/S92iYZtesn
|
||||
q2wxBAat3ZYn6tpkXx+4u9bSZ+U9OfYijxBv2x+BnAf0nQ1zNqmTOolEAIEMLS60
|
||||
5WFWKVaOeqAP0Q185TEqpUFqcaTCycV2w1hN/XXuAiYqXaSYwg4ZtCmWmxbn20QH
|
||||
SMvRuY6MZSNNncgoLbm+ySq1yP1Z46kRsU1ufAyN3Jue+6DVd8wFrEOXfLJnCbFk
|
||||
Eykpd7vxzczHXWgrlakl2sPFy4ltcALc8ZhsmGO+goWNqwp4QPX4LMHeUsA9n86Q
|
||||
ABNV+KkCyIzp6FsFVqeHCxD8EoE/MuiuMHy/n0oEGj7zp9Moq5DHrgQDmdKnhrAG
|
||||
B2HqYlCH54LDKd3wlgT76/HJ8yviFZECY2q6Z1BnMzm2ikKLCyPBMKln2eaNUqss
|
||||
YNt/16DUgxpThoXfS1T8zbYHGCO0niPGMy6LYWFu0XBVgKrFcl+D1mz9vGC2CBto
|
||||
VA9YhIhjtlUWwmIaJAmlTXbHCXKWLjaK9/DbsnJOlUYG5XwTC+ntW24jZnDGkHzn
|
||||
Vj87JDijGzziM6qte/JM4WrUKxd6Zrvl6AaTqGH3aPxZWdFsKETfJhfbBX3vjw5+
|
||||
j6ltm4ZA+YXE2j8DLUQ8XMQlo66FUpiOj559aOXxfEb4HhJNrwo7VLsKuK56LdYb
|
||||
keQmeQr+4HkDGjD0T8+0sAOx82B0TkgWYaCFU1wmzIsny+wiQmMoKJIR3T3Mzb07
|
||||
9d5ncndS7DqcdAKMuG/F9w46QWW8G0veaJlV8ws7Ags1iBOxgTKrNsQNedB7B+zw
|
||||
cTqikGnDgxVfiXOBRzHq7F3ZH9HcT4SSxuM6y2YN91C2DmPbtZAwlJX5nkORANy7
|
||||
05kCAW/Md35jfVkZJsLsDDLNfRqukcWadkcKp3XvDB7/4WWFu8BrR9CHBY9j8hEt
|
||||
FC4FTxZnnoDnnVg5sC8rYB6avD/MiomOUGOlHgM3MMk/Ta7fmioauCUBR5oXa/We
|
||||
uhSoNyRY0/VZgE+fJ7P0Y5hzgnBDncVH5j57G0q4KTiTBDfuHBTLw+h5Htd5VBGS
|
||||
5PwhKfrAvIwetRWMyRhfjixPDtcWZ2jx20fWCVxpPp+3MxBtuMgn7A==
|
||||
-----END RSA PRIVATE KEY-----";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)), "12345");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA_DES_EDE3_CBC()
|
||||
{
|
||||
var key = @"-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,AF373EFF708479DF
|
||||
|
||||
iiuyZiL4qEI7nrJQL4gQZFyYYfji0GaNntX5rPrBlBLbwQySYq5d7ExLbv3tpB++
|
||||
V1sQBHV9vcxNdq+uYqFofOuKHBXebIJLwluS+qVHC4sZoaYJxFIizl0Cf2RQzPPH
|
||||
4XtAet8lrherbVm48YGAIcop9on87ILcOinNPf+0mT+wNLwFmymMkHmSByEMXU1m
|
||||
7CF0GWY31rtFgfEZGw8KUjrolA0/JKUn7taLEHKHrmsXJKH2O/c7DvxMgL7ldBFk
|
||||
mPVNQxsJfNGWsuU1/OzJjXWc5YYbziO2zKnJsCDpYOhATl92WABA7dPhI5jAJhWT
|
||||
N1xo2JStdgy/wnyrye4WWzRZdPL47hO1bbQnpcG+VAHMsTSNngJuy1Y0pezsb7OW
|
||||
2vmRM/I4QY2sPLhMOm9nbVfImJXIBukPbwpO5AtT3m+JwiyElnJcihDIaSkFTGOk
|
||||
89i2tKPxWrl3obdo9CYy8ukrFMDHiOP4EGRAYFbxHLI20QDuyBEw5TR90ClCFE7P
|
||||
ltM2NZRU/wCtF/4XEZ3P1KNVYu33d3hjr2J/fkba1xQ0xkCEfTXA8EgCA5ioQLie
|
||||
WzdJndxuWMDZkHHeFbrLDmUBBtcv2ubC9eL6ULyeTk/v9F3gbnh46Oye3KUG64Ur
|
||||
7H+NugCIDYyKdvcLl9O8JfspcNpg7ooLUliRMFCjIZI8G8V5fXqP1c4OTMaU0bGt
|
||||
kBiVZeULxpKhPe8Inx4E33C1TAaHGwYezxzr9QP162ib9iWQ6hAWHizkzOYC8vRx
|
||||
v0TKYR//1joVw7Wh27KOogoZEGy/gR3FZ5RxHai8inW22wlV9DobLJcib2dPkhMU
|
||||
6ACAhGNwmjr1oHnCmINmKaTCxGsiqs7R13k+3qbTF5SfofOIdNzgP0rlo1X4ckuU
|
||||
uA0jcNMk/R2qAn7xWDS1bdlBwj+85DlqWkKsrYuc9Jrll11HYCPoyIiY/kTahVLL
|
||||
VJ+FDIjRaHEK0knjfVMtB+E3aZhaHpvLBRFNsU1POoLkqer7CyUAxD4UJSC87kIc
|
||||
x8gX7kLR+ZTPuZ8Dx39jEpH+501bvoVxgDRstQkH0JTnOYJmLu/zobwAaX/+Xgdx
|
||||
ALu2YJZJ8ikkFU7vbqUdzvCYKiM4srbMa+E/5wqIr6G4SSk8FupWIJWsAkczbEkH
|
||||
PEfbVmWR0Lgh2i/RZU3kNqmUgV6DRfaML64z6dA13UIYIhVyg7ix6KYsJFJVKC5P
|
||||
YY8No7y29htDbPqjWDZ1Y95/9foKAKhv+iNOTLfIa7H7iWYFTLYXMLt3Vsux6V9V
|
||||
15+eUCe82yg7/MqcdL3IkX41AgQ6yijBWk761mbYJQ0TFNfPdtHxwKd9Rvj7nU+R
|
||||
g0XhLT/b9gBNNvJeo02Hgs0axNo1WtMvd/HqYFpEx7SJf/ClniJd+kBBpn29zbLA
|
||||
vaZAkxmIZc4rVeZEV8N14i9HfzmfjLM69wiMjfpO3H9nwzHHLhZCnzp483yTGKbc
|
||||
EGa4dkBt3eYQDPkiK68vTt6fUfAWtiqhjmHCpOi+bZF/EfbTmz1zGIRNscFOl1Ln
|
||||
bIk+F6YypdWnYjwQMr0e/RBZDVvsFH0XgHESq8hLEFXa6kWzQPIaVw==
|
||||
-----END RSA PRIVATE KEY-----";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)), "12345");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA_AES_128_CBC()
|
||||
{
|
||||
var key = @"
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: AES-128-CBC,A8B993177AE83E5476797236484F7CB6
|
||||
|
||||
tgMoS/2KhL+p/KslJVfX1RYiJtu3MlHA9gLu4Cq+yG63Yo4eLJmxV11CxSFGhamx
|
||||
mPhSh6KDxj5VV1BQm6jsY4sabZARZRuwwFnpGOHUsGCU7zfY3GTDhYfCHDhjXuhy
|
||||
LBloxq+5DafcagqFG1AZyJEJV0ZxGb0jbxWU13frKIEr5WvUbNN/XamBo2UffmNu
|
||||
Mumc/tl0sFih134PNAPvG53R99vuup5aAe7L72OmLEU3UqEH8Sm6i1Y0XKV/CB3I
|
||||
BoO7lsu8bk+QWl0ZsPULXEejub+P12Q08ySM6wXHDsTex6D09vIYZsoaG0lzbglJ
|
||||
LnMAXkVzvJOup5wYJgtpDJG1p1QtEvYjV94wyRoGWz9+7Nc9NlhgTeV02u6c2y0m
|
||||
GZ/ok7Jkc1HGLi9N3MIdLQ56l25DChZv0VqS95tmoRrtAnxXpk5MVsSVdBH8OC7E
|
||||
DyE++sdw6E5w3B596xJaJFnt3mz3+l5OdXd1/nASx3Oklq+nQ9GA2CKvOUYrQBqn
|
||||
JO30lMTm77iFXXUTitXFN7Z5KLNoBV8exHKhWTEqKq+BjBTrUx9y/gDQ3Bz/T1hN
|
||||
iuBtesIt5UdCpXKpG6klqfMZPDbRZCWCf6Kuby8+Lw5yCPgI6L5Wj2y69Cnbjva5
|
||||
1vbmVQkXmjBUlM29huE9iI9Qsoc2Ws0TflXaHpO5ovN0mhuU9UpTXNwwIZbsGZBI
|
||||
Fa8tToU8Z+xV/cktHJdwuFGWL9MwMvc6JdvRI/AZ9CVe/bahXlp/ETIX3xCs1dmm
|
||||
MU+xh9t+fje8Ms7HNmHmbS4SQPnf0GA9BaQsA7HzblzE/xYh0nrLirXGVagUv7UJ
|
||||
OPqBvxtrIbSbpgHjDkXcYlF1qdYBaTsh3CaDLcShBPz9GlC9XFh2S4imtJy+ESz9
|
||||
wRtZMEZ4R9LchrK8ElEQbPvv2M9UsjLEi70idWKcHAuws05/IIQ6AgRnRoiuRb5Q
|
||||
d71Hcbwt9X16PrfRSYRMNKoNmWQwTUvGFmIOc8HQYUPvHxdbTJYwha9rl+jecdd+
|
||||
ExoUx0xhR+bXWoFPMqRzvGrFEOfjZ+JycSInhY/3cop7+m1xEk3nlc2ZH0Bm2E73
|
||||
R1fkmJoj5/StLh2sNr+PCCVd2k70X/jfrgLvHqCtQPkdNlJnEV0tFchyaGealxCX
|
||||
JtsAHIH4YgE5Ojnxb3aFJAsELKzTHYalR2pz1rwR1LWeT2bBpGq7R7Mh2tUg7BKc
|
||||
1I9JfgzGi8X2+o+UHnzXPoVEEY1Snxkbni2jmQ06uoLaTow3qwUPExGE2J7CMOxZ
|
||||
KYUy2T1aGGnIIzhYPslPU5BPEPmTDukk76B5Rvam0fvXwE4mv4YR0kb/XHYN7cEl
|
||||
InDGFKnTcgLJfU/B+IxVoG9ZYIndlCgia1YMeXR+mqX0EdzCYmFxMNqW6QD5uzoC
|
||||
LTNOQtqwiDAvWbLZcqkzT6YnGjN6TBJEnVY4nvZRpyHxFN5qcQnjfMNqc/V47H0u
|
||||
GHy3G9CPTezdd7CGtb2sfDrls446rS8R9Zm15/2Y8sxysYXGZC/yv8a4QTnJn4lX
|
||||
omJXeM2qa9U4lK44MhtHj+eLveKQokkJEHN1yeRUMWcbb4r2QSzbpwjjfna0QKBP
|
||||
-----END RSA PRIVATE KEY-----
|
||||
";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)), "tester");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA_AES_192_CBC()
|
||||
{
|
||||
var key = @"-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: AES-192-CBC,0E34605476FC4C57886CE6350CD6F61E
|
||||
|
||||
yOzUZ81fSG2jBfhe7h/f2Uy7K86+VZFXVG3Y3qdQe6HD6kvQgQJLN+g8OVHan7vA
|
||||
CYnKImqS5fiTIwvsMxzVWtCeY2kJ9BMNeNIoLXebD5RV93lKPBgl0IldrkfJrg0w
|
||||
VNPkCHLFHWIOUA/bxYiXEeLRHuvndSkYH/JCzESiquf51chU4CIEmrbuvtvLXKta
|
||||
YPO9eCw0PP1QKO/fJVrUHfp6Bsvai/J0+PG19XzkKCMsewG0MkAqpkzQrAjaCJyj
|
||||
IwiqxxV72FIQDITgIQf5sY2yPzya/TjnBpu4m9D7TzQhCw9J2EDx61qvvKt3BDyq
|
||||
DahaY6/T/wgcYvdoJ3RzOiWmSLvXNc1PNVY9OfQXG2EtJa/xi2BHyeHgo/Kib7Wr
|
||||
nfaKgM7V998bLjiUnLK9CoD2WG3oSIrkAieNYbaD+RvU/mR/TNp5xMLMVJYduZo+
|
||||
EeyooM1a29WjOU8LPZ/AwNS4/DHnzEG1UBsUbKtyzQHiKU3JoW+5BkZ2tAs+VEWo
|
||||
b5Jx9XCKfL9JepP0Ti2adAlPYU9jH6YzTpZZfu+sd2+X/N8obYssUP6bFSB0KWL0
|
||||
s/nx7DKzbXo4P+Lm04FpmeqmP3h4lhsInoozr0tP3JJKTb99kGV480eVdqDuV+Af
|
||||
WJ4HLKlWxu8aHNnYb8/ATWEvh0Li0Qmx/ok8Ixa4XmHv2W0hjk7yhNewLpIwQ35X
|
||||
qJgQph96gGzMGZQ3r/TjNd7YiAfPishOC/TnitIZzC/Es+zZ7QsGgBP4j1hPLAjs
|
||||
OTrOvwkLuGUOoI9jJwm6343ZeGBFuWXJu0CSk4OF1EUMNziMUz9Rfw6xHSAnzff/
|
||||
YuQwDx+EtZLyyxFsfdhLjwcR38R6WoFqeDPpb3i6B5dYhHG6w60Yq5X1J4EnJgLL
|
||||
4zYqVLoC6rvUuslFX2EFGrTTZP/7qRi5H3ZhNzMf/KDVbTyhzzHx27LR/8vbScA0
|
||||
IFp5NhmbmBbH7PmEF3UoVwSn/u+5iF8dmuhuOqNidImAULLCf5qCSbJNvagk9sSf
|
||||
c6SdbX+EOkF6nTZYfSA0lT2u7rSfFw7khn6f+/ySRlQra7v3MBeeIuqrHEamlc73
|
||||
4hPKnl8eGcT3XvrpMnuiYADjJ4qOYzwx3YiKGqvdGzqd+ML6f2Tk31N7E53UDvSR
|
||||
96gYz7IiBEkbaQSV1iZ95iiv/0m2J8B7VR5FfwvLltrmD10Alq97Gpj7HUH/Yy+8
|
||||
Wu4ADp6wdSWXMki2+QUxucIqWJ4nViE6K4FJy3SbPwtJWxiLkLQibGxdZl0jHDOl
|
||||
F/FuWxjizKtOwn9rzQ+viVvYaQW1QTv5kS0d0L7FV2J8lQbsr8T86jUAJRASt5Cf
|
||||
/+Z628xFSwDZjITOjhHT2GJqho/eW4h/naWgMRoThFI2l+o8Ko+kBFZ+fvmnY+MU
|
||||
VcueeowDqsPawOj2YaaifvOzzsoP4C6Uu7K8UwAXE7gnKRWjIB4EJZLEaTXBpIUM
|
||||
BcBcYCqd1X+JFQxp7fID+EGxlMfTjdZM4c51y67EHzMquZSiLEGBQgE8KiJclsIN
|
||||
/PjY3hlwcZpyTEnqTYLnhL5SG/1fskUWPLaJ66u+aGoo9bcfOq9AE0yzPsl6MCes
|
||||
-----END RSA PRIVATE KEY-----";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)), "12345");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("olegkap")]
|
||||
[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA_AES_256_CBC()
|
||||
{
|
||||
var key = @"-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: AES-256-CBC,063DE67AE11456C89BCE9D4A21BE3DFB
|
||||
|
||||
6mS1GhCjAg5mEwMFcKRJwg1uxCeY3ekJNCQewIN9NSI5A8prBOQ+JSyWAsn6c3Gw
|
||||
OeRyur+5dxMFdt5Hz1CBi9EePvhVyMry7U5U86BWB0HgtDAD02b324sfc6Wk+kj5
|
||||
PZvuKyXDiqdwy0rsbBUT+bLtXjCI4Ws1k/KbbF0OqGhFJJvErNU5x8zMD9mqp92R
|
||||
D8ZZ/F8Sks3V/JeUisAF86sgMfVCELJobn5Zq/IaUyzQwC6IEL+Sy5fSBB5NHiex
|
||||
NDIJg2RW79uLbufCpuoMPS/GKydf4dq0L5MwvKeqtUgf9Wddc+ZAE4+q1Xz/T8iN
|
||||
3IMqsQfVbYjVK7uTaVGKH+Ew77Qryj01Vg+zyzdf4UwOV3XXQKLVCjNxpMCVtoq7
|
||||
S45M3Ad7598vb7ooa/BFCIcEM8TkuzPnuttLqjzXEzUcA5kqm3kV14IKtlexBfNT
|
||||
tarbidlZcOinvJaoIT3baP4rVnEWDKcxpc+UzNU5RRty6l0zpRmw/9RQ5+FKreh8
|
||||
eXDHD8TT8ArdaREFM8J2OGpkmIK5sLhhYi9gnTopmKIHn8OAXusmQosEOzS6kGxk
|
||||
aFtZezXSCBGgXp5RsrBGGx3oXWHGuWbEFXAq+M7PKXMQe5rLRv6sQdfTFSB5hgNK
|
||||
82P8UzV1wWtAX4JYAhRh2zA8agY2arbNvbjRyjSbp9HNVBgSbVQ60JInesOqLxEg
|
||||
XURuCYp4F8AeHzyO805MTNpcX7PZT2kOxp9sKKABJ9BJ0RoSWa0LJqXzGCHvrExE
|
||||
g7XY/ZfDFZlPLbQnrOgVlYh7pzyfyKB74/oXHkonAisRfsgnQ87yT2DmcHNP6Cek
|
||||
eae2nrpx2yn9Bf8rYdpmJgNxduO8IZvpn84xEyPqK+FbQsdOefBvsg5TgfzETkh/
|
||||
SJjzbqCTDa3XHEUCInixo/wT7FxT8KR9vk43FGPNVRUvPB2GNxe9ZwLYIir64hcQ
|
||||
CpdA3ipVx4/jVzWQH8KXG9UP9TDAKXEvbndLnr2taPnUdAnznwHN2EkfzS/PrFG4
|
||||
/j3l1+VY2AyRybbCTI2iuwJPnKdxOR5oWW6I2Ksfq93Oy+NQz/zasjyNpCZBZWds
|
||||
5gBmwiNk2Xzq7ikEVtVk3osOQRw/u9GbretfaT9jtClALL3DFbOzL4WxA+0NJqpd
|
||||
NB2MohOJa1BJjdfh6x6EVhugH85Y9uYyz/MQj7piljAJY96190n3Q86b/7phfwuD
|
||||
A/ixS42nqpyOPO+EjiWFerFVTJ3iBj7GXXOZGwCrZfpTbqE7OdTDnE3Vr4MO/Etq
|
||||
kSDmJ/+4SFFh80YwYVERDNFdDxCYxx5AnxaBFwbqjzatTV/btgGVabIf6zm2L6aY
|
||||
BJ5wnBZnRnsRaIMehDQmTjioMcyHBSMqId+LYQp+KFpBXqXQTEjJPnq+t4o2FF/N
|
||||
8yoKR8BX6HXSO5qUndI8emwec1JeveiRai6SDnEz1EFfetYXImR290mlqt0aRjQk
|
||||
t/HXRv+fmDQk5hJbCPICydcVSRyrbzxKkppVceEf9NwkBT1MBsOZIFJ3s3A9I72n
|
||||
XPIab5czlgSLYA/U9nEg2XU21hKD2kRH1OF0WSlpNhN2SJFViVqlC3v36MgHoWNh
|
||||
-----END RSA PRIVATE KEY-----";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)), "12345");
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
//[Owner("olegkap")]
|
||||
//[TestCategory("PrivateKey")]
|
||||
public void Test_PrivateKey_RSA_DES_EDE3_CFB()
|
||||
{
|
||||
var key = @"-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CFB,81C75CC63A21DFFB
|
||||
|
||||
7BCpj4mM2LTaWGP2f/IK8+Zd7XssLHtagETCURfg+x+IYhOOsW/qORNBeOL4lT8G
|
||||
s8ymGJIMjNC0aGwJb214Kp19ajMlRN8IaHtw1QD3BYIxFSx35DSWd6WrECcdaJCm
|
||||
FZ5y+rXf0NMUOUKg9xXF+Xnbucau3QN4NiLBB50oJyRIRco6Wy/9AB1yKrZsll4N
|
||||
3+1XnnXZuanvIugi8TybUgzyrGE1dqwyGjHtN+bf8hWu8jrnx3AkjmzXJ+yiGbd4
|
||||
w/JYfCzyVsEZuEzkn62johwNpwcuXFYEXxSSU444/TZf2BuuvvpkbCltkfvhOC3z
|
||||
fp1DOtToaZadwHsH8laB+HPktisfetoPaQdqi/fGgqiERzDq9Xy7wY9JXdT65WeU
|
||||
mh+USBy7mF6I57UgRM6AAZLvrJmG+hE8GYezThT9ZEnFyumrQgt8sTdWWFStYJcW
|
||||
jlohuNO8c4IXwvXfVgafaIIAcFUcAKk/XgSLjMcn7YyBlaR6qIdwLLfRNEspv9mR
|
||||
IF0M2ua4vZRLJfn+NOcs0n10v0jUFgMXoIqDr86OB3pW3ud/lET6bz6QYO3rNHW4
|
||||
NtAmD2wwl66nuq2d9uLUSSkQj5spVDbFzfvnZCN3yl4hdyWlmzRJqybyr5xTIbT7
|
||||
x5JF/eg3xq8weaZrFqq7r5uIhDYI7/sexxL9M/8nyV8COUYkDxxISbNpoDuCKbv8
|
||||
fyIX92mGQtM8D7YftvCbEr8kw1fga9XhkDdOEuBzKZyIAD50xE39rFFMNNq8l8/Y
|
||||
Gxo8zq0rW/IsrwvhWLLGtvmy68Be+WAi/mDHf6x4
|
||||
-----END RSA PRIVATE KEY-----";
|
||||
new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(key)), "1234567890");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ChangeDirectory
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_ChangeDirectory_Root_Dont_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.ChangeDirectory("/asdasd");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.ChangeDirectory("/asdasd/");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_ChangeDirectory_Subfolder_Dont_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.ChangeDirectory("/asdasd/sssddds");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.ChangeDirectory("/asdasd/sssddds/");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_ChangeDirectory_Which_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.ChangeDirectory("/usr");
|
||||
Assert.AreEqual("/usr", sftp.WorkingDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_ChangeDirectory_Which_Exists_With_Slash()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.ChangeDirectory("/usr/");
|
||||
Assert.AreEqual("/usr", sftp.WorkingDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for CreateDirectoryTest
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class CreateDirectoryTest
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SshConnectionException))]
|
||||
public void Test_Sftp_CreateDirectory_Without_Connecting()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.CreateDirectory("test");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_CreateDirectory_In_Current_Location()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.CreateDirectory("test");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPermissionDeniedException))]
|
||||
public void Test_Sftp_CreateDirectory_In_Forbidden_Directory()
|
||||
{
|
||||
if (Resources.USERNAME == "root")
|
||||
Assert.Fail("Must not run this test as root!");
|
||||
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.CreateDirectory("/sbin/test");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_CreateDirectory_Invalid_Path()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.CreateDirectory("/abcdefg/abcefg");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SshException))]
|
||||
public void Test_Sftp_CreateDirectory_Already_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.CreateDirectory("test");
|
||||
|
||||
sftp.CreateDirectory("test");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to CreateDirectory.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_CreateDirectory_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.CreateDirectory(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class DeleteDirectoryTest
|
||||
{
|
||||
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SshConnectionException))]
|
||||
public void Test_Sftp_DeleteDirectory_Without_Connecting()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.DeleteDirectory("test");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_DeleteDirectory_Which_Doesnt_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.DeleteDirectory("abcdef");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPermissionDeniedException))]
|
||||
public void Test_Sftp_DeleteDirectory_Which_No_Permissions()
|
||||
{
|
||||
if (Resources.USERNAME == "root")
|
||||
Assert.Fail("Must not run this test as root!");
|
||||
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.DeleteDirectory("/usr");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_DeleteDirectory()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.CreateDirectory("abcdef");
|
||||
sftp.DeleteDirectory("abcdef");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to DeleteDirectory.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_DeleteDirectory_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.DeleteDirectory(null);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for DeleteFileTest
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class DeleteFileTest
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to DeleteFile.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_DeleteFile_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.DeleteFile(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class GetTest
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Get_Root_Directory()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
var directory = sftp.Get("/");
|
||||
|
||||
Assert.AreEqual("/", directory.FullName);
|
||||
Assert.IsTrue(directory.IsDirectory);
|
||||
Assert.IsFalse(directory.IsRegularFile);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Get_Invalid_Directory()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.Get("/xyz");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Get_File()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.UploadFile(new MemoryStream(), "abc.txt");
|
||||
|
||||
var file = sftp.Get("abc.txt");
|
||||
|
||||
Assert.AreEqual("/home/tester/abc.txt", file.FullName);
|
||||
Assert.IsTrue(file.IsRegularFile);
|
||||
Assert.IsFalse(file.IsDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to Get.")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_Get_File_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var file = sftp.Get(null);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Get_International_File()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.UploadFile(new MemoryStream(), "test-üöä-");
|
||||
|
||||
var file = sftp.Get("test-üöä-");
|
||||
|
||||
Assert.AreEqual("/home/tester/test-üöä-", file.FullName);
|
||||
Assert.IsTrue(file.IsRegularFile);
|
||||
Assert.IsFalse(file.IsDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ListDirectoryTest
|
||||
{
|
||||
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
//client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SshConnectionException))]
|
||||
public void Test_Sftp_ListDirectory_Without_Connecting()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
var files = sftp.ListDirectory(".");
|
||||
foreach (var file in files)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPermissionDeniedException))]
|
||||
public void Test_Sftp_ListDirectory_Permission_Denied()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var files = sftp.ListDirectory("/root");
|
||||
foreach (var file in files)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_ListDirectory_Not_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var files = sftp.ListDirectory("/asdfgh");
|
||||
foreach (var file in files)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_ListDirectory_Current()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var files = sftp.ListDirectory(".");
|
||||
|
||||
Assert.IsTrue(files.Count() > 0);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_ListDirectory_Empty()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var files = sftp.ListDirectory(string.Empty);
|
||||
|
||||
Assert.IsTrue(files.Count() > 0);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to ListDirectory.")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_Sftp_ListDirectory_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var files = sftp.ListDirectory(null);
|
||||
|
||||
Assert.IsTrue(files.Count() > 0);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_ListDirectory_HugeDirectory()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
// Create 10000 directory items
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
sftp.CreateDirectory(string.Format("test_{0}", i));
|
||||
Debug.WriteLine("Created " + i);
|
||||
}
|
||||
|
||||
var files = sftp.ListDirectory(".");
|
||||
|
||||
// Ensure that directory has at least 10000 items
|
||||
Assert.IsTrue(files.Count() > 10000);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_Change_Directory()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester");
|
||||
|
||||
sftp.CreateDirectory("test1");
|
||||
|
||||
sftp.ChangeDirectory("test1");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1");
|
||||
|
||||
sftp.CreateDirectory("test1_1");
|
||||
sftp.CreateDirectory("test1_2");
|
||||
sftp.CreateDirectory("test1_3");
|
||||
|
||||
var files = sftp.ListDirectory(".");
|
||||
|
||||
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory)));
|
||||
|
||||
sftp.ChangeDirectory("test1_1");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1");
|
||||
|
||||
sftp.ChangeDirectory("../test1_2");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_2");
|
||||
|
||||
sftp.ChangeDirectory("..");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1");
|
||||
|
||||
sftp.ChangeDirectory("..");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester");
|
||||
|
||||
files = sftp.ListDirectory("test1/test1_1");
|
||||
|
||||
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory)));
|
||||
|
||||
sftp.ChangeDirectory("test1/test1_1");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1");
|
||||
|
||||
sftp.ChangeDirectory("/home/tester/test1/test1_1");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1");
|
||||
|
||||
sftp.ChangeDirectory("/home/tester/test1/test1_1/../test1_2");
|
||||
|
||||
Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_2");
|
||||
|
||||
sftp.ChangeDirectory("../../");
|
||||
|
||||
sftp.DeleteDirectory("test1/test1_1");
|
||||
sftp.DeleteDirectory("test1/test1_2");
|
||||
sftp.DeleteDirectory("test1/test1_3");
|
||||
sftp.DeleteDirectory("test1");
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to ChangeDirectory.")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_Sftp_ChangeDirectory_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.ChangeDirectory(null);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test calling EndListDirectory method more then once.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_Call_EndListDirectory_Twice()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
var ar = sftp.BeginListDirectory("/", null, null);
|
||||
var result = sftp.EndListDirectory(ar);
|
||||
var result1 = sftp.EndListDirectory(ar);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using Renci.SshNet.Sftp;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ProxyTest
|
||||
{
|
||||
[TestMethod]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("Test connect to remote server via a SOCKS4 proxy server.")]
|
||||
[TestCategory("Proxy")]
|
||||
public void Test_Sftp_Connect_Via_Socks4()
|
||||
{
|
||||
var connInfo = new PasswordConnectionInfo(Resources.HOST,Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks4, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
|
||||
using (var client = new SftpClient(connInfo))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var ret = client.GetLastWriteTime(".");
|
||||
Debug.WriteLine(ret, "GetLastWriteTime");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("Test connect to remote server via a TCP SOCKS5 proxy server.")]
|
||||
[TestCategory("Proxy")]
|
||||
public void Test_Sftp_Connect_Via_TcpSocks5()
|
||||
{
|
||||
var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks5, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
|
||||
using (var client = new SftpClient(connInfo))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var ret = client.GetLastWriteTime(".");
|
||||
Debug.WriteLine(ret, "GetLastWriteTime");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("Test connect to remote server via a HTTP proxy server.")]
|
||||
[TestCategory("Proxy")]
|
||||
public void Test_Sftp_Connect_Via_HttpProxy()
|
||||
{
|
||||
var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Http, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
|
||||
using (var client = new SftpClient(connInfo))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var ret = client.GetLastWriteTime(".");
|
||||
Debug.WriteLine(ret, "GetLastWriteTime");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class RenameFileTest
|
||||
{
|
||||
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_Rename_File()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string remoteFileName1 = Path.GetRandomFileName();
|
||||
string remoteFileName2 = Path.GetRandomFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 1);
|
||||
|
||||
using (var file = File.OpenRead(uploadedFileName))
|
||||
{
|
||||
sftp.UploadFile(file, remoteFileName1);
|
||||
}
|
||||
|
||||
sftp.RenameFile(remoteFileName1, remoteFileName2);
|
||||
|
||||
File.Delete(uploadedFileName);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to RenameFile.")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_Sftp_RenameFile_Null()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
sftp.RenameFile(null, null);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the test file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">Name of the file.</param>
|
||||
/// <param name="size">Size in megabytes.</param>
|
||||
private void CreateTestFile(string fileName, int size)
|
||||
{
|
||||
using (var testFile = File.Create(fileName))
|
||||
{
|
||||
|
||||
var random = new Random();
|
||||
for (int i = 0; i < 1024 * size; i++)
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
random.NextBytes(buffer);
|
||||
testFile.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class SftpFileStreamTest
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class SftpFileTest
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_SftpFile_MoveTo()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string remoteFileName = Path.GetRandomFileName();
|
||||
string newFileName = Path.GetRandomFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 1);
|
||||
|
||||
using (var file = File.OpenRead(uploadedFileName))
|
||||
{
|
||||
sftp.UploadFile(file, remoteFileName);
|
||||
}
|
||||
|
||||
var sftpFile = sftp.Get(remoteFileName);
|
||||
|
||||
sftpFile.MoveTo(newFileName);
|
||||
|
||||
Assert.AreEqual(newFileName, sftpFile.Name);
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates the test file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">Name of the file.</param>
|
||||
/// <param name="size">Size in megabytes.</param>
|
||||
private void CreateTestFile(string fileName, int size)
|
||||
{
|
||||
using (var testFile = File.Create(fileName))
|
||||
{
|
||||
|
||||
var random = new Random();
|
||||
for (int i = 0; i < 1024 * size; i++)
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
random.NextBytes(buffer);
|
||||
testFile.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class SynchronizeDirectoriesTest
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_SynchronizeDirectories()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
|
||||
string sourceDir = Path.GetDirectoryName(uploadedFileName);
|
||||
string destDir = "/";
|
||||
string searchPattern = Path.GetFileName(uploadedFileName);
|
||||
var upLoadedFiles = sftp.SynchronizeDirectories(sourceDir, destDir, searchPattern);
|
||||
|
||||
Assert.IsTrue(upLoadedFiles.Count() > 0);
|
||||
|
||||
foreach (var file in upLoadedFiles)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_BeginSynchronizeDirectories()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
|
||||
string sourceDir = Path.GetDirectoryName(uploadedFileName);
|
||||
string destDir = "/";
|
||||
string searchPattern = Path.GetFileName(uploadedFileName);
|
||||
|
||||
var asyncResult = sftp.BeginSynchronizeDirectories(sourceDir,
|
||||
destDir,
|
||||
searchPattern,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
// Wait for the WaitHandle to become signaled.
|
||||
asyncResult.AsyncWaitHandle.WaitOne(1000);
|
||||
|
||||
var upLoadedFiles = sftp.EndSynchronizeDirectories(asyncResult);
|
||||
|
||||
Assert.IsTrue(upLoadedFiles.Count() > 0);
|
||||
|
||||
foreach (var file in upLoadedFiles)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
// Close the wait handle.
|
||||
asyncResult.AsyncWaitHandle.Close();
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,549 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using Renci.SshNet.Sftp;
|
||||
using System.Threading;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class UploadDownloadFileTest
|
||||
{
|
||||
[TestInitialize()]
|
||||
public void CleanCurrentFolder()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_Upload_And_Download_1MB_File()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string remoteFileName = Path.GetRandomFileName();
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 1);
|
||||
|
||||
// Calculate has value
|
||||
var uploadedHash = CalculateMD5(uploadedFileName);
|
||||
|
||||
using (var file = File.OpenRead(uploadedFileName))
|
||||
{
|
||||
sftp.UploadFile(file, remoteFileName);
|
||||
}
|
||||
|
||||
string downloadedFileName = Path.GetTempFileName();
|
||||
|
||||
using (var file = File.OpenWrite(downloadedFileName))
|
||||
{
|
||||
sftp.DownloadFile(remoteFileName, file);
|
||||
}
|
||||
|
||||
var downloadedHash = CalculateMD5(downloadedFileName);
|
||||
|
||||
sftp.DeleteFile(remoteFileName);
|
||||
|
||||
File.Delete(uploadedFileName);
|
||||
File.Delete(downloadedFileName);
|
||||
|
||||
sftp.Disconnect();
|
||||
|
||||
Assert.AreEqual(uploadedHash, downloadedHash);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPermissionDeniedException))]
|
||||
public void Test_Sftp_Upload_Forbidden()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
string remoteFileName = "/root/1";
|
||||
|
||||
this.CreateTestFile(uploadedFileName, 1);
|
||||
|
||||
using (var file = File.OpenRead(uploadedFileName))
|
||||
{
|
||||
sftp.UploadFile(file, remoteFileName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPermissionDeniedException))]
|
||||
public void Test_Sftp_Download_Forbidden()
|
||||
{
|
||||
if (Resources.USERNAME == "root")
|
||||
Assert.Fail("Must not run this test as root!");
|
||||
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string remoteFileName = "/root/.profile";
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
sftp.DownloadFile(remoteFileName, ms);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(SftpPathNotFoundException))]
|
||||
public void Test_Sftp_Download_File_Not_Exists()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string remoteFileName = "/xxx/eee/yyy";
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
sftp.DownloadFile(remoteFileName, ms);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_Multiple_Async_Upload_And_Download_10Files_5MB_Each()
|
||||
{
|
||||
var maxFiles = 10;
|
||||
var maxSize = 5;
|
||||
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
var testInfoList = new Dictionary<string, TestInfo>();
|
||||
|
||||
for (int i = 0; i < maxFiles; i++)
|
||||
{
|
||||
var testInfo = new TestInfo();
|
||||
testInfo.UploadedFileName = Path.GetTempFileName();
|
||||
testInfo.DownloadedFileName = Path.GetTempFileName();
|
||||
testInfo.RemoteFileName = Path.GetRandomFileName();
|
||||
|
||||
this.CreateTestFile(testInfo.UploadedFileName, maxSize);
|
||||
|
||||
// Calculate hash value
|
||||
testInfo.UploadedHash = CalculateMD5(testInfo.UploadedFileName);
|
||||
|
||||
testInfoList.Add(testInfo.RemoteFileName, testInfo);
|
||||
}
|
||||
|
||||
var uploadWaitHandles = new List<WaitHandle>();
|
||||
|
||||
// Start file uploads
|
||||
foreach (var remoteFile in testInfoList.Keys)
|
||||
{
|
||||
var testInfo = testInfoList[remoteFile];
|
||||
testInfo.UploadedFile = File.OpenRead(testInfo.UploadedFileName);
|
||||
|
||||
testInfo.UploadResult = sftp.BeginUploadFile(testInfo.UploadedFile,
|
||||
remoteFile,
|
||||
null,
|
||||
null) as SftpUploadAsyncResult;
|
||||
|
||||
|
||||
uploadWaitHandles.Add(testInfo.UploadResult.AsyncWaitHandle);
|
||||
}
|
||||
|
||||
// Wait for upload to finish
|
||||
bool uploadCompleted = false;
|
||||
while (!uploadCompleted)
|
||||
{
|
||||
// Assume upload completed
|
||||
uploadCompleted = true;
|
||||
|
||||
foreach (var testInfo in testInfoList.Values)
|
||||
{
|
||||
var sftpResult = testInfo.UploadResult;
|
||||
|
||||
if (!testInfo.UploadResult.IsCompleted)
|
||||
{
|
||||
uploadCompleted = false;
|
||||
}
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
// End file uploads
|
||||
foreach (var remoteFile in testInfoList.Keys)
|
||||
{
|
||||
var testInfo = testInfoList[remoteFile];
|
||||
|
||||
sftp.EndUploadFile(testInfo.UploadResult);
|
||||
testInfo.UploadedFile.Dispose();
|
||||
}
|
||||
|
||||
// Start file downloads
|
||||
|
||||
var downloadWaitHandles = new List<WaitHandle>();
|
||||
|
||||
foreach (var remoteFile in testInfoList.Keys)
|
||||
{
|
||||
var testInfo = testInfoList[remoteFile];
|
||||
testInfo.DownloadedFile = File.OpenWrite(testInfo.DownloadedFileName);
|
||||
testInfo.DownloadResult = sftp.BeginDownloadFile(remoteFile,
|
||||
testInfo.DownloadedFile,
|
||||
null,
|
||||
null) as SftpDownloadAsyncResult;
|
||||
|
||||
downloadWaitHandles.Add(testInfo.DownloadResult.AsyncWaitHandle);
|
||||
}
|
||||
|
||||
// Wait for download to finish
|
||||
bool downloadCompleted = false;
|
||||
while (!downloadCompleted)
|
||||
{
|
||||
// Assume download completed
|
||||
downloadCompleted = true;
|
||||
|
||||
foreach (var testInfo in testInfoList.Values)
|
||||
{
|
||||
var sftpResult = testInfo.DownloadResult;
|
||||
|
||||
if (!testInfo.DownloadResult.IsCompleted)
|
||||
{
|
||||
downloadCompleted = false;
|
||||
}
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
var hashMatches = true;
|
||||
var uploadDownloadSizeOk = true;
|
||||
// End file downloads
|
||||
foreach (var remoteFile in testInfoList.Keys)
|
||||
{
|
||||
var testInfo = testInfoList[remoteFile];
|
||||
|
||||
sftp.EndDownloadFile(testInfo.DownloadResult);
|
||||
|
||||
testInfo.DownloadedFile.Dispose();
|
||||
|
||||
testInfo.DownloadedHash = CalculateMD5(testInfo.DownloadedFileName);
|
||||
|
||||
if (!(testInfo.UploadResult.UploadedBytes > 0 && testInfo.DownloadResult.DownloadedBytes > 0 && testInfo.DownloadResult.DownloadedBytes == testInfo.UploadResult.UploadedBytes))
|
||||
{
|
||||
uploadDownloadSizeOk = false;
|
||||
}
|
||||
|
||||
if (!testInfo.DownloadedHash.Equals(testInfo.UploadedHash))
|
||||
{
|
||||
hashMatches = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up after test
|
||||
foreach (var remoteFile in testInfoList.Keys)
|
||||
{
|
||||
var testInfo = testInfoList[remoteFile];
|
||||
|
||||
sftp.DeleteFile(remoteFile);
|
||||
|
||||
File.Delete(testInfo.UploadedFileName);
|
||||
File.Delete(testInfo.DownloadedFileName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
|
||||
Assert.IsTrue(hashMatches, "Hash does not match");
|
||||
Assert.IsTrue(uploadDownloadSizeOk, "Uploaded and downloaded bytes does not match");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test that delegates passed to BeginUploadFile, BeginDownloadFile and BeginListDirectory are actually called.")]
|
||||
public void Test_Sftp_Ensure_Async_Delegates_Called_For_BeginFileUpload_BeginFileDownload_BeginListDirectory()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string remoteFileName = Path.GetRandomFileName();
|
||||
string localFileName = Path.GetRandomFileName();
|
||||
bool uploadDelegateCalled = false;
|
||||
bool downloadDelegateCalled = false;
|
||||
bool listDirectoryDelegateCalled = false;
|
||||
IAsyncResult asyncResult;
|
||||
|
||||
|
||||
// Test for BeginUploadFile.
|
||||
|
||||
CreateTestFile(localFileName, 1);
|
||||
|
||||
using (var fileStream = File.OpenRead(localFileName))
|
||||
{
|
||||
asyncResult = sftp.BeginUploadFile(fileStream, remoteFileName, delegate(IAsyncResult ar)
|
||||
{
|
||||
sftp.EndUploadFile(ar);
|
||||
uploadDelegateCalled = true;
|
||||
|
||||
}, null);
|
||||
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
File.Delete(localFileName);
|
||||
|
||||
Assert.IsTrue(uploadDelegateCalled, "BeginUploadFile");
|
||||
|
||||
// Test for BeginDownloadFile.
|
||||
|
||||
asyncResult = null;
|
||||
using (var fileStream = File.OpenWrite(localFileName))
|
||||
{
|
||||
asyncResult = sftp.BeginDownloadFile(remoteFileName, fileStream, delegate(IAsyncResult ar)
|
||||
{
|
||||
sftp.EndDownloadFile(ar);
|
||||
downloadDelegateCalled = true;
|
||||
|
||||
}, null);
|
||||
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
File.Delete(localFileName);
|
||||
|
||||
Assert.IsTrue(downloadDelegateCalled, "BeginDownloadFile");
|
||||
|
||||
// Test for BeginListDirectory.
|
||||
|
||||
asyncResult = null;
|
||||
asyncResult = sftp.BeginListDirectory(sftp.WorkingDirectory, delegate(IAsyncResult ar)
|
||||
{
|
||||
sftp.EndListDirectory(ar);
|
||||
listDirectoryDelegateCalled = true;
|
||||
|
||||
}, null);
|
||||
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
Assert.IsTrue(listDirectoryDelegateCalled, "BeginListDirectory");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to BeginUploadFile")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_Sftp_BeginUploadFile_StreamIsNull()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.BeginUploadFile(null, "aaaaa", null, null);
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to BeginUploadFile")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.BeginUploadFile(new MemoryStream(), " ", null, null);
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to BeginUploadFile")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_BeginUploadFile_FileNameIsNull()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.BeginUploadFile(new MemoryStream(), null, null, null);
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to BeginDownloadFile")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_Sftp_BeginDownloadFile_StreamIsNull()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.BeginDownloadFile("aaaa", null, null, null);
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to BeginDownloadFile")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_BeginDownloadFile_FileNameIsWhiteSpace()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.BeginDownloadFile(" ", new MemoryStream(), null, null);
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[Description("Test passing null to BeginDownloadFile")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_BeginDownloadFile_FileNameIsNull()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
sftp.BeginDownloadFile(null, new MemoryStream(), null, null);
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_EndUploadFile_Invalid_Async_Handle()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
var async1 = sftp.BeginListDirectory("/", null, null);
|
||||
var filename = Path.GetTempFileName();
|
||||
this.CreateTestFile(filename, 100);
|
||||
var async2 = sftp.BeginUploadFile(File.OpenRead(filename), "test", null, null);
|
||||
sftp.EndUploadFile(async1);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_Sftp_EndDownloadFile_Invalid_Async_Handle()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
var filename = Path.GetTempFileName();
|
||||
this.CreateTestFile(filename, 1);
|
||||
sftp.UploadFile(File.OpenRead(filename), "test123");
|
||||
var async1 = sftp.BeginListDirectory("/", null, null);
|
||||
var async2 = sftp.BeginDownloadFile("test123", new MemoryStream(), null, null);
|
||||
sftp.EndDownloadFile(async1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates the test file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">Name of the file.</param>
|
||||
/// <param name="size">Size in megabytes.</param>
|
||||
private void CreateTestFile(string fileName, int size)
|
||||
{
|
||||
using (var testFile = File.Create(fileName))
|
||||
{
|
||||
|
||||
var random = new Random();
|
||||
for (int i = 0; i < 1024 * size; i++)
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
random.NextBytes(buffer);
|
||||
testFile.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static string CalculateMD5(string fileName)
|
||||
{
|
||||
using (FileStream file = new FileStream(fileName, FileMode.Open))
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] retVal = md5.ComputeHash(file);
|
||||
file.Close();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < retVal.Length; i++)
|
||||
{
|
||||
sb.Append(retVal[i].ToString("x2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper class to help with upload and download testing
|
||||
/// </summary>
|
||||
private class TestInfo
|
||||
{
|
||||
public string RemoteFileName { get; set; }
|
||||
|
||||
public string UploadedFileName { get; set; }
|
||||
|
||||
public string DownloadedFileName { get; set; }
|
||||
|
||||
//public ulong UploadedBytes { get; set; }
|
||||
|
||||
//public ulong DownloadedBytes { get; set; }
|
||||
|
||||
public FileStream UploadedFile { get; set; }
|
||||
|
||||
public FileStream DownloadedFile { get; set; }
|
||||
|
||||
public string UploadedHash { get; set; }
|
||||
|
||||
public string DownloadedHash { get; set; }
|
||||
|
||||
public SftpUploadAsyncResult UploadResult { get; set; }
|
||||
|
||||
public SftpDownloadAsyncResult DownloadResult { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using Renci.SshNet.Sftp;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ProxyTest
|
||||
{
|
||||
[TestMethod]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("Test connect to remote server via a SOCKS4 proxy server.")]
|
||||
[TestCategory("Proxy")]
|
||||
public void Test_Ssh_Connect_Via_Socks4()
|
||||
{
|
||||
var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks4, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
|
||||
using (var client = new SshClient(connInfo))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var ret = client.RunCommand("ls -la");
|
||||
Debug.WriteLine(ret.Result, "Command result:");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("Test connect to remote server via a TCP SOCKS5 proxy server.")]
|
||||
[TestCategory("Proxy")]
|
||||
public void Test_Ssh_Connect_Via_TcpSocks5()
|
||||
{
|
||||
var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks5, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
|
||||
using (var client = new SshClient(connInfo))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var ret = client.RunCommand("ls -la");
|
||||
Debug.WriteLine(ret.Result, "Command result:");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Owner("Kenneth_aa")]
|
||||
[Description("Test connect to remote server via a HTTP proxy server.")]
|
||||
[TestCategory("Proxy")]
|
||||
public void Test_Ssh_Connect_Via_HttpProxy()
|
||||
{
|
||||
var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Http, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
|
||||
using (var client = new SshClient(connInfo))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var ret = client.RunCommand("ls -la");
|
||||
Debug.WriteLine(ret.Result, "Command result:");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using Renci.SshNet.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UnitTest1
|
||||
/// </summary>
|
||||
public partial class TestPortForwarding
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(SshConnectionException))]
|
||||
public void Test_PortForwarding_Local_Without_Connecting()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80);
|
||||
client.AddForwardedPort(port1);
|
||||
port1.Exception += delegate(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
Assert.Fail(e.Exception.ToString());
|
||||
};
|
||||
port1.Start();
|
||||
|
||||
System.Threading.Tasks.Parallel.For(0, 100,
|
||||
//new ParallelOptions
|
||||
//{
|
||||
// MaxDegreeOfParallelism = 20,
|
||||
//},
|
||||
(counter) =>
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
var req = HttpWebRequest.Create("http://localhost:8084");
|
||||
using (var response = req.GetResponse())
|
||||
{
|
||||
|
||||
var data = ReadStream(response.GetResponseStream());
|
||||
var end = DateTime.Now;
|
||||
|
||||
Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, (end - start), counter));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_PortForwarding_Remote()
|
||||
{
|
||||
// ******************************************************************
|
||||
// ************* Tests are still in not finished ********************
|
||||
// ******************************************************************
|
||||
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortRemote(8082, "www.renci.org", 80);
|
||||
client.AddForwardedPort(port1);
|
||||
port1.Exception += delegate(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
Assert.Fail(e.Exception.ToString());
|
||||
};
|
||||
port1.Start();
|
||||
var boundport = port1.BoundPort;
|
||||
|
||||
System.Threading.Tasks.Parallel.For(0, 5,
|
||||
//new ParallelOptions
|
||||
//{
|
||||
// MaxDegreeOfParallelism = 1,
|
||||
//},
|
||||
(counter) =>
|
||||
{
|
||||
var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport));
|
||||
var result = cmd.Execute();
|
||||
var end = DateTime.Now;
|
||||
Debug.WriteLine(string.Format("Length: {0}", result.Length));
|
||||
}
|
||||
);
|
||||
Thread.Sleep(1000 * 100);
|
||||
port1.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_PortForwarding_Local()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80);
|
||||
client.AddForwardedPort(port1);
|
||||
port1.Exception += delegate(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
Assert.Fail(e.Exception.ToString());
|
||||
};
|
||||
port1.Start();
|
||||
|
||||
System.Threading.Tasks.Parallel.For(0, 100,
|
||||
//new ParallelOptions
|
||||
//{
|
||||
// MaxDegreeOfParallelism = 20,
|
||||
//},
|
||||
(counter) =>
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
var req = HttpWebRequest.Create("http://localhost:8084");
|
||||
using (var response = req.GetResponse())
|
||||
{
|
||||
|
||||
var data = ReadStream(response.GetResponseStream());
|
||||
var end = DateTime.Now;
|
||||
|
||||
Debug.WriteLine(string.Format("Request# {2}: Length: {0} Time: {1}", data.Length, (end - start), counter));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using Renci.SshNet.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UnitTest1
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public partial class TestPortForwarding
|
||||
{
|
||||
[TestMethod]
|
||||
[WorkItem(713)]
|
||||
[Owner("kenneth_aa")]
|
||||
[TestCategory("PortForwarding")]
|
||||
[Description("Test if calling Stop on ForwardedPortLocal instance causes wait.")]
|
||||
public void Test_PortForwarding_Local_Stop_Hangs_On_Wait()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Int32.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var port1 = new ForwardedPortLocal("localhost", 8084, "www.google.com", 80);
|
||||
client.AddForwardedPort(port1);
|
||||
port1.Exception += delegate(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
Assert.Fail(e.Exception.ToString());
|
||||
};
|
||||
|
||||
port1.Start();
|
||||
|
||||
bool hasTestedTunnel = false;
|
||||
System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = "http://www.google.com/";
|
||||
Debug.WriteLine("Starting web request to \"" + url + "\"");
|
||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
Assert.IsNotNull(response);
|
||||
|
||||
Debug.WriteLine("Http Response status code: " + response.StatusCode.ToString());
|
||||
|
||||
response.Close();
|
||||
|
||||
hasTestedTunnel = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.Fail(ex.ToString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Wait for the web request to complete.
|
||||
while(!hasTestedTunnel)
|
||||
{
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Try stop the port forwarding, wait 3 seconds and fail if it is still started.
|
||||
System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state)
|
||||
{
|
||||
Debug.WriteLine("Trying to stop port forward.");
|
||||
port1.Stop();
|
||||
Debug.WriteLine("Port forwarding stopped.");
|
||||
|
||||
});
|
||||
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
if (port1.IsStarted)
|
||||
{
|
||||
Assert.Fail("Port forwarding not stopped.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.Fail(ex.ToString());
|
||||
}
|
||||
client.Disconnect();
|
||||
Debug.WriteLine("Success.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing null to AddForwardedPort hosts (local).")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_AddForwardedPort_Local_Hosts_Are_Null()
|
||||
{
|
||||
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortLocal(null, 8080, null, 80);
|
||||
client.AddForwardedPort(port1);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing null to AddForwardedPort hosts (remote).")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_AddForwardedPort_Remote_Hosts_Are_Null()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortRemote(null, 8080, null, 80);
|
||||
client.AddForwardedPort(port1);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing string.Empty to AddForwardedPort host (remote).")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_AddForwardedPort_Remote_Hosts_Are_Empty()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortRemote(string.Empty, 8080, string.Empty, 80);
|
||||
client.AddForwardedPort(port1);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing string.Empty to AddForwardedPort host (local).")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_AddForwardedPort_Local_Hosts_Are_Empty()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortLocal(string.Empty, 8080, string.Empty, 80);
|
||||
client.AddForwardedPort(port1);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing invalid port numbers to AddForwardedPort.")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_AddForwardedPort_Invalid_PortNumber()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var port1 = new ForwardedPortRemote("localhost", IPEndPoint.MaxPort + 1, "www.renci.org", IPEndPoint.MaxPort + 1);
|
||||
client.AddForwardedPort(port1);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing null to constructor of PortForwardEventArgs.")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void Test_PortForwardEventArgs_Host_Null()
|
||||
{
|
||||
var args = new PortForwardEventArgs(null, 80);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing string.Empty to constructor of PortForwardEventArgs.")]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_PortForwardEventArgs_Host_Empty()
|
||||
{
|
||||
var args = new PortForwardEventArgs(string.Empty, 80);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Description("Test passing an invalid port to constructor of PortForwardEventArgs.")]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Test_PortForwardEventArgs_Port_Invalid()
|
||||
{
|
||||
var args = new PortForwardEventArgs("string", IPEndPoint.MaxPort + 1);
|
||||
}
|
||||
|
||||
private static byte[] ReadStream(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int read = stream.Read(buffer, 0, buffer.Length);
|
||||
if (read > 0)
|
||||
ms.Write(buffer, 0, read);
|
||||
else
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class TestShell
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
public partial class TestSshCommand
|
||||
{
|
||||
|
||||
//[TestMethod]
|
||||
public void Test_MultipleThread_10000_MultipleConnections()
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Threading.Tasks.Parallel.For(0, 10000,
|
||||
() =>
|
||||
{
|
||||
var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD);
|
||||
client.Connect();
|
||||
return client;
|
||||
},
|
||||
(int counter, ParallelLoopState pls, SshClient client) =>
|
||||
{
|
||||
var result = ExecuteTestCommand(client);
|
||||
Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
|
||||
Assert.IsTrue(result);
|
||||
return client;
|
||||
},
|
||||
(SshClient client) =>
|
||||
{
|
||||
client.Disconnect();
|
||||
client.Dispose();
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
Assert.Fail(exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
public void Test_MultipleThread_10000_MultipleSessions()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
System.Threading.Tasks.Parallel.For(0, 10000,
|
||||
(counter) =>
|
||||
{
|
||||
var result = ExecuteTestCommand(client);
|
||||
Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
);
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,327 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.SshClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public partial class TestSshCommand
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(SshConnectionException))]
|
||||
public void Test_Execute_SingleCommand_Without_Connecting()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
var result = ExecuteTestCommand(client);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_SingleCommand()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var result = ExecuteTestCommand(client);
|
||||
client.Disconnect();
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(SshOperationTimeoutException))]
|
||||
public void Test_Execute_Timeout()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("sleep 10s");
|
||||
cmd.CommandTimeout = TimeSpan.FromSeconds(5);
|
||||
cmd.Execute();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Infinite_Timeout()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("sleep 10s");
|
||||
cmd.Execute();
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_InvalidCommand()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var cmd = client.CreateCommand(";");
|
||||
cmd.Execute();
|
||||
if (string.IsNullOrEmpty(cmd.Error))
|
||||
{
|
||||
Assert.Fail("Operation should fail");
|
||||
}
|
||||
Assert.IsTrue(cmd.ExitStatus > 0);
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_InvalidCommand_Then_Execute_ValidCommand()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand(";");
|
||||
cmd.Execute();
|
||||
if (string.IsNullOrEmpty(cmd.Error))
|
||||
{
|
||||
Assert.Fail("Operation should fail");
|
||||
}
|
||||
Assert.IsTrue(cmd.ExitStatus > 0);
|
||||
|
||||
var result = ExecuteTestCommand(client);
|
||||
|
||||
client.Disconnect();
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_with_ExtendedOutput()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("echo 12345; echo 654321 >&2");
|
||||
cmd.Execute();
|
||||
//var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray());
|
||||
var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd();
|
||||
client.Disconnect();
|
||||
|
||||
Assert.AreEqual("12345\n", cmd.Result);
|
||||
Assert.AreEqual("654321\n", extendedData);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_Reconnect_Execute_Command()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var result = ExecuteTestCommand(client);
|
||||
Assert.IsTrue(result);
|
||||
|
||||
client.Disconnect();
|
||||
client.Connect();
|
||||
result = ExecuteTestCommand(client);
|
||||
Assert.IsTrue(result);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_ExitStatus()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var cmd = client.RunCommand("exit 128");
|
||||
Assert.IsTrue(cmd.ExitStatus == 128);
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_Asynchronously()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var cmd = client.CreateCommand("sleep 5s; echo 'test'");
|
||||
var asyncResult = cmd.BeginExecute(null, null);
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
cmd.EndExecute(asyncResult);
|
||||
|
||||
Assert.IsTrue(cmd.Result == "test\n");
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_Asynchronously_With_Error()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var cmd = client.CreateCommand("sleep 5s; ;");
|
||||
var asyncResult = cmd.BeginExecute(null, null);
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
cmd.EndExecute(asyncResult);
|
||||
|
||||
Assert.IsFalse(string.IsNullOrEmpty(cmd.Error));
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_Asynchronously_With_Callback()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
|
||||
var callbackCalled = false;
|
||||
|
||||
var cmd = client.CreateCommand("sleep 5s; echo 'test'");
|
||||
var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
|
||||
{
|
||||
callbackCalled = true;
|
||||
}), null);
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
cmd.EndExecute(asyncResult);
|
||||
|
||||
Assert.IsTrue(callbackCalled);
|
||||
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Execute_Command_Asynchronously_With_Callback_On_Different_Thread()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var currentThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
int callbackThreadId = 0;
|
||||
|
||||
var cmd = client.CreateCommand("sleep 5s; echo 'test'");
|
||||
var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
|
||||
{
|
||||
callbackThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
}), null);
|
||||
while (!asyncResult.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
cmd.EndExecute(asyncResult);
|
||||
|
||||
Assert.AreNotEqual(currentThreadId, callbackThreadId);
|
||||
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for Issue 563.
|
||||
/// </summary>
|
||||
[WorkItem(563), TestMethod]
|
||||
public void Test_Execute_Command_Same_Object_Different_Commands()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("echo 12345");
|
||||
cmd.Execute();
|
||||
Assert.AreEqual("12345\n", cmd.Result);
|
||||
cmd.Execute("echo 23456");
|
||||
Assert.AreEqual("23456\n", cmd.Result);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Get_Result_Without_Execution()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("ls -l");
|
||||
|
||||
Assert.IsTrue(string.IsNullOrEmpty(cmd.Result));
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Get_Error_Without_Execution()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("ls -l");
|
||||
|
||||
Assert.IsTrue(string.IsNullOrEmpty(cmd.Error));
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[WorkItem(703), TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Test_EndExecute_Before_BeginExecute()
|
||||
{
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
var cmd = client.CreateCommand("ls -l");
|
||||
cmd.EndExecute(null);
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static bool ExecuteTestCommand(SshClient s)
|
||||
{
|
||||
var testValue = Guid.NewGuid().ToString();
|
||||
var command = string.Format("echo {0}", testValue);
|
||||
var cmd = s.CreateCommand(command);
|
||||
var result = cmd.Execute();
|
||||
result = result.Substring(0, result.Length - 1); // Remove \n character returned by command
|
||||
return result.Equals(testValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
Renci.SshNet.dll
|
||||
Desktop
|
||||
Reference in New Issue
Block a user