-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from FrendsPlatform/issue-151
SFTP.DownloadFiles - Bug fixes and new features
- Loading branch information
Showing
15 changed files
with
1,070 additions
and
881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
290 changes: 162 additions & 128 deletions
290
Frends.SFTP.DownloadFiles/Frends.SFTP.DownloadFiles.Tests/ConnectivityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,162 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
using Frends.SFTP.DownloadFiles.Definitions; | ||
|
||
namespace Frends.SFTP.DownloadFiles.Tests | ||
{ | ||
[TestFixture] | ||
public class ConnectivityTests : DownloadFilesTestBase | ||
{ | ||
[Test] | ||
public void DownloadFiles_TestWithLargerBuffer() | ||
{ | ||
Helpers.UploadLargeTestFiles(_source.Directory, 1); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
connection.BufferSize = 256; | ||
|
||
var source = new Source | ||
{ | ||
Directory = _source.Directory, | ||
FileName = "LargeTestFile1.bin", | ||
Action = SourceAction.Error, | ||
Operation = SourceOperation.Nothing, | ||
}; | ||
|
||
var result = SFTP.DownloadFiles(source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestTransferThatThrowsWithIncorrectCredentials() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.ConnectionTimeout = 10; | ||
connection.UserName = "demo"; | ||
connection.Password = "demo"; | ||
|
||
var result = Assert.Throws<Exception>(() => SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken())); | ||
Assert.That(result.Message.StartsWith("SFTP transfer failed: Authentication of SSH session failed: Permission denied (password)")); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestPrivateKeyFileRsa() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.Authentication = AuthenticationType.UsernamePasswordPrivateKeyFile; | ||
connection.PrivateKeyFilePassphrase = "passphrase"; | ||
connection.PrivateKeyFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Volumes/ssh_host_rsa_key"); | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestPrivateKeyFileRsaFromString() | ||
{ | ||
var key = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Volumes/ssh_host_rsa_key")); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
connection.Authentication = AuthenticationType.UsernamePasswordPrivateKeyString; | ||
connection.PrivateKeyFilePassphrase = "passphrase"; | ||
connection.PrivateKeyString = key; | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestWithInteractiveKeyboardAuthentication() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.UseKeyboardInteractiveAuthentication = true; | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestKeepAliveIntervalWithDefault() | ||
{ | ||
Helpers.UploadLargeTestFiles(_source.Directory, 1); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
|
||
var source = new Source | ||
{ | ||
Directory = _source.Directory, | ||
FileName = "*.bin", | ||
Action = SourceAction.Error, | ||
Operation = SourceOperation.Nothing, | ||
}; | ||
|
||
var result = SFTP.DownloadFiles(source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestKeepAliveIntervalWith1ms() | ||
{ | ||
Helpers.UploadLargeTestFiles(_source.Directory, 1); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
connection.KeepAliveInterval = 1; | ||
connection.BufferSize = 256; | ||
|
||
var source = new Source | ||
{ | ||
Directory = _source.Directory, | ||
FileName = "*.bin", | ||
Action = SourceAction.Error, | ||
Operation = SourceOperation.Nothing, | ||
}; | ||
|
||
var result = SFTP.DownloadFiles(source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
} | ||
} | ||
|
||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
using Frends.SFTP.DownloadFiles.Definitions; | ||
|
||
namespace Frends.SFTP.DownloadFiles.Tests | ||
{ | ||
[TestFixture] | ||
public class ConnectivityTests : DownloadFilesTestBase | ||
{ | ||
[Test] | ||
public void DownloadFiles_TestWithLargerBuffer() | ||
{ | ||
Helpers.UploadLargeTestFiles(_source.Directory, 1); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
connection.BufferSize = 256; | ||
|
||
var source = new Source | ||
{ | ||
Directory = _source.Directory, | ||
FileName = "LargeTestFile1.bin", | ||
Action = SourceAction.Error, | ||
Operation = SourceOperation.Nothing, | ||
}; | ||
|
||
var result = SFTP.DownloadFiles(source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestTransferThatThrowsWithIncorrectCredentials() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.ConnectionTimeout = 10; | ||
connection.UserName = "demo"; | ||
connection.Password = "demo"; | ||
|
||
var result = Assert.Throws<Exception>(() => SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken())); | ||
Assert.IsTrue(result.Message.StartsWith("SFTP transfer failed: Authentication of SSH session failed: Permission denied (password)")); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestPrivateKeyFileRsa() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.Authentication = AuthenticationType.UsernamePasswordPrivateKeyFile; | ||
connection.PrivateKeyPassphrase = "passphrase"; | ||
connection.PrivateKeyFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Volumes/ssh_host_rsa_key"); | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestPrivateKeyFileRsaFromString() | ||
{ | ||
var key = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Volumes/ssh_host_rsa_key")); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
connection.HostKeyAlgorithm = HostKeyAlgorithms.RSA; | ||
connection.Authentication = AuthenticationType.UsernamePasswordPrivateKeyString; | ||
connection.PrivateKeyPassphrase = "passphrase"; | ||
connection.PrivateKeyString = key; | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestWithInteractiveKeyboardAuthentication() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.UseKeyboardInteractiveAuthentication = true; | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestWithInteractiveKeyboardAuthenticationAndPrivateKey() | ||
{ | ||
var connection = Helpers.GetSftpConnection(); | ||
connection.Authentication = AuthenticationType.UsernamePrivateKeyFile; | ||
connection.PrivateKeyFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Volumes/ssh_host_rsa_key"); | ||
connection.Password = null; | ||
connection.PrivateKeyPassphrase = "passphrase"; | ||
connection.UseKeyboardInteractiveAuthentication = true; | ||
connection.PromptAndResponse = new PromptResponse[] { new PromptResponse { Prompt = "Password", Response = "pass" } }; | ||
|
||
var result = SFTP.DownloadFiles(_source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
|
||
connection.Authentication = AuthenticationType.UsernamePrivateKeyString; | ||
connection.PrivateKeyFile = null; | ||
connection.PrivateKeyString = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Volumes/ssh_host_rsa_key")); | ||
connection.PrivateKeyPassphrase = "passphrase"; | ||
|
||
var destination = new Destination | ||
{ | ||
Directory = Path.Combine(_workDir, "destination"), | ||
Action = DestinationAction.Overwrite, | ||
FileNameEncoding = FileEncoding.UTF8, | ||
EnableBomForFileName = true | ||
}; | ||
|
||
result = SFTP.DownloadFiles(_source, destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestKeepAliveIntervalWithDefault() | ||
{ | ||
Helpers.UploadLargeTestFiles(_source.Directory, 1); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
|
||
var source = new Source | ||
{ | ||
Directory = _source.Directory, | ||
FileName = "*.bin", | ||
Action = SourceAction.Error, | ||
Operation = SourceOperation.Nothing, | ||
}; | ||
|
||
var result = SFTP.DownloadFiles(source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
|
||
[Test] | ||
public void DownloadFiles_TestKeepAliveIntervalWith1ms() | ||
{ | ||
Helpers.UploadLargeTestFiles(_source.Directory, 1); | ||
|
||
var connection = Helpers.GetSftpConnection(); | ||
connection.KeepAliveInterval = 1; | ||
connection.BufferSize = 256; | ||
|
||
var source = new Source | ||
{ | ||
Directory = _source.Directory, | ||
FileName = "*.bin", | ||
Action = SourceAction.Error, | ||
Operation = SourceOperation.Nothing, | ||
}; | ||
|
||
var result = SFTP.DownloadFiles(source, _destination, connection, _options, _info, new CancellationToken()); | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.