From 50a4badb798e051e93ac3c965b9ca39b1eb4bd21 Mon Sep 17 00:00:00 2001 From: Yanbing Date: Thu, 1 Mar 2018 15:11:55 -0800 Subject: [PATCH] Test Fixes on down level OS (#279) * Test Fixes on downlevel machines 1. Test fix to run on win7 and win8 2. Add -onecore parameter to start-opensshpackage in build helper script 3. Add copying of libcrypto.dll and libcrypto.pdb 4. Update the build number on appveyor.yml --- appveyor.yml | 7 ++++--- contrib/win32/openssh/OpenSSHBuildHelper.psm1 | 16 +++++++++++++--- .../Authorized_keys_fileperm.Tests.ps1 | 8 +++++--- regress/pesterTests/CertAuth.Tests.ps1 | 6 +----- regress/pesterTests/Hostkey_fileperm.Tests.ps1 | 9 +++++---- regress/pesterTests/PortForwarding.Tests.ps1 | 1 + regress/pesterTests/SSH.Tests.ps1 | 9 +++++---- regress/pesterTests/SSHDConfig.tests.ps1 | 8 +++++--- 8 files changed, 39 insertions(+), 25 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index cccd93f97..f6058d84d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.0.0.0.{build} +version: 7.6.0.0.{build} image: Visual Studio 2015 branches: @@ -6,7 +6,8 @@ branches: - latestw_all init: - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + - ps: | + [Environment]::OSVersion | fl * build_script: - ps: | @@ -34,6 +35,6 @@ after_test: Publish-OpenSSHTestResults on_finish: - - ps: | + - ps: | Import-Module $env:APPVEYOR_BUILD_FOLDER\contrib\win32\openssh\AppveyorHelper.psm1 Publish-Artifact \ No newline at end of file diff --git a/contrib/win32/openssh/OpenSSHBuildHelper.psm1 b/contrib/win32/openssh/OpenSSHBuildHelper.psm1 index 4c00e0065..d1204ac8f 100644 --- a/contrib/win32/openssh/OpenSSHBuildHelper.psm1 +++ b/contrib/win32/openssh/OpenSSHBuildHelper.psm1 @@ -344,7 +344,8 @@ function Start-OpenSSHPackage # Copy payload to DestinationPath instead of packaging [string]$DestinationPath = "", - [switch]$NoOpenSSL + [switch]$NoOpenSSL, + [switch]$OneCore ) [System.IO.DirectoryInfo] $repositoryRoot = Get-RepositoryRoot @@ -406,7 +407,16 @@ function Start-OpenSSHPackage $libreSSLSDKPath = Join-Path $PSScriptRoot $script:libreSSLSDKStr if (-not $NoOpenSSL.IsPresent) { - Copy-Item -Path $(Join-Path $libreSSLSDKPath "$NativeHostArch\libcrypto.dll") -Destination $packageDir -Force -ErrorAction Stop + if($OneCore) + { + Copy-Item -Path $(Join-Path $libreSSLSDKPath "Onecore\$NativeHostArch\libcrypto.dll") -Destination $packageDir -Force -ErrorAction Stop + Copy-Item -Path $(Join-Path $libreSSLSDKPath "Onecore\$NativeHostArch\libcrypto.pdb") -Destination $symbolsDir -Force -ErrorAction Stop + } + else + { + Copy-Item -Path $(Join-Path $libreSSLSDKPath "$NativeHostArch\libcrypto.dll") -Destination $packageDir -Force -ErrorAction Stop + Copy-Item -Path $(Join-Path $libreSSLSDKPath "$NativeHostArch\libcrypto.pdb") -Destination $symbolsDir -Force -ErrorAction Stop + } } if ($DestinationPath -ne "") { @@ -446,7 +456,7 @@ function Start-OpenSSHPackage } else { - Write-BuildMsg -AsInfo -Message "Packaged Symbols not compressed." + Write-BuildMsg -AsInfo -Message "Packaged Symbols not compressed." } } Remove-Item $symbolsDir -Recurse -Force -ErrorAction SilentlyContinue diff --git a/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 b/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 index 07346981b..915b89f1c 100644 --- a/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 +++ b/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 @@ -26,9 +26,11 @@ Describe "Tests for authorized_keys file permission" -Tags "CI" { $ssouserProfile = $OpenSSHTestInfo["SSOUserProfile"] $opensshbinpath = $OpenSSHTestInfo['OpenSSHBinPath'] Remove-Item -Path (Join-Path $testDir "*$sshLogName") -Force -ErrorAction SilentlyContinue - $platform = Get-Platform - $skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2) - if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6)) + + #skip when the task schedular (*-ScheduledTask) cmdlets does not exist + $ts = (get-command get-ScheduledTask -ErrorAction SilentlyContinue) + $skip = $ts -eq $null + if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6)) { #suppress the firewall blocking dialogue on win7 netsh advfirewall firewall add rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any action=allow dir=in diff --git a/regress/pesterTests/CertAuth.Tests.ps1 b/regress/pesterTests/CertAuth.Tests.ps1 index d49663228..f075b5ffc 100644 --- a/regress/pesterTests/CertAuth.Tests.ps1 +++ b/regress/pesterTests/CertAuth.Tests.ps1 @@ -22,11 +22,7 @@ Describe "E2E scenarios for certificate authentication" -Tags "CI" { $null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue } $user_key = Join-Path $testDir "cert_auth_user_key" - $keypassphrase = "testpassword" - - $platform = Get-Platform - $skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2) - + $keypassphrase = "testpassword" } BeforeEach { diff --git a/regress/pesterTests/Hostkey_fileperm.Tests.ps1 b/regress/pesterTests/Hostkey_fileperm.Tests.ps1 index 0bb7bc421..2777517cc 100644 --- a/regress/pesterTests/Hostkey_fileperm.Tests.ps1 +++ b/regress/pesterTests/Hostkey_fileperm.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Tests for host keys file permission" -Tags "CI" { $script:logNum = 0 Remove-Item -Path (Join-Path $testDir "*$logName") -Force -ErrorAction SilentlyContinue $platform = Get-Platform - $skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2) + $skip = ($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6) -and ([Environment]::OSVersion.Version.Minor -lt 2) if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6)) { #suppress the firewall blocking dialogue on win7 @@ -77,12 +77,12 @@ Describe "Tests for host keys file permission" -Tags "CI" { $logPath = Join-Path $testDir "$tC.$tI.$logName" } - AfterAll { + AfterEach { if(Test-path $hostKeyFilePath -PathType Leaf) { Repair-SshdHostKeyPermission -filepath $hostKeyFilePath -confirm:$false - } - $tC++ + } } + AfterAll { $tC++ } It "$tC.$tI-Host keys-positive (both public and private keys are owned by admin groups and running process can access to public key file)" { Repair-FilePermission -Filepath $hostKeyFilePath -Owners $adminsSid -FullAccessNeeded $adminsSid,$systemSid -confirm:$false @@ -149,6 +149,7 @@ Describe "Tests for host keys file permission" -Tags "CI" { $logPath | Should Contain "key_load_private: bad permissions" } + #skip on win7 because Set-Acl failed due to issue on win7 when user does not have write permission on the file It "$tC.$tI-Host keys-negative (the running process does not have read access to public key)" -skip:$skip { #setup to have ssouser as owner and grant it full control Repair-FilePermission -Filepath $hostKeyFilePath -Owners $systemSid -FullAccessNeeded $systemSid,$adminsSid -confirm:$false diff --git a/regress/pesterTests/PortForwarding.Tests.ps1 b/regress/pesterTests/PortForwarding.Tests.ps1 index 609d6a9ff..68f38d2f2 100644 --- a/regress/pesterTests/PortForwarding.Tests.ps1 +++ b/regress/pesterTests/PortForwarding.Tests.ps1 @@ -16,6 +16,7 @@ Describe "E2E scenarios for port forwarding" -Tags "CI" { $null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue } $platform = Get-Platform + #skip on ps 2 becase non-interactive cmd require a ENTER before it returns on ps2 $skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2) } diff --git a/regress/pesterTests/SSH.Tests.ps1 b/regress/pesterTests/SSH.Tests.ps1 index df728dd51..81f764326 100644 --- a/regress/pesterTests/SSH.Tests.ps1 +++ b/regress/pesterTests/SSH.Tests.ps1 @@ -28,6 +28,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" { $acl.SetAccessRule($accessRule) Set-Acl -Path $testDir -AclObject $acl $platform = Get-Platform + #skip on ps 2 becase non-interactive cmd require a ENTER before it returns on ps2 $skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2) <#$testData = @( @@ -147,7 +148,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" { $o | Should Be "1234" } - It "$tC.$tI - stdin from PS object" { + It "$tC.$tI - stdin from PS object" -skip:$skip { # execute this script that dumps the length of input data, on the remote end $str = "begin {} process { Write-Output `$input.Length} end { }" $EncodedText =[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($str)) @@ -157,7 +158,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" { $o | Should Be "8" } - It "$tC.$tI - stream file in and out" { + It "$tC.$tI - stream file in and out" -skip:$skip { # prep a file of size > 10KB (https://github.com/PowerShell/Win32-OpenSSH/issues/908 was caught with such file size) $str = "" (1..100) | foreach {$str += "1234567890"} @@ -191,7 +192,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" { Remove-ItemProperty -Path $dfltShellRegPath -Name $dfltShellCmdOptionRegKeyName -ErrorAction SilentlyContinue } - It "$tC.$tI - default shell as powershell" { + It "$tC.$tI - default shell as powershell" -skip:$skip { $shell_path = (Get-Command powershell.exe -ErrorAction SilentlyContinue).path if($shell_path -ne $null) { ConfigureDefaultShell -default_shell_path $shell_path -default_shell_cmd_option_val "/c" @@ -201,7 +202,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" { } } - It "$tC.$tI - default shell as cmd" { + It "$tC.$tI - default shell as cmd" -skip:$skip { $shell_path = (Get-Command cmd.exe -ErrorAction SilentlyContinue).path if($shell_path -ne $null) { ConfigureDefaultShell -default_shell_path $shell_path -default_shell_cmd_option_val "/c" diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 3c02e5bd3..65d339f77 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -112,13 +112,15 @@ Describe "Tests of sshd_config" -Tags "CI" { } } } - $platform = Get-Platform - $skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2) + + #skip when the task schedular (*-ScheduledTask) cmdlets does not exist + $ts = (get-command get-ScheduledTask -ErrorAction SilentlyContinue) + $skip = $ts -eq $null if(-not $skip) { Stop-SSHDTestDaemon } - if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6)) + if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6)) { #suppress the firewall blocking dialogue on win7 netsh advfirewall firewall add rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any action=allow dir=in