Source snapshot from Powershell/openssh-portable:latestw_all

This commit is contained in:
bingbing8 2017-05-15 17:36:22 -07:00
parent 6a86fdd825
commit 9fd0cdab04
17 changed files with 261 additions and 142 deletions

View File

@ -1,4 +1,4 @@
version: 0.0.13.0.{build} version: 0.0.14.0.{build}
image: Visual Studio 2015 image: Visual Studio 2015
branches: branches:

View File

@ -119,6 +119,8 @@ WARNING: Following changes will be made to OpenSSH configuration
- will be replaced with a test sshd_config - will be replaced with a test sshd_config
- $HOME\.ssh\known_hosts will be backed up as known_hosts.ori - $HOME\.ssh\known_hosts will be backed up as known_hosts.ori
- will be replaced with a test known_hosts - will be replaced with a test known_hosts
- $HOME\.ssh\config will be backed up as config.ori
- will be replaced with a test config
- sshd test listener will be on port 47002 - sshd test listener will be on port 47002
- $HOME\.ssh\known_hosts will be modified with test host key entry - $HOME\.ssh\known_hosts will be modified with test host key entry
- test accounts - ssouser, pubkeyuser, and passwduser will be added - test accounts - ssouser, pubkeyuser, and passwduser will be added
@ -172,17 +174,23 @@ WARNING: Following changes will be made to OpenSSH configuration
#Backup existing known_hosts and replace with test version #Backup existing known_hosts and replace with test version
#TODO - account for custom known_hosts locations #TODO - account for custom known_hosts locations
$knowHostsDirectoryPath = Join-Path $home .ssh $dotSshDirectoryPath = Join-Path $home .ssh
$knowHostsFilePath = Join-Path $knowHostsDirectoryPath known_hosts $knowHostsFilePath = Join-Path $dotSshDirectoryPath known_hosts
if(-not (Test-Path $knowHostsDirectoryPath -PathType Container)) if(-not (Test-Path $dotSshDirectoryPath -PathType Container))
{ {
New-Item -ItemType Directory -Path $knowHostsDirectoryPath -Force -ErrorAction SilentlyContinue | out-null New-Item -ItemType Directory -Path $dotSshDirectoryPath -Force -ErrorAction SilentlyContinue | out-null
} }
if ((Test-Path $knowHostsFilePath -PathType Leaf) -and (-not (Test-Path (Join-Path $knowHostsDirectoryPath known_hosts.ori) -PathType Leaf))) { if ((Test-Path $knowHostsFilePath -PathType Leaf) -and (-not (Test-Path (Join-Path $dotSshDirectoryPath known_hosts.ori) -PathType Leaf))) {
Copy-Item $knowHostsFilePath (Join-Path $knowHostsDirectoryPath known_hosts.ori) -Force Copy-Item $knowHostsFilePath (Join-Path $dotSshDirectoryPath known_hosts.ori) -Force
} }
Copy-Item (Join-Path $Script:E2ETestDirectory known_hosts) $knowHostsFilePath -Force Copy-Item (Join-Path $Script:E2ETestDirectory known_hosts) $knowHostsFilePath -Force
$sshConfigFilePath = Join-Path $dotSshDirectoryPath config
if ((Test-Path $sshConfigFilePath -PathType Leaf) -and (-not (Test-Path (Join-Path $dotSshDirectoryPath config.ori) -PathType Leaf))) {
Copy-Item $sshConfigFilePath (Join-Path $dotSshDirectoryPath config.ori) -Force
}
Copy-Item (Join-Path $Script:E2ETestDirectory ssh_config) $sshConfigFilePath -Force
# create test accounts # create test accounts
#TODO - this is Windows specific. Need to be in PAL #TODO - this is Windows specific. Need to be in PAL
foreach ($user in $OpenSSHTestAccounts) foreach ($user in $OpenSSHTestAccounts)
@ -212,6 +220,7 @@ WARNING: Following changes will be made to OpenSSH configuration
$testPriKeypath = Join-Path $Script:E2ETestDirectory sshtest_userssokey_ed25519 $testPriKeypath = Join-Path $Script:E2ETestDirectory sshtest_userssokey_ed25519
Cleanup-SecureFileACL -FilePath $testPriKeypath -owner $owner Cleanup-SecureFileACL -FilePath $testPriKeypath -owner $owner
cmd /c "ssh-add $testPriKeypath 2>&1 >> $Script:TestSetupLogFile" cmd /c "ssh-add $testPriKeypath 2>&1 >> $Script:TestSetupLogFile"
Backup-OpenSSHTestInfo
} }
#TODO - this is Windows specific. Need to be in PAL #TODO - this is Windows specific. Need to be in PAL
function Get-LocalUserProfile function Get-LocalUserProfile
@ -314,6 +323,14 @@ function Cleanup-OpenSSHTestEnvironment
Remove-Item $originKnowHostsPath -Force -ErrorAction SilentlyContinue Remove-Item $originKnowHostsPath -Force -ErrorAction SilentlyContinue
} }
#Restore ssh_config
$originConfigPath = Join-Path $home .ssh\config.ori
if (Test-Path $originConfigPath)
{
Copy-Item $originConfigPath (Join-Path $home .ssh\config) -Force -ErrorAction SilentlyContinue
Remove-Item $originConfigPath -Force -ErrorAction SilentlyContinue
}
#Delete accounts #Delete accounts
foreach ($user in $OpenSSHTestAccounts) foreach ($user in $OpenSSHTestAccounts)
{ {
@ -395,7 +412,7 @@ function Run-OpenSSHE2ETest
# Discover all CI tests and run them. # Discover all CI tests and run them.
Push-Location $Script:E2ETestDirectory Push-Location $Script:E2ETestDirectory
Write-Log -Message "Running OpenSSH E2E tests..." Write-Log -Message "Running OpenSSH E2E tests..."
$testFolders = Get-ChildItem *.tests.ps1 -Recurse -Exclude SSHDConfig.tests.ps1, SSH.Tests.ps1 | ForEach-Object{ Split-Path $_.FullName} | Sort-Object -Unique $testFolders = Get-ChildItem *.tests.ps1 -Recurse | ForEach-Object{ Split-Path $_.FullName} | Sort-Object -Unique
Invoke-Pester $testFolders -OutputFormat NUnitXml -OutputFile $Script:E2ETestResultsFile -Tag 'CI' Invoke-Pester $testFolders -OutputFormat NUnitXml -OutputFile $Script:E2ETestResultsFile -Tag 'CI'
Pop-Location Pop-Location
} }
@ -439,6 +456,56 @@ function Run-OpenSSHUnitTest
$testfailed $testfailed
} }
function Backup-OpenSSHTestInfo
{
param
(
[string] $BackupFile = $null
)
if ($Global:OpenSSHTestInfo -eq $null) {
Throw "`$OpenSSHTestInfo is null. Did you run Setup-OpenSSHTestEnvironment yet?"
}
$testInfo = $Global:OpenSSHTestInfo
if ([String]::IsNullOrEmpty($BackupFile)) {
$BackupFile = Join-Path $testInfo["TestDataPath"] "OpenSSHTestInfo_backup.txt"
}
$null | Set-Content $BackupFile
foreach ($key in $testInfo.Keys) {
$value = $testInfo[$key]
Add-Content $BackupFile "$key,$value"
}
}
function Recover-OpenSSHTestInfo
{
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $BackupFile
)
if($Global:OpenSSHTestInfo -ne $null)
{
$Global:OpenSSHTestInfo.Clear()
$Global:OpenSSHTestInfo = $null
}
$Global:OpenSSHTestInfo = @{}
$entries = Get-Content $BackupFile
foreach ($entry in $entries) {
$data = $entry.Split(",")
$Global:OpenSSHTestInfo[$data[0]] = $data[1]
}
}
<# <#
Write-Log Write-Log
#> #>
@ -460,4 +527,4 @@ function Write-Log
} }
} }
Export-ModuleMember -Function Setup-OpenSSHTestEnvironment, Cleanup-OpenSSHTestEnvironment, Run-OpenSSHUnitTest, Run-OpenSSHE2ETest Export-ModuleMember -Function Setup-OpenSSHTestEnvironment, Cleanup-OpenSSHTestEnvironment, Run-OpenSSHUnitTest, Run-OpenSSHE2ETest, Backup-OpenSSHTestInfo, Recover-OpenSSHTestInfo

