PowerShell/test/powershell/engine/Remoting/SSHRemotingAPI.Tests.ps1
Lee Spottiswood 1d42862e21 Adds Port parameter for SSH PSSessions (#3499)
* fixes summary block typo

* Adds support for Port parameter for SSH PSSessions

* Reverted back to master, modified based on PR feedback

* Update exception message

* remove unused line

* Add existing constructor back in as to not break public contract

* remove port check

* pass nested inner exception straight to Should

* dispose runspace after each test

* Add SSHHostParameterSet attribute for Invoke-Command Port property

* Update ParseSSHConnectionHashTable method to accept Port value as integer

* Add helper method for validating port in range. Refactor port parameter constructor overload to use original constructor

* rename method

* Adds GetSSHConnectionStringParameter and GetSSHConnectionIntParameter methods for retrieving SSHConnection hashtable values

* Adds method comments

* Adds helper method comment

* Change methods to add C# 7 patterns
2017-04-25 18:02:16 -07:00

70 lines
2.3 KiB
PowerShell

Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
Describe "SSH Remoting API Tests" -Tags "Feature" {
Context "SSHConnectionInfo Class Tests" {
AfterEach {
if ($rs -ne $null) {
$rs.Dispose()
}
}
It "SSHConnectionInfo constructor should throw null argument exception for null HostName parameter" {
{ [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
"UserName",
[System.Management.Automation.Internal.AutomationNull]::Value,
[System.Management.Automation.Internal.AutomationNull]::Value,
0) } | ShouldBeErrorId "PSArgumentNullException"
}
It "SSHConnectionInfo should throw file not found exception for invalid key file path" {
try
{
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
"UserName",
"localhost",
"NoValidKeyFilePath",
22)
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
$rs.Open()
throw "No Exception!"
}
catch
{
$_.Exception.InnerException.InnerException | Should BeOfType "System.IO.FileNotFoundException"
}
}
It "SSHConnectionInfo should throw argument exception for invalid port (non 16bit uint)" {
try
{
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
"UserName",
"localhost",
"ValidKeyFilePath",
99999)
$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
$rs.Open()
throw "No Exception!"
}
catch
{
$expectedArgumentException = $_.Exception
if ($_.Exception.InnerException -ne $null)
{
$expectedArgumentException = $_.Exception.InnerException
}
$expectedArgumentException | Should BeOfType "System.ArgumentException"
}
}
}
}