2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
2016-09-14 15:13:10 -07:00
|
|
|
Describe "SSH Remoting API Tests" -Tags "Feature" {
|
|
|
|
|
|
|
|
|
|
Context "SSHConnectionInfo Class Tests" {
|
|
|
|
|
|
2017-10-13 13:54:43 -07:00
|
|
|
BeforeAll {
|
|
|
|
|
## Skip the test if ssh is not present.
|
2018-08-23 15:10:39 -07:00
|
|
|
$skipTest = @(Get-Command 'ssh' -CommandType Application -ErrorAction SilentlyContinue).Count -eq 0
|
2017-10-13 13:54:43 -07:00
|
|
|
}
|
|
|
|
|
|
2017-04-26 02:02:16 +01:00
|
|
|
AfterEach {
|
2017-07-22 05:03:49 +01:00
|
|
|
if ($null -ne $rs) {
|
2017-04-26 02:02:16 +01:00
|
|
|
$rs.Dispose()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 15:13:10 -07:00
|
|
|
It "SSHConnectionInfo constructor should throw null argument exception for null HostName parameter" {
|
|
|
|
|
|
2017-04-26 02:02:16 +01:00
|
|
|
{ [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
|
|
|
|
|
"UserName",
|
|
|
|
|
[System.Management.Automation.Internal.AutomationNull]::Value,
|
|
|
|
|
[System.Management.Automation.Internal.AutomationNull]::Value,
|
2018-05-17 14:42:04 -07:00
|
|
|
0) } | Should -Throw -ErrorId "PSArgumentNullException"
|
2016-09-14 15:13:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-13 13:54:43 -07:00
|
|
|
It "SSHConnectionInfo should throw file not found exception for invalid key file path" -Skip:$skipTest {
|
2018-05-17 14:42:04 -07:00
|
|
|
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
|
|
|
|
|
"UserName",
|
|
|
|
|
"localhost",
|
|
|
|
|
"NoValidKeyFilePath",
|
|
|
|
|
22)
|
2016-09-14 15:13:10 -07:00
|
|
|
|
2018-05-17 14:42:04 -07:00
|
|
|
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
|
2016-09-14 15:13:10 -07:00
|
|
|
|
2018-05-17 14:42:04 -07:00
|
|
|
$e = { $rs.Open() } | Should -Throw -PassThru
|
2020-01-24 19:00:37 +00:00
|
|
|
$e.Exception.InnerException.InnerException | Should -BeOfType System.IO.FileNotFoundException
|
2017-04-26 02:02:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "SSHConnectionInfo should throw argument exception for invalid port (non 16bit uint)" {
|
|
|
|
|
{
|
|
|
|
|
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
|
2018-05-17 14:42:04 -07:00
|
|
|
"UserName",
|
|
|
|
|
"localhost",
|
|
|
|
|
"ValidKeyFilePath",
|
|
|
|
|
99999)
|
2017-04-26 02:02:16 +01:00
|
|
|
|
|
|
|
|
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
|
|
|
|
|
$rs.Open()
|
2018-05-17 14:42:04 -07:00
|
|
|
} | Should -Throw -ErrorId "ArgumentException" -PassThru
|
2016-09-14 15:13:10 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|