Binary file not shown.

View File

@ -66,7 +66,7 @@ typedef struct _SCREEN_RECORD {
PSCREEN_RECORD pSavedScreenRec = NULL; PSCREEN_RECORD pSavedScreenRec = NULL;
int in_raw_mode = 0; int in_raw_mode = 0;
char *consoleTitle = "Microsoft openSSH client"; char *consoleTitle = "OpenSSH SSH client";
/* Used to enter the raw mode */ /* Used to enter the raw mode */
int int

View File

@ -117,7 +117,7 @@ char* _sys_errlist_ext[] = {
"No STREAM resources", /* ENOSR 124 */ "No STREAM resources", /* ENOSR 124 */
"Not a STREAM", /* ENOSTR 125 */ "Not a STREAM", /* ENOSTR 125 */
"The socket is not connected", /* ENOTCONN 126 */ "The socket is not connected", /* ENOTCONN 126 */
"enotecoverable", /* ENOTRECOVERABLE 127 */ "enotrecoverable", /* ENOTRECOVERABLE 127 */
"Not a socket", /* ENOTSOCK 128 */ "Not a socket", /* ENOTSOCK 128 */
"Operation not supported", /* ENOTSUP 129 */ "Operation not supported", /* ENOTSUP 129 */
"Operation not supported on socket", /* EOPNOTSUPP 130 */ "Operation not supported on socket", /* EOPNOTSUPP 130 */
@ -256,7 +256,6 @@ w32_fopen_utf8(const char *path, const char *mode)
} }
f = _wfopen(wpath, wmode); f = _wfopen(wpath, wmode);
if (f) { if (f) {
/* BOM adjustments for file streams*/ /* BOM adjustments for file streams*/
if (mode[0] == 'w' && fseek(f, 0, SEEK_SET) != EBADF) { if (mode[0] == 'w' && fseek(f, 0, SEEK_SET) != EBADF) {

View File

@ -55,8 +55,9 @@
*/ */
int int
check_secure_file_permission(const char *name, struct passwd * pw) check_secure_file_permission(const char *name, struct passwd * pw)
{ {
PSECURITY_DESCRIPTOR pSD = NULL; return 0;
/*PSECURITY_DESCRIPTOR pSD = NULL;
wchar_t * name_utf16 = NULL; wchar_t * name_utf16 = NULL;
PSID owner_sid = NULL, user_sid = NULL; PSID owner_sid = NULL, user_sid = NULL;
PACL dacl = NULL; PACL dacl = NULL;
@ -79,10 +80,10 @@ check_secure_file_permission(const char *name, struct passwd * pw)
if ((name_utf16 = utf8_to_utf16(name)) == NULL) { if ((name_utf16 = utf8_to_utf16(name)) == NULL) {
errno = ENOMEM; errno = ENOMEM;
goto cleanup; goto cleanup;
} }*/
/*Get the owner sid of the file.*/ /*Get the owner sid of the file.*/
if ((error_code = GetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT, /*if ((error_code = GetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
&owner_sid, NULL, &dacl, NULL, &pSD)) != ERROR_SUCCESS) { &owner_sid, NULL, &dacl, NULL, &pSD)) != ERROR_SUCCESS) {
debug3("failed to retrieve the owner sid and dacl of file %s with error code: %d", name, error_code); debug3("failed to retrieve the owner sid and dacl of file %s with error code: %d", name, error_code);
@ -102,14 +103,14 @@ check_secure_file_permission(const char *name, struct passwd * pw)
debug3("Bad owner on %s", name); debug3("Bad owner on %s", name);
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }*/
/* /*
iterate all aces of the file to find out if there is voilation of the following rules: iterate all aces of the file to find out if there is voilation of the following rules:
1. no others than administrators group, system account, and current user, owner accounts have write permission on the file 1. no others than administrators group, system account, and current user, owner accounts have write permission on the file
2. sshd account can only have read permission 2. sshd account can only have read permission
3. this user and file owner should at least have read permission 3. this user and file owner should at least have read permission
*/ */
for (DWORD i = 0; i < dacl->AceCount; i++) { /*for (DWORD i = 0; i < dacl->AceCount; i++) {
PVOID current_ace = NULL; PVOID current_ace = NULL;
PACE_HEADER current_aceHeader = NULL; PACE_HEADER current_aceHeader = NULL;
PSID current_trustee_sid = NULL; PSID current_trustee_sid = NULL;
@ -152,10 +153,10 @@ check_secure_file_permission(const char *name, struct passwd * pw)
// Not interested ACE // Not interested ACE
continue; continue;
} }
} }*/
/*no need to check administrators group, owner account, user account and system account*/ /*no need to check administrators group, owner account, user account and system account*/
if (IsWellKnownSid(current_trustee_sid, WinBuiltinAdministratorsSid) || /*if (IsWellKnownSid(current_trustee_sid, WinBuiltinAdministratorsSid) ||
IsWellKnownSid(current_trustee_sid, WinLocalSystemSid) || IsWellKnownSid(current_trustee_sid, WinLocalSystemSid) ||
EqualSid(current_trustee_sid, owner_sid) || EqualSid(current_trustee_sid, owner_sid) ||
EqualSid(current_trustee_sid, user_sid) || EqualSid(current_trustee_sid, user_sid) ||
@ -188,7 +189,7 @@ cleanup:
FreeSid(user_sid); FreeSid(user_sid);
if(name_utf16) if(name_utf16)
free(name_utf16); free(name_utf16);
return ret; return ret;*/
} }
static BOOL static BOOL
@ -267,7 +268,8 @@ done:
int int
set_secure_file_permission(const char *name, struct passwd * pw) set_secure_file_permission(const char *name, struct passwd * pw)
{ {
PSECURITY_DESCRIPTOR pSD = NULL; return 0;
/*PSECURITY_DESCRIPTOR pSD = NULL;
PSID owner_sid = NULL; PSID owner_sid = NULL;
PACL dacl = NULL; PACL dacl = NULL;
wchar_t *name_utf16 = NULL, *sid_utf16 = NULL, sddl[256]; wchar_t *name_utf16 = NULL, *sid_utf16 = NULL, sddl[256];
@ -327,10 +329,10 @@ set_secure_file_permission(const char *name, struct passwd * pw)
errno = ENOMEM; errno = ENOMEM;
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }*/
/*Set the owner sid and acl of the file.*/ /*Set the owner sid and acl of the file.*/
if ((error_code = SetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT, /*if ((error_code = SetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | PROTECTED_DACL_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | PROTECTED_DACL_SECURITY_INFORMATION,
owner_sid, NULL, dacl, NULL)) != ERROR_SUCCESS) { owner_sid, NULL, dacl, NULL)) != ERROR_SUCCESS) {
debug3("failed to set the owner sid and dacl of file %s with error code: %d", name, error_code); debug3("failed to set the owner sid and dacl of file %s with error code: %d", name, error_code);
@ -348,5 +350,5 @@ cleanup:
if (owner_sid) if (owner_sid)
FreeSid(owner_sid); FreeSid(owner_sid);
return ret; return ret;*/
} }

View File

@ -1,5 +1,5 @@
Import-Module $PSScriptRoot\CommonUtils.psm1 -Force Import-Module $PSScriptRoot\CommonUtils.psm1 -Force
Describe "Tests for authorized_keys file permission" -Tags "CI" { Describe "Tests for authorized_keys file permission" -Tags "Scenario" {
BeforeAll { BeforeAll {
if($OpenSSHTestInfo -eq $null) if($OpenSSHTestInfo -eq $null)
{ {

View File

@ -1,4 +1,4 @@
Describe "Tests for ssh config" -Tags "CI" { Describe "Tests for ssh config" -Tags "Scenario" {
BeforeAll { BeforeAll {
if($OpenSSHTestInfo -eq $null) if($OpenSSHTestInfo -eq $null)
{ {

View File

@ -1,5 +1,5 @@
Import-Module $PSScriptRoot\CommonUtils.psm1 -Force Import-Module $PSScriptRoot\CommonUtils.psm1 -Force
Describe "Tests for host keys file permission" -Tags "CI" { Describe "Tests for host keys file permission" -Tags "Scenario" {
BeforeAll { BeforeAll {
if($OpenSSHTestInfo -eq $null) if($OpenSSHTestInfo -eq $null)
{ {

View File

@ -2,7 +2,7 @@
$tI = 0 $tI = 0
$suite = "keyutils" $suite = "keyutils"
Describe "E2E scenarios for ssh key management" -Tags "CI" { Describe "E2E scenarios for ssh key management" -Tags "Scenario" {
BeforeAll { BeforeAll {
if($OpenSSHTestInfo -eq $null) if($OpenSSHTestInfo -eq $null)
{ {
@ -14,6 +14,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
{ {
$null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue $null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue
} }
$keypassphrase = "testpassword" $keypassphrase = "testpassword"
$keytypes = @("rsa","dsa","ecdsa","ed25519") $keytypes = @("rsa","dsa","ecdsa","ed25519")
#only validate owner and ACE of the file #only validate owner and ACE of the file
@ -36,8 +37,12 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
} }
BeforeEach { BeforeEach {
$tI++; $stderrFile=Join-Path $testDir "$tC.$tI.stderr.txt"
} $stdoutFile=Join-Path $testDir "$tC.$tI.stdout.txt"
$logFile = Join-Path $testDir "$tC.$tI.log.txt"
}
AfterEach {$tI++;}
Context "$tC - ssh-keygen all key types" { Context "$tC - ssh-keygen all key types" {
@ -124,6 +129,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
#ensure added keys are listed #ensure added keys are listed
$allkeys = ssh-add -L $allkeys = ssh-add -L
$allkeys | Set-Content (Join-Path $testDir "$tC.$tI.allkeyonAdd.txt")
foreach($type in $keytypes) foreach($type in $keytypes)
{ {
@ -141,7 +147,8 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
#check keys are deleted #check keys are deleted
$allkeys = ssh-add -L $allkeys = ssh-add -L
$allkeys | Set-Content (Join-Path $testDir "$tC.$tI.allkeyonDelete.txt")
foreach($type in $keytypes) foreach($type in $keytypes)
{ {
$keyPath = Join-Path $testDir "id_$type" $keyPath = Join-Path $testDir "id_$type"

View File

@ -1,48 +1,36 @@
 $tC = 1
Describe "Tests for portforwarding" -Tags "CI" { $tI = 0
$suite = "portfwd"
Describe "E2E scenarios for port forwarding" -Tags "CI" {
BeforeAll { BeforeAll {
$testDir = Join-Path $OpenSSHTestInfo["TestDataPath"] $suite
if($OpenSSHTestInfo -eq $null) if(-not (Test-Path $testDir))
{ {
Throw "`$OpenSSHTestInfo is null. Please run Setup-OpenSSHTestEnvironment to setup test environment." $null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue
} }
$fileName = "test.txt"
$filePath = Join-Path ${TestDrive} $fileName
$logName = "log.txt"
$logPath = Join-Path ${TestDrive} $logName
$server = $OpenSSHTestInfo["Target"]
$port = $OpenSSHTestInfo["Port"]
$ssouser = $OpenSSHTestInfo["SSOUser"]
$testData = @(
@{
Title = "Local port forwarding"
Options = "-L 5432:127.0.0.1:47001"
FwdedPort = 5432
},
@{
Title = "Remote port forwarding"
Options = "-R 5432:127.0.0.1:47001"
FwdedPort = 5432
}
)
} }
AfterEach { BeforeEach {
Remove-Item -Path $filePath -Force -ea silentlycontinue $stderrFile=Join-Path $testDir "$tC.$tI.stderr.txt"
Remove-Item -Path $logPath -Force -ea silentlycontinue $stdoutFile=Join-Path $testDir "$tC.$tI.stdout.txt"
} $logFile = Join-Path $testDir "$tC.$tI.log.txt"
}
AfterEach {$tI++;}
It '<Title>' -TestCases:$testData { Context "$tC - Basic port forwarding scenarios" {
param([string]$Title, $Options, $FwdedPort) BeforeAll {$tI=1}
AfterAll{$tC++}
$str = "ssh -p $($port) -E $logPath $($Options) $($ssouser)@$($server) powershell.exe Test-WSMan -computer 127.0.0.1 -port $FwdedPort > $filePath"
# TODO - move this to PAL #TODO - this relies on winrm (that is windows specific)
cmd /c $str It "$tC.$tI - local port forwarding" {
#validate file content. ssh -L 5432:127.0.0.1:47001 test_target powershell.exe Test-WSMan -computer 127.0.0.1 -port 5432 | Set-Content $stdoutFile
$content = Get-Content $filePath $stdoutFile | Should Contain "wsmid"
$content -like "wsmid*" | Should Not Be $null }
}
It "$tC.$tI - remote port forwarding" {
ssh -R 5432:127.0.0.1:47001 test_target powershell.exe Test-WSMan -computer 127.0.0.1 -port 5432 | Set-Content $stdoutFile
$stdoutFile | Should Contain "wsmid"
}
}
} }

View File

@ -1,4 +1,4 @@
Run OpenSSH Pester Tests: Run OpenSSH Pester Tests:
================================== ==================================
#### To setup the test environment before test run: #### To setup the test environment before test run:
@ -40,3 +40,27 @@ $OpenSSHTestInfo["DebugMode"] = $true
```powershell ```powershell
Cleanup-OpenSSHTestEnvironment Cleanup-OpenSSHTestEnvironment
``` ```
#### Guidelines for writing Pester based OpenSSH test cases
Follow these simple steps for test case indexing
- Initialize the following variables at start
```
$tC = 1
$tI = 0
```
- Place the following blocks in Describe
```
BeforeEach {
$stderrFile=Join-Path $testDir "$tC.$tI.stderr.txt"
$stdoutFile=Join-Path $testDir "$tC.$tI.stdout.txt"
$logFile = Join-Path $testDir "$tC.$tI.log.txt"
}
AfterEach {$tI++;}
```
- Place the following blocks in each Context
```
BeforeAll {$tI=1}
AfterAll{$tC++}
```
- Prefix any test out file with $tC.$tI. You may use pre-created $stderrFile, $stdoutFile, $logFile for this purpose

View File

@ -8,11 +8,6 @@ Describe "Tests for scp command" -Tags "CI" {
Throw "`$OpenSSHTestInfo is null. Please run Setup-OpenSSHTestEnvironment to setup test environment." 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
}
$fileName1 = "test.txt" $fileName1 = "test.txt"
$fileName2 = "test2.txt" $fileName2 = "test2.txt"
$SourceDirName = "SourceDir" $SourceDirName = "SourceDir"
@ -46,12 +41,12 @@ Describe "Tests for scp command" -Tags "CI" {
@{ @{
Title = 'Simple copy local file to remote file' Title = 'Simple copy local file to remote file'
Source = $SourceFilePath Source = $SourceFilePath
Destination = "$($ssouser)@$($server):$DestinationFilePath" Destination = "test_target:$DestinationFilePath"
Options = "-P $port -S $sshcmd" Options = "-P $port -S $sshcmd"
}, },
@{ @{
Title = 'Simple copy remote file to local file' Title = 'Simple copy remote file to local file'
Source = "$($ssouser)@$($server):$SourceFilePath" Source = "test_target:$SourceFilePath"
Destination = $DestinationFilePath Destination = $DestinationFilePath
Options = "-P $port -p -c aes128-ctr -C" Options = "-P $port -p -c aes128-ctr -C"
}, },
@ -64,12 +59,12 @@ Describe "Tests for scp command" -Tags "CI" {
@{ @{
Title = 'simple copy local file to remote dir' Title = 'simple copy local file to remote dir'
Source = $SourceFilePath Source = $SourceFilePath
Destination = "$($ssouser)@$($server):$DestinationDir" Destination = "test_target:$DestinationDir"
Options = "-P $port -C -q" Options = "-P $port -C -q"
}<#, }<#,
@{ @{
Title = 'simple copy remote file to local dir' Title = 'simple copy remote file to local dir'
Source = "$($ssouser)@$($server):$SourceFilePath" Source = "test_target:$SourceFilePath"
Destination = $DestinationDir Destination = $DestinationDir
Options = "-P $port " Options = "-P $port "
}#> }#>
@ -79,7 +74,7 @@ Describe "Tests for scp command" -Tags "CI" {
@{ @{
Title = 'copy from local dir to remote dir' Title = 'copy from local dir to remote dir'
Source = $sourceDir Source = $sourceDir
Destination = "$($ssouser)@$($server):$DestinationDir" Destination = "test_target:$DestinationDir"
Options = "-P $port -r -p -c aes128-ctr" Options = "-P $port -r -p -c aes128-ctr"
}, },
@{ @{
@ -90,7 +85,7 @@ Describe "Tests for scp command" -Tags "CI" {
}, },
@{ @{
Title = 'copy from remote dir to local dir' Title = 'copy from remote dir to local dir'
Source = "$($ssouser)@$($server):$sourceDir" Source = "test_target:$sourceDir"
Destination = $DestinationDir Destination = $DestinationDir
Options = "-P $port -C -r -q" Options = "-P $port -C -r -q"
} }

View File

@ -5,11 +5,6 @@
Throw "`$OpenSSHTestInfo is null. Please run Setup-OpenSSHTestEnvironment to setup test environment." 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
}
$rootDirectory = "$($OpenSSHTestInfo["TestDataPath"])\SFTP" $rootDirectory = "$($OpenSSHTestInfo["TestDataPath"])\SFTP"
$outputFileName = "output.txt" $outputFileName = "output.txt"
@ -41,7 +36,6 @@
$testData1 = @( $testData1 = @(
@{ @{
title = "put, ls for non-unicode file names" title = "put, ls for non-unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "put $tempFilePath $serverDirectory commands = "put $tempFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -49,7 +43,6 @@
}, },
@{ @{
title = "get, ls for non-unicode file names" title = "get, ls for non-unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "get $tempFilePath $clientDirectory commands = "get $tempFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -57,7 +50,6 @@
}, },
@{ @{
title = "mput, ls for non-unicode file names" title = "mput, ls for non-unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mput $tempFilePath $serverDirectory commands = "mput $tempFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -65,7 +57,6 @@
}, },
@{ @{
title = "mget, ls for non-unicode file names" title = "mget, ls for non-unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mget $tempFilePath $clientDirectory commands = "mget $tempFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -73,7 +64,6 @@
}, },
@{ @{
title = "mkdir, cd, pwd for non-unicode directory names" title = "mkdir, cd, pwd for non-unicode directory names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "cd $serverdirectory commands = "cd $serverdirectory
mkdir server_test_dir mkdir server_test_dir
@ -83,7 +73,6 @@
}, },
@{ @{
Title = "lmkdir, lcd, lpwd for non-unicode directory names" Title = "lmkdir, lcd, lpwd for non-unicode directory names"
LogonStr = "$($ssouser)@$($server)"
Options = '' Options = ''
Commands = "lcd $clientDirectory Commands = "lcd $clientDirectory
lmkdir client_test_dir lmkdir client_test_dir
@ -93,7 +82,6 @@
}, },
@{ @{
title = "put, ls for unicode file names" title = "put, ls for unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "put $tempUnicodeFilePath $serverDirectory commands = "put $tempUnicodeFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -101,7 +89,6 @@
}, },
@{ @{
title = "get, ls for unicode file names" title = "get, ls for unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "get $tempUnicodeFilePath $clientDirectory commands = "get $tempUnicodeFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -109,7 +96,6 @@
}, },
@{ @{
title = "mput, ls for unicode file names" title = "mput, ls for unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mput $tempUnicodeFilePath $serverDirectory commands = "mput $tempUnicodeFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -117,7 +103,6 @@
}, },
@{ @{
title = "mget, ls for unicode file names" title = "mget, ls for unicode file names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mget $tempUnicodeFilePath $clientDirectory commands = "mget $tempUnicodeFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -125,7 +110,6 @@
}, },
@{ @{
title = "mkdir, cd, pwd for unicode directory names" title = "mkdir, cd, pwd for unicode directory names"
logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "cd $serverdirectory commands = "cd $serverdirectory
mkdir server_test_dir_язык mkdir server_test_dir_язык
@ -135,7 +119,6 @@
}, },
@{ @{
Title = "lmkdir, lcd, lpwd for unicode directory names" Title = "lmkdir, lcd, lpwd for unicode directory names"
LogonStr = "$($ssouser)@$($server)"
Options = '' Options = ''
Commands = "lcd $clientDirectory Commands = "lcd $clientDirectory
lmkdir client_test_dir_язык lmkdir client_test_dir_язык
@ -149,7 +132,6 @@
$testData2 = @( $testData2 = @(
@{ @{
title = "rm, rmdir, rename for unicode file, directory" title = "rm, rmdir, rename for unicode file, directory"
logonstr = "$($ssouser)@$($server)"
options = '-b $batchFilePath' options = '-b $batchFilePath'
tmpFileName1 = $tempUnicodeFileName tmpFileName1 = $tempUnicodeFileName
@ -164,7 +146,6 @@
}, },
@{ @{
title = "rm, rmdir, rename for non-unicode file, directory" title = "rm, rmdir, rename for non-unicode file, directory"
logonstr = "$($ssouser)@$($server)"
options = '-b $batchFilePath' options = '-b $batchFilePath'
tmpFileName1 = $tempFileName tmpFileName1 = $tempFileName
@ -223,10 +204,10 @@
} }
It '<Title>' -TestCases:$testData1 { It '<Title>' -TestCases:$testData1 {
param([string]$Title, $LogonStr, $Options, $Commands, $ExpectedOutput) param([string]$Title, $Options, $Commands, $ExpectedOutput)
Set-Content $batchFilePath -Encoding UTF8 -value $Commands Set-Content $batchFilePath -Encoding UTF8 -value $Commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) -b $batchFilePath $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) -b $batchFilePath test_target > $outputFilePath")
iex $str iex $str
#validate file content. #validate file content.
@ -234,14 +215,14 @@
} }
It '<Title>' -TestCases:$testData2 { It '<Title>' -TestCases:$testData2 {
param([string]$Title, $LogonStr, $Options, $tmpFileName1, $tmpFilePath1, $tmpFileName2, $tmpFilePath2, $tmpDirectoryName1, $tmpDirectoryPath1, $tmpDirectoryName2, $tmpDirectoryPath2) param([string]$Title, $Options, $tmpFileName1, $tmpFilePath1, $tmpFileName2, $tmpFilePath2, $tmpDirectoryName1, $tmpDirectoryPath1, $tmpDirectoryName2, $tmpDirectoryPath2)
#rm (remove file) #rm (remove file)
$commands = "mkdir $tmpDirectoryPath1 $commands = "mkdir $tmpDirectoryPath1
put $tmpFilePath1 $tmpDirectoryPath1 put $tmpFilePath1 $tmpDirectoryPath1
ls $tmpDirectoryPath1" ls $tmpDirectoryPath1"
Set-Content $batchFilePath -Encoding UTF8 -value $commands Set-Content $batchFilePath -Encoding UTF8 -value $commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) test_target > $outputFilePath")
iex $str iex $str
Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $true Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $true
@ -250,7 +231,7 @@
pwd pwd
" "
Set-Content $batchFilePath -Encoding UTF8 -value $commands Set-Content $batchFilePath -Encoding UTF8 -value $commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) test_target > $outputFilePath")
iex $str iex $str
Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $false Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $false
@ -261,7 +242,7 @@
ls $tmpDirectoryPath1 ls $tmpDirectoryPath1
pwd" pwd"
Set-Content $batchFilePath -Encoding UTF8 -value $commands Set-Content $batchFilePath -Encoding UTF8 -value $commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) test_target > $outputFilePath")
iex $str iex $str
Test-Path (join-path $tmpDirectoryPath1 $tmpFileName2) | Should be $true Test-Path (join-path $tmpDirectoryPath1 $tmpFileName2) | Should be $true
@ -271,7 +252,7 @@
rename $tmpDirectoryPath1 $tmpDirectoryPath2 rename $tmpDirectoryPath1 $tmpDirectoryPath2
ls $serverDirectory" ls $serverDirectory"
Set-Content $batchFilePath -Encoding UTF8 -value $commands Set-Content $batchFilePath -Encoding UTF8 -value $commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) test_target > $outputFilePath")
iex $str iex $str
Test-Path $tmpDirectoryPath2 | Should be $true Test-Path $tmpDirectoryPath2 | Should be $true
@ -280,7 +261,7 @@
$commands = "rmdir $tmpDirectoryPath2 $commands = "rmdir $tmpDirectoryPath2
ls $serverDirectory" ls $serverDirectory"
Set-Content $batchFilePath -Encoding UTF8 -value $commands Set-Content $batchFilePath -Encoding UTF8 -value $commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) test_target > $outputFilePath")
iex $str iex $str
Test-Path $tmpDirectoryPath2 | Should be $false Test-Path $tmpDirectoryPath2 | Should be $false
} }

View File

@ -2,31 +2,26 @@
#todo: -S -F -V -e #todo: -S -F -V -e
$tC = 1 $tC = 1
$tI = 0 $tI = 0
$suite = "sshclient"
Describe "ssh client tests" -Tags "CI" { Describe "E2E scenarios for ssh client" -Tags "CI" {
BeforeAll { BeforeAll {
if($OpenSSHTestInfo -eq $null) if($OpenSSHTestInfo -eq $null)
{ {
Throw "`$OpenSSHTestInfo is null. Please run Setup-OpenSSHTestEnvironment to setup test environment." 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
}
$server = $OpenSSHTestInfo["Target"] $server = $OpenSSHTestInfo["Target"]
$port = $OpenSSHTestInfo["Port"] $port = $OpenSSHTestInfo["Port"]
$ssouser = $OpenSSHTestInfo["SSOUser"] $ssouser = $OpenSSHTestInfo["SSOUser"]
$sshCmdDefault = "ssh -p $port $($ssouser)@$($server)"
$testDir = Join-Path $OpenSSHTestInfo["TestDataPath"] "ssh" $testDir = Join-Path $OpenSSHTestInfo["TestDataPath"] $suite
if(-not (Test-Path $testDir)) if(-not (Test-Path $testDir))
{ {
$null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue $null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue
} }
$testData = @( <#$testData = @(
@{ @{
Title = 'Simple logon no option'; Title = 'Simple logon no option';
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
@ -55,51 +50,60 @@ Describe "ssh client tests" -Tags "CI" {
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
Options = '-i $identifyFile -c aes256-ctr' Options = '-i $identifyFile -c aes256-ctr'
}, },
<# -V does not redirect to file -V does not redirect to file
@{ @{
Title = "logon using -i -V option" Title = "logon using -i -V option"
LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" LogonStr = "$($server.localAdminUserName)@$($server.MachineName)"
Options = '-i $identifyFile -V' Options = '-i $identifyFile -V'
SkipVerification = $true SkipVerification = $true
},#> },
@{ @{
Title = 'logon using -i -l option' Title = 'logon using -i -l option'
LogonStr = $server.MachineName LogonStr = $server.MachineName
Options = '-i $identifyFile -l $($server.localAdminUserName)' Options = '-i $identifyFile -l $($server.localAdminUserName)'
} }
) )#>
} }
BeforeEach { BeforeEach {
$tI++; $stderrFile=Join-Path $testDir "$tC.$tI.stderr.txt"
$tFile=Join-Path $testDir "$tC.$tI.txt" $stdoutFile=Join-Path $testDir "$tC.$tI.stdout.txt"
$logFile = Join-Path $testDir "$tC.$tI.log.txt"
} }
AfterEach {$tI++;}
Context "$tC - Basic Scenarios" { Context "$tC - Basic Scenarios" {
BeforeAll {$tI=1} BeforeAll {$tI=1}
AfterAll{$tC++} AfterAll{$tC++}
It "$tC.$tI - test version" { It "$tC.$tI - test version" {
iex "cmd /c `"ssh -V 2> $tFile`"" iex "cmd /c `"ssh -V 2> $stderrFile`""
$tFile | Should Contain "OpenSSH_" $stderrFile | Should Contain "OpenSSH_"
} }
It "$tC.$tI - test help" { It "$tC.$tI - test help" {
iex "cmd /c `"ssh -? 2> $tFile`"" iex "cmd /c `"ssh -? 2> $stderrFile`""
$tFile | Should Contain "usage: ssh" $stderrFile | Should Contain "usage: ssh"
} }
It "$tC.$tI - remote echo command" { It "$tC.$tI - remote echo command" {
iex "$sshDefaultCmd echo 1234" | Should Be "1234" iex "$sshDefaultCmd echo 1234" | Should Be "1234"
} }
It "$tC.$tI - exit code" { }
ssh -p $port $ssouser@$server exit 0
$LASTEXITCODE | Should Be 0 Context "$tC - exit code (exit-status.sh)" {
ssh -p $port $ssouser@$server exit 21 BeforeAll {$tI=1}
$LASTEXITCODE | Should Be 21 AfterAll{$tC++}
It "$tC.$tI - various exit codes" {
foreach ($i in (0,1,4,5,44)) {
ssh -p $port $ssouser@$server exit $i
$LASTEXITCODE | Should Be $i
}
} }
} }
@ -109,12 +113,12 @@ Describe "ssh client tests" -Tags "CI" {
AfterAll{$tC++} AfterAll{$tC++}
It "$tC.$tI - stdout to file" { It "$tC.$tI - stdout to file" {
iex "$sshDefaultCmd powershell get-process > $tFile" ssh test_target powershell get-process > $stdoutFile
$tFile | Should Contain "ProcessName" $stdoutFile | Should Contain "ProcessName"
} }
It "$tC.$tI - stdout to PS object" { It "$tC.$tI - stdout to PS object" {
$o = iex "$sshDefaultCmd echo 1234" $o = ssh test_target echo 1234
$o | Should Be "1234" $o | Should Be "1234"
} }
@ -130,16 +134,63 @@ Describe "ssh client tests" -Tags "CI" {
BeforeAll {$tI=1} BeforeAll {$tI=1}
AfterAll{$tC++} AfterAll{$tC++}
It "$tC.$tI - verbose to file" { It "$tC.$tI - verbose to file (-v -E)" {
$logFile = Join-Path $testDir "$tC.$tI.log.txt" $o = ssh -v -E $logFile test_target echo 1234
$o = ssh -p $port -v -E $logFile $ssouser@$server echo 1234
$o | Should Be "1234" $o | Should Be "1234"
#TODO - checks below are very inefficient (time taking). #TODO - checks below are very inefficient (time taking).
$logFile | Should Contain "OpenSSH_" $logFile | Should Contain "OpenSSH_"
$logFile | Should Contain "Exit Status 0" $logFile | Should Contain "Exit Status 0"
} }
It "$tC.$tI - cipher options (-c)" {
#bad cipher
iex "cmd /c `"ssh -c bad_cipher test_target echo 1234 2>$stderrFile`""
$stderrFile | Should Contain "Unknown cipher type"
#good cipher, ensure cipher is used from debug logs
$o = ssh -c aes256-ctr -v -E $logFile test_target echo 1234
$o | Should Be "1234"
$logFile | Should Contain "kex: server->client cipher: aes256-ctr"
$logFile | Should Contain "kex: client->server cipher: aes256-ctr"
}
It "$tC.$tI - ssh_config (-F)" {
#ensure -F is working by pointing to a bad configuration
$badConfigFile = Join-Path $testDir "$tC.$tI.bad_ssh_config"
"bad_config_line" | Set-Content $badConfigFile
iex "cmd /c `"ssh -F $badConfigFile test_target echo 1234 2>$stderrFile`""
$stderrFile | Should Contain "bad_ssh_config"
$stderrFile | Should Contain "bad_config_line"
$stderrFile | Should Contain "bad configuration options"
#try with a proper configuration file. Put it on a unicode path with unicode content
#so we can test the Unicode support simultaneously
$goodConfigFile = Join-Path $testDir "$tC.$tI.Очень_хорошо_ssh_config"
"#this is a Unicode comment because it contains русский язык" | Set-Content $goodConfigFile -Encoding UTF8
"Host myhost" | Add-Content $goodConfigFile
" HostName $server" | Add-Content $goodConfigFile
" Port $port" | Add-Content $goodConfigFile
" User $ssouser" | Add-Content $goodConfigFile
$o = ssh -F $goodConfigFile myhost echo 1234
$o | Should Be "1234"
}
It "$tC.$tI - IP options - (-4) (-6)" {
# TODO - this test assumes target is localhost.
# make it work independent of target
#-4
$o = ssh -4 -v -E $logFile test_target echo 1234
$o | Should Be "1234"
$logFile | Should Contain "[127.0.0.1]"
#-4
$o = ssh -6 -v -E $logFile test_target echo 1234
$o | Should Be "1234"
$logFile | Should Contain "[::1]"
}
} }
<#Context "Key is not secured in ssh-agent on server" { <#Context "Key is not secured in ssh-agent on server" {
BeforeAll { BeforeAll {
$identifyFile = $client.clientPrivateKeyPaths[0] $identifyFile = $client.clientPrivateKeyPaths[0]

View File

@ -1,5 +1,5 @@
Import-Module $PSScriptRoot\CommonUtils.psm1 -Force Import-Module $PSScriptRoot\CommonUtils.psm1 -Force
Describe "Tests for user Key file permission" -Tags "CI" { Describe "Tests for user Key file permission" -Tags "Scenario" {
BeforeAll { BeforeAll {
if($OpenSSHTestInfo -eq $null) if($OpenSSHTestInfo -eq $null)
{ {

View File

@ -0,0 +1,5 @@
# host alias for OpenSSH E2E tests
Host test_target
HostName localhost
Port 47002
User sshtest_ssouser