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.
|
|
|
|
$skipTest = (Get-Command 'ssh' -CommandType Application -ErrorAction SilentlyContinue) -eq $null
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
0) } | ShouldBeErrorId "PSArgumentNullException"
|
|
|
|
}
|
|
|
|
|
2017-10-13 22:54:43 +02:00
|
|
|
It "SSHConnectionInfo should throw file not found exception for invalid key file path" -Skip:$skipTest {
|
2017-04-26 03:02:16 +02:00
|
|
|
|
2016-09-15 00:13:10 +02:00
|
|
|
try
|
|
|
|
{
|
2017-04-26 03:02:16 +02:00
|
|
|
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
|
2016-09-15 00:13:10 +02:00
|
|
|
"UserName",
|
2017-04-26 03:02:16 +02:00
|
|
|
"localhost",
|
|
|
|
"NoValidKeyFilePath",
|
|
|
|
22)
|
2016-09-15 00:13:10 +02:00
|
|
|
|
2017-04-26 03:02:16 +02:00
|
|
|
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
|
|
|
|
$rs.Open()
|
2017-10-13 22:54:43 +02:00
|
|
|
|
2017-02-16 01:40:51 +01:00
|
|
|
throw "No Exception!"
|
2016-09-15 00:13:10 +02:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2017-04-26 03:02:16 +02:00
|
|
|
$_.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)" {
|
2017-10-13 22:54:43 +02:00
|
|
|
try
|
2016-09-15 00:13:10 +02:00
|
|
|
{
|
|
|
|
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
|
|
|
|
"UserName",
|
|
|
|
"localhost",
|
2017-04-26 03:02:16 +02:00
|
|
|
"ValidKeyFilePath",
|
|
|
|
99999)
|
2016-09-15 00:13:10 +02:00
|
|
|
|
|
|
|
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
|
|
|
|
$rs.Open()
|
2017-10-13 22:54:43 +02:00
|
|
|
|
2017-02-16 01:40:51 +01:00
|
|
|
throw "No Exception!"
|
2016-09-15 00:13:10 +02:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2017-04-26 03:02:16 +02:00
|
|
|
$expectedArgumentException = $_.Exception
|
2017-07-22 06:03:49 +02:00
|
|
|
if ($null -ne $_.Exception.InnerException)
|
2017-04-26 03:02:16 +02:00
|
|
|
{
|
|
|
|
$expectedArgumentException = $_.Exception.InnerException
|
|
|
|
}
|
|
|
|
|
|
|
|
$expectedArgumentException | Should BeOfType "System.ArgumentException"
|
2016-09-15 00:13:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|