diff --git a/contrib/win32/openssh/OpenSSHTestHelper.psm1 b/contrib/win32/openssh/OpenSSHTestHelper.psm1 index 752fcdfa7..27405582a 100644 --- a/contrib/win32/openssh/OpenSSHTestHelper.psm1 +++ b/contrib/win32/openssh/OpenSSHTestHelper.psm1 @@ -140,7 +140,12 @@ WARNING: Following changes will be made to OpenSSH configuration } Install-OpenSSHTestDependencies - + + if(-not (Test-path $TestDataPath -PathType Container)) + { + New-Item -ItemType Directory -Path $TestDataPath -Force -ErrorAction SilentlyContinue | out-null + } + #Backup existing OpenSSH configuration $backupConfigPath = Join-Path $script:OpenSSHBinPath sshd_config.ori if (-not (Test-Path $backupConfigPath -PathType Leaf)) { diff --git a/regress/pesterTests/README.md b/regress/pesterTests/README.md index f5bf7ff56..9d41eac7f 100644 --- a/regress/pesterTests/README.md +++ b/regress/pesterTests/README.md @@ -27,6 +27,14 @@ Run-OpenSSHUnitTest C:\git\openssh-portable\regress\pesterTests\SCP.Tests.ps1 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: ```powershell diff --git a/regress/pesterTests/SCP.Tests.ps1 b/regress/pesterTests/SCP.Tests.ps1 index d0defd9d7..30c78a24c 100644 --- a/regress/pesterTests/SCP.Tests.ps1 +++ b/regress/pesterTests/SCP.Tests.ps1 @@ -96,14 +96,11 @@ Describe "Tests for scp command" -Tags "CI" { } ) + # for the first time, delete the existing log files. if ($OpenSSHTestInfo['DebugMode']) { - Stop-Service ssh-agent -Force - Start-Sleep 2 - # 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 + Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\ssh-agent.log" -Force -ErrorAction ignore + Clear-Content "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" -Force -ErrorAction ignore } function CheckTarget { @@ -112,9 +109,14 @@ Describe "Tests for scp command" -Tags "CI" { { if( $OpenSSHTestInfo["DebugMode"]) { - Copy-Item "$($OpenSSHTestInfo['OpenSSHDir'])\logs\ssh-agent.log" "$($OpenSSHTestInfo['OpenSSHDir'])\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\ssh-agent.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\failedagent$script:logNum.log" -Force + Copy-Item "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\sshd.log" "$($OpenSSHTestInfo['OpenSSHBinPath'])\logs\failedsshd$script:logNum.log" -Force + $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 diff --git a/regress/pesterTests/SFTP.Tests.ps1 b/regress/pesterTests/SFTP.Tests.ps1 index 44a885d10..9f82e0ff9 100644 --- a/regress/pesterTests/SFTP.Tests.ps1 +++ b/regress/pesterTests/SFTP.Tests.ps1 @@ -1,46 +1,55 @@ -Describe "SFTP Testcases" -Tags "Scenario" { +Describe "SFTP Test Cases" -Tags "CI" { 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" $batchFileName = "sftp-batchcmds.txt" $outputFilePath = Join-Path $rootDirectory $outputFileName $batchFilePath = Join-Path $rootDirectory $batchFileName - + $tempFileName = "tempFile.txt" $tempFilePath = Join-Path $rootDirectory $tempFileName - + $tempUnicodeFileName = "tempFile_язык.txt" $tempUnicodeFilePath = Join-Path $rootDirectory $tempUnicodeFileName - + $clientDirectory = Join-Path $rootDirectory 'client_dir' $serverDirectory = Join-Path $rootDirectory 'server_dir' - + $null = New-Item $clientDirectory -ItemType directory -Force $null = New-Item $serverDirectory -ItemType directory -Force $null = New-Item $batchFilePath -ItemType file -Force $null = New-Item $outputFilePath -ItemType file -Force $null = New-Item $tempFilePath -ItemType file -Force -value "temp file data" $null = New-Item $tempUnicodeFilePath -ItemType file -Force -value "temp file data" - - $expectedOutputDelimiter = "#DL$" - - [Machine] $client = [Machine]::new([MachineRole]::Client) - [Machine] $server = [Machine]::new([MachineRole]::Server) - + + $server = $OpenSSHTestInfo["Target"] + $port = $OpenSSHTestInfo["Port"] + $ssouser = $OpenSSHTestInfo["SSOUser"] + $script:testId = 1 + $testData1 = @( @{ title = "put, ls for non-unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "put $tempFilePath $serverDirectory ls $serverDirectory" expectedoutput = (join-path $serverdirectory $tempFileName) - }, @{ title = "get, ls for non-unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "get $tempFilePath $clientDirectory ls $clientDirectory" @@ -48,7 +57,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "mput, ls for non-unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "mput $tempFilePath $serverDirectory ls $serverDirectory" @@ -56,7 +65,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "mget, ls for non-unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "mget $tempFilePath $clientDirectory ls $clientDirectory" @@ -64,7 +73,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "mkdir, cd, pwd for non-unicode directory names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "cd $serverdirectory mkdir server_test_dir @@ -74,7 +83,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ Title = "lmkdir, lcd, lpwd for non-unicode directory names" - LogonStr = "$($server.ssouser)@$($server.MachineName)" + LogonStr = "$($ssouser)@$($server)" Options = '' Commands = "lcd $clientDirectory lmkdir client_test_dir @@ -84,7 +93,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "put, ls for unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "put $tempUnicodeFilePath $serverDirectory ls $serverDirectory" @@ -92,7 +101,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "get, ls for unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "get $tempUnicodeFilePath $clientDirectory ls $clientDirectory" @@ -100,7 +109,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "mput, ls for unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "mput $tempUnicodeFilePath $serverDirectory ls $serverDirectory" @@ -108,7 +117,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "mget, ls for unicode file names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "mget $tempUnicodeFilePath $clientDirectory ls $clientDirectory" @@ -116,7 +125,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "mkdir, cd, pwd for unicode directory names" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '' commands = "cd $serverdirectory mkdir server_test_dir_язык @@ -126,7 +135,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ Title = "lmkdir, lcd, lpwd for unicode directory names" - LogonStr = "$($server.ssouser)@$($server.MachineName)" + LogonStr = "$($ssouser)@$($server)" Options = '' Commands = "lcd $clientDirectory lmkdir client_test_dir_язык @@ -140,8 +149,8 @@ Describe "SFTP Testcases" -Tags "Scenario" { $testData2 = @( @{ title = "rm, rmdir, rename for unicode file, directory" - logonstr = "$($server.ssouser)@$($server.machinename)" - options = 'b $batchFilePath' + logonstr = "$($ssouser)@$($server)" + options = '-b $batchFilePath' tmpFileName1 = $tempUnicodeFileName tmpFilePath1 = $tempUnicodeFilePath @@ -155,7 +164,7 @@ Describe "SFTP Testcases" -Tags "Scenario" { }, @{ title = "rm, rmdir, rename for non-unicode file, directory" - logonstr = "$($server.ssouser)@$($server.machinename)" + logonstr = "$($ssouser)@$($server)" options = '-b $batchFilePath' tmpFileName1 = $tempFileName @@ -169,89 +178,110 @@ Describe "SFTP Testcases" -Tags "Scenario" { 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 { - } - - Context "SFTP Test Cases" { - BeforeAll { - } - AfterAll { + if(!$OpenSSHTestInfo["DebugMode"]) + { Get-Item $rootDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue } + } - BeforeEach { - Get-ChildItem $serverDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue - Get-ChildItem $clientDirectory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue - Remove-Item $batchFilePath - Remove-Item $outputFilePath - } - - It '