Enabled SFTP E2E tests based on test framework changes (#101)

This commit is contained in:
bagajjal 2017-03-31 11:47:24 -07:00 committed by Manoj Ampalam
parent 0d1b232d3b
commit 589f2db723
5 changed files with 160 additions and 115 deletions

View File

@ -141,6 +141,11 @@ WARNING: Following changes will be made to OpenSSH configuration
Install-OpenSSHTestDependencies Install-OpenSSHTestDependencies
if(-not (Test-path $TestDataPath -PathType Container))
{
New-Item -ItemType Directory -Path $TestDataPath -Force -ErrorAction SilentlyContinue | out-null
}
#Backup existing OpenSSH configuration #Backup existing OpenSSH configuration
$backupConfigPath = Join-Path $script:OpenSSHBinPath sshd_config.ori $backupConfigPath = Join-Path $script:OpenSSHBinPath sshd_config.ori
if (-not (Test-Path $backupConfigPath -PathType Leaf)) { if (-not (Test-Path $backupConfigPath -PathType Leaf)) {

View File

@ -27,6 +27,14 @@ Run-OpenSSHUnitTest
C:\git\openssh-portable\regress\pesterTests\SCP.Tests.ps1 C:\git\openssh-portable\regress\pesterTests\SCP.Tests.ps1
C:\git\openssh-portable\bin\x64\Release\unittest-bitmap\unittest-bitmap.exe C:\git\openssh-portable\bin\x64\Release\unittest-bitmap\unittest-bitmap.exe
``` ```
#### To verify / modify (Ex- DebugMode) the Test setup environment
```powershell
$OpenSSHTestInfo
$OpenSSHTestInfo["DebugMode"] = $true
```
#### To revert what's done in Setup-OpenSSHTestEnvironment: #### To revert what's done in Setup-OpenSSHTestEnvironment:
```powershell ```powershell

View File

@ -96,14 +96,11 @@ Describe "Tests for scp command" -Tags "CI" {
} }
) )
# for the first time, delete the existing log files.
if ($OpenSSHTestInfo['DebugMode']) if ($OpenSSHTestInfo['DebugMode'])
{ {
Stop-Service ssh-agent -Force Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore
Start-Sleep 2 Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore
# Fix this - pick up logs from ssh installation dir, not test directory
Remove-Item "$($OpenSSHTestInfo['OpenSSHDir'])\logs\ssh-agent.log" -Force -ErrorAction ignore
Remove-Item "$($OpenSSHTestInfo['OpenSSHDir'])\logs\sshd.log" -Force -ErrorAction ignore
Start-Service sshd
} }
function CheckTarget { function CheckTarget {
@ -112,9 +109,14 @@ Describe "Tests for scp command" -Tags "CI" {
{ {
if( $OpenSSHTestInfo["DebugMode"]) if( $OpenSSHTestInfo["DebugMode"])
{ {
Copy-Item "$($OpenSSHTestInfo['OpenSSHDir'])\logs\ssh-agent.log" "$($OpenSSHTestInfo['OpenSSHDir'])\logs\failedagent$script:logNum.log" -Force Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\failedagent$script:logNum.log" -Force
Copy-Item "$($OpenSSHTestInfo['OpenSSHDir'])\logs\sshd.log" "$($OpenSSHTestInfo['OpenSSHDir'])\logs\failedsshd$script:logNum.log" -Force Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\failedsshd$script:logNum.log" -Force
$script:logNum++ $script:logNum++
# clear the ssh-agent, sshd logs so that next testcase will get fresh logs.
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore
} }
return $false return $false

View File

@ -1,6 +1,16 @@
Describe "SFTP Testcases" -Tags "Scenario" { Describe "SFTP Test Cases" -Tags "CI" {
BeforeAll { BeforeAll {
$rootDirectory = $TestDrive 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
}
$rootDirectory = "$($OpenSSHTestInfo["TestDataPath"])\SFTP"
$outputFileName = "output.txt" $outputFileName = "output.txt"
$batchFileName = "sftp-batchcmds.txt" $batchFileName = "sftp-batchcmds.txt"
@ -23,24 +33,23 @@ Describe "SFTP Testcases" -Tags "Scenario" {
$null = New-Item $tempFilePath -ItemType file -Force -value "temp file data" $null = New-Item $tempFilePath -ItemType file -Force -value "temp file data"
$null = New-Item $tempUnicodeFilePath -ItemType file -Force -value "temp file data" $null = New-Item $tempUnicodeFilePath -ItemType file -Force -value "temp file data"
$expectedOutputDelimiter = "#DL$" $server = $OpenSSHTestInfo["Target"]
$port = $OpenSSHTestInfo["Port"]
[Machine] $client = [Machine]::new([MachineRole]::Client) $ssouser = $OpenSSHTestInfo["SSOUser"]
[Machine] $server = [Machine]::new([MachineRole]::Server) $script:testId = 1
$testData1 = @( $testData1 = @(
@{ @{
title = "put, ls for non-unicode file names" title = "put, ls for non-unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "put $tempFilePath $serverDirectory commands = "put $tempFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
expectedoutput = (join-path $serverdirectory $tempFileName) expectedoutput = (join-path $serverdirectory $tempFileName)
}, },
@{ @{
title = "get, ls for non-unicode file names" title = "get, ls for non-unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "get $tempFilePath $clientDirectory commands = "get $tempFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -48,7 +57,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "mput, ls for non-unicode file names" title = "mput, ls for non-unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mput $tempFilePath $serverDirectory commands = "mput $tempFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -56,7 +65,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "mget, ls for non-unicode file names" title = "mget, ls for non-unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mget $tempFilePath $clientDirectory commands = "mget $tempFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -64,7 +73,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "mkdir, cd, pwd for non-unicode directory names" title = "mkdir, cd, pwd for non-unicode directory names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "cd $serverdirectory commands = "cd $serverdirectory
mkdir server_test_dir mkdir server_test_dir
@ -74,7 +83,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
Title = "lmkdir, lcd, lpwd for non-unicode directory names" Title = "lmkdir, lcd, lpwd for non-unicode directory names"
LogonStr = "$($server.ssouser)@$($server.MachineName)" LogonStr = "$($ssouser)@$($server)"
Options = '' Options = ''
Commands = "lcd $clientDirectory Commands = "lcd $clientDirectory
lmkdir client_test_dir lmkdir client_test_dir
@ -84,7 +93,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "put, ls for unicode file names" title = "put, ls for unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "put $tempUnicodeFilePath $serverDirectory commands = "put $tempUnicodeFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -92,7 +101,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "get, ls for unicode file names" title = "get, ls for unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "get $tempUnicodeFilePath $clientDirectory commands = "get $tempUnicodeFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -100,7 +109,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "mput, ls for unicode file names" title = "mput, ls for unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mput $tempUnicodeFilePath $serverDirectory commands = "mput $tempUnicodeFilePath $serverDirectory
ls $serverDirectory" ls $serverDirectory"
@ -108,7 +117,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "mget, ls for unicode file names" title = "mget, ls for unicode file names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "mget $tempUnicodeFilePath $clientDirectory commands = "mget $tempUnicodeFilePath $clientDirectory
ls $clientDirectory" ls $clientDirectory"
@ -116,7 +125,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "mkdir, cd, pwd for unicode directory names" title = "mkdir, cd, pwd for unicode directory names"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '' options = ''
commands = "cd $serverdirectory commands = "cd $serverdirectory
mkdir server_test_dir_язык mkdir server_test_dir_язык
@ -126,7 +135,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
Title = "lmkdir, lcd, lpwd for unicode directory names" Title = "lmkdir, lcd, lpwd for unicode directory names"
LogonStr = "$($server.ssouser)@$($server.MachineName)" LogonStr = "$($ssouser)@$($server)"
Options = '' Options = ''
Commands = "lcd $clientDirectory Commands = "lcd $clientDirectory
lmkdir client_test_dir_язык lmkdir client_test_dir_язык
@ -140,8 +149,8 @@ Describe "SFTP Testcases" -Tags "Scenario" {
$testData2 = @( $testData2 = @(
@{ @{
title = "rm, rmdir, rename for unicode file, directory" title = "rm, rmdir, rename for unicode file, directory"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = 'b $batchFilePath' options = '-b $batchFilePath'
tmpFileName1 = $tempUnicodeFileName tmpFileName1 = $tempUnicodeFileName
tmpFilePath1 = $tempUnicodeFilePath tmpFilePath1 = $tempUnicodeFilePath
@ -155,7 +164,7 @@ Describe "SFTP Testcases" -Tags "Scenario" {
}, },
@{ @{
title = "rm, rmdir, rename for non-unicode file, directory" title = "rm, rmdir, rename for non-unicode file, directory"
logonstr = "$($server.ssouser)@$($server.machinename)" logonstr = "$($ssouser)@$($server)"
options = '-b $batchFilePath' options = '-b $batchFilePath'
tmpFileName1 = $tempFileName tmpFileName1 = $tempFileName
@ -169,17 +178,38 @@ Describe "SFTP Testcases" -Tags "Scenario" {
tmpDirectoryPath2 = (join-path $serverDirectory "test_dir_2") tmpDirectoryPath2 = (join-path $serverDirectory "test_dir_2")
} }
) )
# for the first time, delete the existing log files.
if ($OpenSSHTestInfo['DebugMode'])
{
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sftp-server.log" -Force -ErrorAction ignore
}
function CopyDebugLogs {
if($OpenSSHTestInfo["DebugMode"])
{
Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent_$script:testId.log" -Force
Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd_$script:testId.log" -Force
Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sftp-server.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sftp-server_$script:testId.log" -Force
$script:testId++
# clear the ssh-agent, sshd logs so that next testcase will get fresh logs.
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore
Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sftp-server.log" -Force -ErrorAction ignore
}
}
} }
AfterAll { AfterAll {
} if(!$OpenSSHTestInfo["DebugMode"])
{
Context "SFTP Test Cases" {
BeforeAll {
}
AfterAll {
Get-Item $rootDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue Get-Item $rootDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
} }
}
BeforeEach { BeforeEach {
Get-ChildItem $serverDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue Get-ChildItem $serverDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
@ -188,30 +218,31 @@ Describe "SFTP Testcases" -Tags "Scenario" {
Remove-Item $outputFilePath Remove-Item $outputFilePath
} }
AfterEach {
CopyDebugLogs
}
It '<Title>' -TestCases:$testData1 { It '<Title>' -TestCases:$testData1 {
param([string]$Title, $LogonStr, $Options, $Commands, $ExpectedOutput, $SkipVerification = $false) param([string]$Title, $LogonStr, $Options, $Commands, $ExpectedOutput)
Set-Content $batchFilePath -Encoding UTF8 -value $Commands Set-Content $batchFilePath -Encoding UTF8 -value $Commands
Write-Host "sftp -P 47002 $($Options) -b $batchFilePath $($LogonStr) > $outputFilePath" $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) -b $batchFilePath $($LogonStr) > $outputFilePath")
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P 47002 $($Options) -b $batchFilePath $($LogonStr) > $outputFilePath") iex $str
$client.RunCmd($str)
#validate file content. #validate file content.
$($ExpectedOutput).split($expectedOutputDelimiter) | foreach { Test-Path $ExpectedOutput | Should be $true
Test-Path ($_) | Should be $true
}
} }
It '<Title>' -TestCases:$testData2 { It '<Title>' -TestCases:$testData2 {
param([string]$Title, $LogonStr, $Options, $tmpFileName1, $tmpFilePath1, $tmpFileName2, $tmpFilePath2, $tmpDirectoryName1, $tmpDirectoryPath1, $tmpDirectoryName2, $tmpDirectoryPath2, $SkipVerification = $false) param([string]$Title, $LogonStr, $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 47002 $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath")
$client.RunCmd($str) iex $str
Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $true Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $true
$commands = "rm $tmpDirectoryPath1\* $commands = "rm $tmpDirectoryPath1\*
@ -219,8 +250,8 @@ Describe "SFTP Testcases" -Tags "Scenario" {
pwd pwd
" "
Set-Content $batchFilePath -Encoding UTF8 -value $commands Set-Content $batchFilePath -Encoding UTF8 -value $commands
$str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P 47002 $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath")
$client.RunCmd($str) iex $str
Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $false Test-Path (join-path $tmpDirectoryPath1 $tmpFileName1) | Should be $false
#rename file #rename file
@ -230,8 +261,8 @@ Describe "SFTP Testcases" -Tags "Scenario" {
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 47002 $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath")
$client.RunCmd($str) iex $str
Test-Path (join-path $tmpDirectoryPath1 $tmpFileName2) | Should be $true Test-Path (join-path $tmpDirectoryPath1 $tmpFileName2) | Should be $true
#rename directory #rename directory
@ -240,8 +271,8 @@ Describe "SFTP Testcases" -Tags "Scenario" {
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 47002 $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath")
$client.RunCmd($str) iex $str
Test-Path $tmpDirectoryPath2 | Should be $true Test-Path $tmpDirectoryPath2 | Should be $true
#rmdir (remove directory) #rmdir (remove directory)
@ -249,9 +280,8 @@ Describe "SFTP Testcases" -Tags "Scenario" {
$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 47002 $($Options) $($LogonStr) > $outputFilePath") $str = $ExecutionContext.InvokeCommand.ExpandString("sftp -P $port $($Options) $($LogonStr) > $outputFilePath")
$client.RunCmd($str) iex $str
Test-Path $tmpDirectoryPath2 | Should be $false Test-Path $tmpDirectoryPath2 | Should be $false
} }
}
} }

View File

@ -113,7 +113,7 @@ AuthorizedKeysFile .ssh/authorized_keys
#Banner none #Banner none
# override default of no subsystems # override default of no subsystems
Subsystem sftp sftp-server.exe Subsystem sftp sftp-server.exe -l DEBUG3
# Example of overriding settings on a per-user basis # Example of overriding settings on a per-user basis
#Match User anoncvs #Match User anoncvs