2017-04-15 01:15:32 +02:00
|
|
|
|
#todo: -i -q -v -l -c -C
|
2016-12-19 23:48:14 +01:00
|
|
|
|
#todo: -S -F -V -e
|
2017-05-10 23:47:03 +02:00
|
|
|
|
$tC = 1
|
2017-04-15 01:15:32 +02:00
|
|
|
|
$tI = 0
|
|
|
|
|
|
|
|
|
|
Describe "ssh client tests" -Tags "CI" {
|
2016-12-19 23:48:14 +01:00
|
|
|
|
BeforeAll {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
if($OpenSSHTestInfo -eq $null)
|
|
|
|
|
{
|
|
|
|
|
Throw "`$OpenSSHTestInfo is null. Please run Setup-OpenSSHTestEnvironment to setup test environment."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(-not (Test-Path $OpenSSHTestInfo["TestDataPath"]))
|
|
|
|
|
{
|
|
|
|
|
$null = New-Item $OpenSSHTestInfo["TestDataPath"] -ItemType directory -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
2017-04-15 01:15:32 +02:00
|
|
|
|
$server = $OpenSSHTestInfo["Target"]
|
|
|
|
|
$port = $OpenSSHTestInfo["Port"]
|
|
|
|
|
$ssouser = $OpenSSHTestInfo["SSOUser"]
|
|
|
|
|
$sshCmdDefault = "ssh -p $port $($ssouser)@$($server)"
|
|
|
|
|
|
|
|
|
|
$testDir = Join-Path $OpenSSHTestInfo["TestDataPath"] "ssh"
|
|
|
|
|
if(-not (Test-Path $testDir))
|
|
|
|
|
{
|
|
|
|
|
$null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
2016-12-19 23:48:14 +01:00
|
|
|
|
|
|
|
|
|
$testData = @(
|
|
|
|
|
@{
|
2017-01-27 19:47:20 +01:00
|
|
|
|
Title = 'Simple logon no option';
|
2016-12-19 23:48:14 +01:00
|
|
|
|
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
|
2017-01-27 19:47:20 +01:00
|
|
|
|
Options = ""
|
2016-12-19 23:48:14 +01:00
|
|
|
|
},
|
|
|
|
|
@{
|
|
|
|
|
Title = 'Simple logon using -C -l option'
|
|
|
|
|
LogonStr = $server.MachineName
|
|
|
|
|
Options = "-C -l $($server.localAdminUserName)"
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$testData1 = @(
|
|
|
|
|
@{
|
|
|
|
|
Title = "logon using -i -q option"
|
|
|
|
|
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
|
|
|
|
|
Options = '-i $identifyFile -q'
|
|
|
|
|
},
|
|
|
|
|
@{
|
2017-01-27 19:47:20 +01:00
|
|
|
|
Title = "logon using -i option"
|
2016-12-19 23:48:14 +01:00
|
|
|
|
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
|
2017-01-27 19:47:20 +01:00
|
|
|
|
Options = '-i $identifyFile'
|
2016-12-19 23:48:14 +01:00
|
|
|
|
},
|
|
|
|
|
@{
|
|
|
|
|
Title = "logon using -i -c option"
|
|
|
|
|
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
|
|
|
|
|
Options = '-i $identifyFile -c aes256-ctr'
|
|
|
|
|
},
|
|
|
|
|
<# -V does not redirect to file
|
|
|
|
|
@{
|
|
|
|
|
Title = "logon using -i -V option"
|
|
|
|
|
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
|
|
|
|
|
Options = '-i $identifyFile -V'
|
|
|
|
|
SkipVerification = $true
|
|
|
|
|
},#>
|
|
|
|
|
@{
|
|
|
|
|
Title = 'logon using -i -l option'
|
|
|
|
|
LogonStr = $server.MachineName
|
|
|
|
|
Options = '-i $identifyFile -l $($server.localAdminUserName)'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-15 01:15:32 +02:00
|
|
|
|
BeforeEach {
|
|
|
|
|
$tI++;
|
2017-05-10 23:47:03 +02:00
|
|
|
|
$tFile=Join-Path $testDir "$tC.$tI.txt"
|
2017-04-15 01:15:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
Context "$tC - Basic Scenarios" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
|
|
|
|
|
BeforeAll {$tI=1}
|
2017-05-10 23:47:03 +02:00
|
|
|
|
AfterAll{$tC++}
|
2017-04-15 01:15:32 +02:00
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
It "$tC.$tI - test version" {
|
|
|
|
|
iex "cmd /c `"ssh -V 2> $tFile`""
|
2017-04-15 01:15:32 +02:00
|
|
|
|
$tFile | Should Contain "OpenSSH_"
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
It "$tC.$tI - test help" {
|
|
|
|
|
iex "cmd /c `"ssh -? 2> $tFile`""
|
2017-04-15 01:15:32 +02:00
|
|
|
|
$tFile | Should Contain "usage: ssh"
|
|
|
|
|
}
|
2017-05-10 23:47:03 +02:00
|
|
|
|
|
|
|
|
|
It "$tC.$tI - remote echo command" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
iex "$sshDefaultCmd echo 1234" | Should Be "1234"
|
|
|
|
|
}
|
2017-05-10 23:47:03 +02:00
|
|
|
|
|
|
|
|
|
It "$tC.$tI - exit code" {
|
|
|
|
|
ssh -p $port $ssouser@$server exit 0
|
|
|
|
|
$LASTEXITCODE | Should Be 0
|
|
|
|
|
ssh -p $port $ssouser@$server exit 21
|
|
|
|
|
$LASTEXITCODE | Should Be 21
|
|
|
|
|
}
|
2017-04-15 01:15:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
Context "$tC - Redirection Scenarios" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
|
|
|
|
|
BeforeAll {$tI=1}
|
2017-05-10 23:47:03 +02:00
|
|
|
|
AfterAll{$tC++}
|
2017-04-15 01:15:32 +02:00
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
It "$tC.$tI - stdout to file" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
iex "$sshDefaultCmd powershell get-process > $tFile"
|
|
|
|
|
$tFile | Should Contain "ProcessName"
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
It "$tC.$tI - stdout to PS object" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
$o = iex "$sshDefaultCmd echo 1234"
|
|
|
|
|
$o | Should Be "1234"
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
<#It "$tC.$tI - stdin from PS object" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
#if input redirection doesn't work, this would hang
|
|
|
|
|
0 | ssh -p $port $ssouser@$server pause
|
|
|
|
|
$true | Should Be $true
|
|
|
|
|
}#>
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
Context "$tC - cmdline parameters" {
|
2017-04-15 01:15:32 +02:00
|
|
|
|
|
|
|
|
|
BeforeAll {$tI=1}
|
2017-05-10 23:47:03 +02:00
|
|
|
|
AfterAll{$tC++}
|
2017-04-15 01:15:32 +02:00
|
|
|
|
|
2017-05-10 23:47:03 +02:00
|
|
|
|
It "$tC.$tI - verbose to file" {
|
|
|
|
|
$logFile = Join-Path $testDir "$tC.$tI.log.txt"
|
2017-04-15 01:15:32 +02:00
|
|
|
|
$o = ssh -p $port -v -E $logFile $ssouser@$server echo 1234
|
|
|
|
|
$o | Should Be "1234"
|
|
|
|
|
#TODO - checks below are very inefficient (time taking).
|
|
|
|
|
$logFile | Should Contain "OpenSSH_"
|
|
|
|
|
$logFile | Should Contain "Exit Status 0"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
<#Context "Key is not secured in ssh-agent on server" {
|
2016-12-19 23:48:14 +01:00
|
|
|
|
BeforeAll {
|
|
|
|
|
$identifyFile = $client.clientPrivateKeyPaths[0]
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterEach {
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It '<Title>' -TestCases:$testData1 {
|
|
|
|
|
param([string]$Title, $LogonStr, $Options, $SkipVerification = $false)
|
|
|
|
|
|
|
|
|
|
$str = $ExecutionContext.InvokeCommand.ExpandString(".\ssh $($Options) $($LogonStr) hostname > $filePath")
|
|
|
|
|
$client.RunCmd($str)
|
|
|
|
|
#validate file content.
|
|
|
|
|
Get-Content $filePath | Should be $server.MachineName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context "Key is secured in ssh-agent" {
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$server.SecureHostKeys($server.PrivateHostKeyPaths)
|
|
|
|
|
$identifyFile = $client.clientPrivateKeyPaths[0]
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
|
$Server.CleanupHostKeys()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterEach {
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It '<Title>' -TestCases:$testData1 {
|
|
|
|
|
param([string]$Title, $LogonStr, $Options, $SkipVerification = $false)
|
|
|
|
|
|
|
|
|
|
$str = $ExecutionContext.InvokeCommand.ExpandString(".\ssh $Options $LogonStr hostname > $filePath")
|
|
|
|
|
$client.RunCmd($str)
|
|
|
|
|
#validate file content.
|
|
|
|
|
Get-Content $filePath | Should be $server.MachineName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context "Single signon on client and keys secured in ssh-agent on server" {
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$Server.SecureHostKeys($server.PrivateHostKeyPaths)
|
|
|
|
|
$identifyFile = $client.clientPrivateKeyPaths[0]
|
|
|
|
|
#setup single signon
|
|
|
|
|
.\ssh-add.exe $identifyFile
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
|
$Server.CleanupHostKeys()
|
|
|
|
|
|
|
|
|
|
#cleanup single signon
|
|
|
|
|
.\ssh-add.exe -D
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterEach {
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It '<Title>' -TestCases:$testData {
|
|
|
|
|
param([string]$Title, $LogonStr, $Options)
|
|
|
|
|
|
|
|
|
|
$str = ".\ssh $($Options) $($LogonStr) hostname > $filePath"
|
|
|
|
|
$client.RunCmd($str)
|
|
|
|
|
#validate file content.
|
|
|
|
|
Get-Content $filePath | Should be $server.MachineName
|
|
|
|
|
}
|
2017-01-12 06:54:44 +01:00
|
|
|
|
}
|
|
|
|
|
Context "password authentication" {
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$client.AddPasswordSetting($server.localAdminPassword)
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterAll {
|
|
|
|
|
$client.CleanupPasswordSetting()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterEach {
|
|
|
|
|
Remove-Item -Path $filePath -Force -ea silentlycontinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It '<Title>' -TestCases:$testData {
|
|
|
|
|
param([string]$Title, $LogonStr, $Options)
|
|
|
|
|
|
|
|
|
|
$str = ".\ssh $($Options) $($LogonStr) hostname > $filePath"
|
|
|
|
|
$client.RunCmd($str)
|
|
|
|
|
#validate file content.
|
|
|
|
|
Get-Content $filePath | Should be $server.MachineName
|
|
|
|
|
}
|
2017-04-15 01:15:32 +02:00
|
|
|
|
}#>
|
2016-12-19 23:48:14 +01:00
|
|
|
|
}
|