|
|
@@ -15,6 +15,206 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
[TestClass]
|
|
|
public partial class ScpClientTest : TestBase
|
|
|
{
|
|
|
+ private Random _random;
|
|
|
+
|
|
|
+ [TestInitialize]
|
|
|
+ public void SetUp()
|
|
|
+ {
|
|
|
+ _random = new Random();
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void Ctor_ConnectionInfo_Null()
|
|
|
+ {
|
|
|
+ const ConnectionInfo connectionInfo = null;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ new ScpClient(connectionInfo);
|
|
|
+ Assert.Fail();
|
|
|
+ }
|
|
|
+ catch (ArgumentNullException ex)
|
|
|
+ {
|
|
|
+ Assert.IsNull(ex.InnerException);
|
|
|
+ Assert.AreEqual("connectionInfo", ex.ParamName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void Ctor_ConnectionInfo_NotNull()
|
|
|
+ {
|
|
|
+ var connectionInfo = new ConnectionInfo("HOST", "USER", new PasswordAuthenticationMethod("USER", "PWD"));
|
|
|
+
|
|
|
+ var client = new ScpClient(connectionInfo);
|
|
|
+ Assert.AreEqual(16 * 1024U, client.BufferSize);
|
|
|
+ Assert.AreSame(connectionInfo, client.ConnectionInfo);
|
|
|
+ Assert.IsFalse(client.IsConnected);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.KeepAliveInterval);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.OperationTimeout);
|
|
|
+ Assert.AreSame(RemotePathTransformation.DoubleQuote, client.RemotePathTransformation);
|
|
|
+ Assert.IsNull(client.Session);
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void Ctor_HostAndPortAndUsernameAndPassword()
|
|
|
+ {
|
|
|
+ var host = _random.Next().ToString();
|
|
|
+ var port = _random.Next(1, 100);
|
|
|
+ var userName = _random.Next().ToString();
|
|
|
+ var password = _random.Next().ToString();
|
|
|
+
|
|
|
+ var client = new ScpClient(host, port, userName, password);
|
|
|
+ Assert.AreEqual(16 * 1024U, client.BufferSize);
|
|
|
+ Assert.IsNotNull(client.ConnectionInfo);
|
|
|
+ Assert.IsFalse(client.IsConnected);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.KeepAliveInterval);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.OperationTimeout);
|
|
|
+ Assert.AreSame(RemotePathTransformation.DoubleQuote, client.RemotePathTransformation);
|
|
|
+ Assert.IsNull(client.Session);
|
|
|
+
|
|
|
+ var passwordConnectionInfo = client.ConnectionInfo as PasswordConnectionInfo;
|
|
|
+ Assert.IsNotNull(passwordConnectionInfo);
|
|
|
+ Assert.AreEqual(host, passwordConnectionInfo.Host);
|
|
|
+ Assert.AreEqual(port, passwordConnectionInfo.Port);
|
|
|
+ Assert.AreSame(userName, passwordConnectionInfo.Username);
|
|
|
+ Assert.IsNotNull(passwordConnectionInfo.AuthenticationMethods);
|
|
|
+ Assert.AreEqual(1, passwordConnectionInfo.AuthenticationMethods.Count);
|
|
|
+
|
|
|
+ var passwordAuthentication = passwordConnectionInfo.AuthenticationMethods[0] as PasswordAuthenticationMethod;
|
|
|
+ Assert.IsNotNull(passwordAuthentication);
|
|
|
+ Assert.AreEqual(userName, passwordAuthentication.Username);
|
|
|
+ Assert.IsTrue(Encoding.UTF8.GetBytes(password).IsEqualTo(passwordAuthentication.Password));
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void Ctor_HostAndUsernameAndPassword()
|
|
|
+ {
|
|
|
+ var host = _random.Next().ToString();
|
|
|
+ var userName = _random.Next().ToString();
|
|
|
+ var password = _random.Next().ToString();
|
|
|
+
|
|
|
+ var client = new ScpClient(host, userName, password);
|
|
|
+ Assert.AreEqual(16 * 1024U, client.BufferSize);
|
|
|
+ Assert.IsNotNull(client.ConnectionInfo);
|
|
|
+ Assert.IsFalse(client.IsConnected);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.KeepAliveInterval);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.OperationTimeout);
|
|
|
+ Assert.AreSame(RemotePathTransformation.DoubleQuote, client.RemotePathTransformation);
|
|
|
+ Assert.IsNull(client.Session);
|
|
|
+
|
|
|
+ var passwordConnectionInfo = client.ConnectionInfo as PasswordConnectionInfo;
|
|
|
+ Assert.IsNotNull(passwordConnectionInfo);
|
|
|
+ Assert.AreEqual(host, passwordConnectionInfo.Host);
|
|
|
+ Assert.AreEqual(22, passwordConnectionInfo.Port);
|
|
|
+ Assert.AreSame(userName, passwordConnectionInfo.Username);
|
|
|
+ Assert.IsNotNull(passwordConnectionInfo.AuthenticationMethods);
|
|
|
+ Assert.AreEqual(1, passwordConnectionInfo.AuthenticationMethods.Count);
|
|
|
+
|
|
|
+ var passwordAuthentication = passwordConnectionInfo.AuthenticationMethods[0] as PasswordAuthenticationMethod;
|
|
|
+ Assert.IsNotNull(passwordAuthentication);
|
|
|
+ Assert.AreEqual(userName, passwordAuthentication.Username);
|
|
|
+ Assert.IsTrue(Encoding.UTF8.GetBytes(password).IsEqualTo(passwordAuthentication.Password));
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void Ctor_HostAndPortAndUsernameAndPrivateKeys()
|
|
|
+ {
|
|
|
+ var host = _random.Next().ToString();
|
|
|
+ var port = _random.Next(1, 100);
|
|
|
+ var userName = _random.Next().ToString();
|
|
|
+ var privateKeys = new[] {GetRsaKey(), GetDsaKey()};
|
|
|
+
|
|
|
+ var client = new ScpClient(host, port, userName, privateKeys);
|
|
|
+ Assert.AreEqual(16 * 1024U, client.BufferSize);
|
|
|
+ Assert.IsNotNull(client.ConnectionInfo);
|
|
|
+ Assert.IsFalse(client.IsConnected);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.KeepAliveInterval);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.OperationTimeout);
|
|
|
+ Assert.AreSame(RemotePathTransformation.DoubleQuote, client.RemotePathTransformation);
|
|
|
+ Assert.IsNull(client.Session);
|
|
|
+
|
|
|
+ var privateKeyConnectionInfo = client.ConnectionInfo as PrivateKeyConnectionInfo;
|
|
|
+ Assert.IsNotNull(privateKeyConnectionInfo);
|
|
|
+ Assert.AreEqual(host, privateKeyConnectionInfo.Host);
|
|
|
+ Assert.AreEqual(port, privateKeyConnectionInfo.Port);
|
|
|
+ Assert.AreSame(userName, privateKeyConnectionInfo.Username);
|
|
|
+ Assert.IsNotNull(privateKeyConnectionInfo.AuthenticationMethods);
|
|
|
+ Assert.AreEqual(1, privateKeyConnectionInfo.AuthenticationMethods.Count);
|
|
|
+
|
|
|
+ var privateKeyAuthentication = privateKeyConnectionInfo.AuthenticationMethods[0] as PrivateKeyAuthenticationMethod;
|
|
|
+ Assert.IsNotNull(privateKeyAuthentication);
|
|
|
+ Assert.AreEqual(userName, privateKeyAuthentication.Username);
|
|
|
+ Assert.IsNotNull(privateKeyAuthentication.KeyFiles);
|
|
|
+ Assert.AreEqual(privateKeys.Length, privateKeyAuthentication.KeyFiles.Count);
|
|
|
+ Assert.IsTrue(privateKeyAuthentication.KeyFiles.Contains(privateKeys[0]));
|
|
|
+ Assert.IsTrue(privateKeyAuthentication.KeyFiles.Contains(privateKeys[1]));
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void Ctor_HostAndUsernameAndPrivateKeys()
|
|
|
+ {
|
|
|
+ var host = _random.Next().ToString();
|
|
|
+ var userName = _random.Next().ToString();
|
|
|
+ var privateKeys = new[] { GetRsaKey(), GetDsaKey() };
|
|
|
+
|
|
|
+ var client = new ScpClient(host, userName, privateKeys);
|
|
|
+ Assert.AreEqual(16 * 1024U, client.BufferSize);
|
|
|
+ Assert.IsNotNull(client.ConnectionInfo);
|
|
|
+ Assert.IsFalse(client.IsConnected);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.KeepAliveInterval);
|
|
|
+ Assert.AreEqual(new TimeSpan(0, 0, 0, 0, -1), client.OperationTimeout);
|
|
|
+ Assert.AreSame(RemotePathTransformation.DoubleQuote, client.RemotePathTransformation);
|
|
|
+ Assert.IsNull(client.Session);
|
|
|
+
|
|
|
+ var privateKeyConnectionInfo = client.ConnectionInfo as PrivateKeyConnectionInfo;
|
|
|
+ Assert.IsNotNull(privateKeyConnectionInfo);
|
|
|
+ Assert.AreEqual(host, privateKeyConnectionInfo.Host);
|
|
|
+ Assert.AreEqual(22, privateKeyConnectionInfo.Port);
|
|
|
+ Assert.AreSame(userName, privateKeyConnectionInfo.Username);
|
|
|
+ Assert.IsNotNull(privateKeyConnectionInfo.AuthenticationMethods);
|
|
|
+ Assert.AreEqual(1, privateKeyConnectionInfo.AuthenticationMethods.Count);
|
|
|
+
|
|
|
+ var privateKeyAuthentication = privateKeyConnectionInfo.AuthenticationMethods[0] as PrivateKeyAuthenticationMethod;
|
|
|
+ Assert.IsNotNull(privateKeyAuthentication);
|
|
|
+ Assert.AreEqual(userName, privateKeyAuthentication.Username);
|
|
|
+ Assert.IsNotNull(privateKeyAuthentication.KeyFiles);
|
|
|
+ Assert.AreEqual(privateKeys.Length, privateKeyAuthentication.KeyFiles.Count);
|
|
|
+ Assert.IsTrue(privateKeyAuthentication.KeyFiles.Contains(privateKeys[0]));
|
|
|
+ Assert.IsTrue(privateKeyAuthentication.KeyFiles.Contains(privateKeys[1]));
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void RemotePathTransformation_Value_NotNull()
|
|
|
+ {
|
|
|
+ var client = new ScpClient("HOST", 22, "USER", "PWD");
|
|
|
+
|
|
|
+ Assert.AreSame(RemotePathTransformation.DoubleQuote, client.RemotePathTransformation);
|
|
|
+ client.RemotePathTransformation = RemotePathTransformation.ShellQuote;
|
|
|
+ Assert.AreSame(RemotePathTransformation.ShellQuote, client.RemotePathTransformation);
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void RemotePathTransformation_Value_Null()
|
|
|
+ {
|
|
|
+ var client = new ScpClient("HOST", 22, "USER", "PWD")
|
|
|
+ {
|
|
|
+ RemotePathTransformation = RemotePathTransformation.ShellQuote
|
|
|
+ };
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ client.RemotePathTransformation = null;
|
|
|
+ Assert.Fail();
|
|
|
+ }
|
|
|
+ catch (ArgumentNullException ex)
|
|
|
+ {
|
|
|
+ Assert.IsNull(ex.InnerException);
|
|
|
+ Assert.AreEqual("value", ex.ParamName);
|
|
|
+ }
|
|
|
+
|
|
|
+ Assert.AreSame(RemotePathTransformation.ShellQuote, client.RemotePathTransformation);
|
|
|
+ }
|
|
|
+
|
|
|
[TestMethod]
|
|
|
[TestCategory("Scp")]
|
|
|
[TestCategory("integration")]
|
|
|
@@ -172,10 +372,12 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
{
|
|
|
scp.Connect();
|
|
|
|
|
|
- var uploadDirectory = Directory.CreateDirectory(string.Format("{0}\\{1}", Path.GetTempPath(), Path.GetRandomFileName()));
|
|
|
+ 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));
|
|
|
+ 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);
|
|
|
@@ -185,7 +387,8 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
|
|
|
scp.Upload(uploadDirectory, "uploaded_dir");
|
|
|
|
|
|
- var downloadDirectory = Directory.CreateDirectory(string.Format("{0}\\{1}", Path.GetTempPath(), Path.GetRandomFileName()));
|
|
|
+ var downloadDirectory =
|
|
|
+ Directory.CreateDirectory(string.Format("{0}\\{1}", Path.GetTempPath(), Path.GetRandomFileName()));
|
|
|
|
|
|
scp.Download("uploaded_dir", downloadDirectory);
|
|
|
|
|
|
@@ -193,11 +396,12 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
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;
|
|
|
+ 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();
|
|
|
|
|
|
@@ -331,76 +535,6 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
Assert.Inconclusive("A method that does not return a value cannot be verified.");
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- ///A test for ScpClient Constructor
|
|
|
- ///</summary>
|
|
|
- [TestMethod]
|
|
|
- [Ignore] // placeholder for actual test
|
|
|
- public void ScpClientConstructorTest()
|
|
|
- {
|
|
|
- string host = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- string username = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value
|
|
|
- ScpClient target = new ScpClient(host, username, keyFiles);
|
|
|
- Assert.Inconclusive("TODO: Implement code to verify target");
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- ///A test for ScpClient Constructor
|
|
|
- ///</summary>
|
|
|
- [TestMethod]
|
|
|
- [Ignore] // placeholder for actual test
|
|
|
- public void ScpClientConstructorTest1()
|
|
|
- {
|
|
|
- string host = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- int port = 0; // TODO: Initialize to an appropriate value
|
|
|
- string username = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value
|
|
|
- ScpClient target = new ScpClient(host, port, username, keyFiles);
|
|
|
- Assert.Inconclusive("TODO: Implement code to verify target");
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- ///A test for ScpClient Constructor
|
|
|
- ///</summary>
|
|
|
- [TestMethod]
|
|
|
- [Ignore] // placeholder for actual test
|
|
|
- public void ScpClientConstructorTest2()
|
|
|
- {
|
|
|
- string host = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- string username = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- string password = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- ScpClient target = new ScpClient(host, username, password);
|
|
|
- Assert.Inconclusive("TODO: Implement code to verify target");
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- ///A test for ScpClient Constructor
|
|
|
- ///</summary>
|
|
|
- [TestMethod]
|
|
|
- [Ignore] // placeholder for actual test
|
|
|
- public void ScpClientConstructorTest3()
|
|
|
- {
|
|
|
- string host = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- int port = 0; // TODO: Initialize to an appropriate value
|
|
|
- string username = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- string password = string.Empty; // TODO: Initialize to an appropriate value
|
|
|
- ScpClient target = new ScpClient(host, port, username, password);
|
|
|
- Assert.Inconclusive("TODO: Implement code to verify target");
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- ///A test for ScpClient Constructor
|
|
|
- ///</summary>
|
|
|
- [TestMethod]
|
|
|
- [Ignore] // placeholder for actual test
|
|
|
- public void ScpClientConstructorTest4()
|
|
|
- {
|
|
|
- ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
|
|
|
- ScpClient target = new ScpClient(connectionInfo);
|
|
|
- Assert.Inconclusive("TODO: Implement code to verify target");
|
|
|
- }
|
|
|
-
|
|
|
protected static string CalculateMD5(string fileName)
|
|
|
{
|
|
|
using (var file = new FileStream(fileName, FileMode.Open))
|
|
|
@@ -427,5 +561,21 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
client.Disconnect();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private PrivateKeyFile GetRsaKey()
|
|
|
+ {
|
|
|
+ using (var stream = GetData("Key.RSA.txt"))
|
|
|
+ {
|
|
|
+ return new PrivateKeyFile(stream);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private PrivateKeyFile GetDsaKey()
|
|
|
+ {
|
|
|
+ using (var stream = GetData("Key.SSH2.DSA.txt"))
|
|
|
+ {
|
|
|
+ return new PrivateKeyFile(stream);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|