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