Fix CI Failures caused by moving from WindowsPowerShell to PowerShell 7
Fix CI Failures
This commit is contained in:
commit
e1432f00dd
|
@ -32,8 +32,7 @@ Describe "Tests for authorized_keys file permission" -Tags "CI" {
|
|||
#skip when the task schedular (*-ScheduledTask) cmdlets does not exist
|
||||
$ts = (get-command get-ScheduledTask -ErrorAction SilentlyContinue)
|
||||
$skip = $ts -eq $null
|
||||
$platform = Get-Platform
|
||||
if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6))
|
||||
if($IsWindows -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
|
||||
|
@ -43,8 +42,7 @@ Describe "Tests for authorized_keys file permission" -Tags "CI" {
|
|||
AfterEach { $tI++ }
|
||||
|
||||
AfterAll {
|
||||
$platform = Get-Platform
|
||||
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
{
|
||||
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
|
||||
}
|
||||
|
|
|
@ -9,33 +9,6 @@ Add-Type -TypeDefinition @"
|
|||
}
|
||||
"@
|
||||
|
||||
function Get-Platform {
|
||||
# Use the .NET Core APIs to determine the current platform; if a runtime
|
||||
# exception is thrown, we are on FullCLR, not .NET Core.
|
||||
try {
|
||||
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
|
||||
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
|
||||
|
||||
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
|
||||
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
|
||||
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
|
||||
} catch {
|
||||
try {
|
||||
$IsLinux = $false
|
||||
$IsOSX = $false
|
||||
$IsWindows = $true
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if($IsOSX) {
|
||||
[PlatformType]::OSX
|
||||
} elseif($IsLinux) {
|
||||
[PlatformType]::Linux
|
||||
} else {
|
||||
[PlatformType]::Windows
|
||||
}
|
||||
}
|
||||
|
||||
function Set-FilePermission
|
||||
{
|
||||
param(
|
||||
|
@ -94,8 +67,7 @@ function Set-FilePermission
|
|||
function Add-PasswordSetting
|
||||
{
|
||||
param([string] $pass)
|
||||
$platform = Get-Platform
|
||||
if ($platform -eq [PlatformType]::Windows) {
|
||||
if ($IsWindows) {
|
||||
if (-not($env:DISPLAY)) {$env:DISPLAY = 1}
|
||||
$askpass_util = Join-Path $PSScriptRoot "utilities\askpass_util\askpass_util.exe"
|
||||
$env:SSH_ASKPASS=$askpass_util
|
||||
|
@ -157,8 +129,8 @@ function Stop-SSHDTestDaemon
|
|||
{
|
||||
foreach ($ps in $p) {
|
||||
$pss =$ps.ToString() -split "\s+";
|
||||
$pid = $pss[$pss.length -1]
|
||||
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
|
||||
$processid = $pss[$pss.length -1]
|
||||
Stop-Process -Id $processid -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
#if still running, wait a little while for task to complete
|
||||
$num = 0
|
||||
|
|
|
@ -48,7 +48,7 @@ Describe "Tests for admin and non-admin file based logs" -Tags "CI" {
|
|||
{
|
||||
Stop-SSHDTestDaemon -Port $port
|
||||
}
|
||||
if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6))
|
||||
if($IsWindows -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
|
||||
|
@ -58,7 +58,7 @@ Describe "Tests for admin and non-admin file based logs" -Tags "CI" {
|
|||
AfterEach { $tI++ }
|
||||
|
||||
AfterAll {
|
||||
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
{
|
||||
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
|
||||
}
|
||||
|
@ -131,11 +131,11 @@ Describe "Tests for admin and non-admin file based logs" -Tags "CI" {
|
|||
|
||||
if($OpenSSHTestInfo["NoLibreSSL"])
|
||||
{
|
||||
ssh-keygen.exe -t ed25519 -f $KeyFilePath -Z -P `"`" aes128-ctr
|
||||
ssh-keygen.exe -t ed25519 -f $KeyFilePath -Z -P "" aes128-ctr
|
||||
}
|
||||
else
|
||||
{
|
||||
ssh-keygen.exe -t ed25519 -f $KeyFilePath -P `"`"
|
||||
ssh-keygen.exe -t ed25519 -f $KeyFilePath -P ""
|
||||
}
|
||||
Copy-Item "$keyFilePath.pub" $authorizedkeyPath -Force -ErrorAction SilentlyContinue
|
||||
Repair-AuthorizedKeyPermission -Filepath $authorizedkeyPath -confirm:$false
|
||||
|
|
|
@ -21,9 +21,8 @@ Describe "Tests for host keys file permission" -Tags "CI" {
|
|||
$ssouser = $OpenSSHTestInfo["SSOUser"]
|
||||
$script:logNum = 0
|
||||
Remove-Item -Path (Join-Path $testDir "*$logName") -Force -ErrorAction SilentlyContinue
|
||||
$platform = Get-Platform
|
||||
$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))
|
||||
$skip = $IsWindows -and ([Environment]::OSVersion.Version.Major -le 6) -and ([Environment]::OSVersion.Version.Minor -lt 2)
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.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
|
||||
|
@ -32,7 +31,7 @@ Describe "Tests for host keys file permission" -Tags "CI" {
|
|||
|
||||
AfterEach { $tI++ }
|
||||
AfterAll {
|
||||
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
{
|
||||
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ Describe "Tests for log file permission" -Tags "CI" {
|
|||
|
||||
Remove-Item (Join-Path $testDir "*$logName") -Force -ErrorAction SilentlyContinue
|
||||
|
||||
$platform = Get-Platform
|
||||
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.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
|
||||
|
@ -84,7 +83,7 @@ Describe "Tests for log file permission" -Tags "CI" {
|
|||
|
||||
AfterEach {$tI++;}
|
||||
AfterAll {
|
||||
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
{
|
||||
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
|
||||
}
|
||||
|
|
|
@ -19,26 +19,11 @@ Enum PlatformType {
|
|||
function Set-Platform {
|
||||
# Use the .NET Core APIs to determine the current platform; if a runtime
|
||||
# exception is thrown, we are on FullCLR, not .NET Core.
|
||||
try {
|
||||
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
|
||||
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
|
||||
|
||||
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
|
||||
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
|
||||
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
|
||||
} catch {
|
||||
try {
|
||||
$IsLinux = $false
|
||||
$IsOSX = $false
|
||||
$IsWindows = $true
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if($IsOSX) {
|
||||
if($IsMacOS) {
|
||||
[PlatformType]::OSX
|
||||
} elseif($IsLinux) {
|
||||
[PlatformType]::Linux
|
||||
} else {
|
||||
} elseif($IsWindows) {
|
||||
[PlatformType]::Windows
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,8 @@ 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)
|
||||
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
|
||||
}
|
||||
|
||||
BeforeEach {
|
||||
|
|
|
@ -206,7 +206,7 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
||||
$equal | Should Be $true
|
||||
|
||||
if($Options.contains("-p ") -and ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -gt 2))
|
||||
if($Options.contains("-p ") -and $IsWindows -and ($PSVersionTable.PSVersion.Major -gt 2))
|
||||
{
|
||||
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir).LastWriteTime.DateTime (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ).LastWriteTime.DateTime).Length -eq 0
|
||||
$equal | Should Be $true
|
||||
|
|
|
@ -36,8 +36,7 @@ Describe "SFTP Test Cases" -Tags "CI" {
|
|||
Remove-item (Join-Path $rootDirectory "*.$batchFileName") -Force -ErrorAction SilentlyContinue
|
||||
Remove-item (Join-Path $rootDirectory "*.log") -Force -ErrorAction SilentlyContinue
|
||||
|
||||
$platform = Get-Platform
|
||||
$skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2)
|
||||
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
|
||||
|
||||
$testData1 = @(
|
||||
@{
|
||||
|
|
|
@ -27,9 +27,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
|
|||
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($ssouser, $rights, "ContainerInherit,Objectinherit", "None", "Allow")
|
||||
$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)
|
||||
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
|
||||
|
||||
<#$testData = @(
|
||||
@{
|
||||
|
@ -153,8 +152,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
|
|||
}
|
||||
|
||||
It "$tC.$tI - multiple double quotes in cmdline" {
|
||||
# actual command line ssh target \"cmd\" /c \"echo hello\"
|
||||
$o = ssh test_target `\`"cmd`\`" /c `\`"echo hello`\`"
|
||||
# actual command line ssh target "cmd" /c "echo hello"
|
||||
$o = ssh test_target `"cmd`" /c `"echo hello`"
|
||||
$o | Should Be "hello"
|
||||
}
|
||||
|
||||
|
@ -220,19 +219,19 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
|
|||
}
|
||||
It "$tC.$tI - powershell as default shell and double quotes in cmdline" {
|
||||
# actual command line ssh target echo `"hello`"
|
||||
$o = ssh test_target echo ``\`"hello``\`"
|
||||
$o | Should Be "`"hello`""
|
||||
$o = ssh test_target echo `"hello`"
|
||||
$o | Should Be "hello"
|
||||
}
|
||||
It "$tC.$tI - multiple commands with double quotes in powershell cmdlet" -skip:$skip {
|
||||
# actual command line ssh target cd "$env:programfiles";pwd
|
||||
$o = ssh test_target "cd \`"`$env:programfiles\`";pwd"
|
||||
# actual command line ssh target cd "$env:programfiles\";pwd
|
||||
$o = ssh test_target "cd `"`$env:programfiles\`";pwd"
|
||||
$LASTEXITCODE | Should Be 0
|
||||
$match = $o -match "Program Files"
|
||||
$match.count | Should be 1
|
||||
}
|
||||
It "$tC.$tI - multiple commands with double quotes in powershell cmdlet" -skip:$skip {
|
||||
# actual command line ssh target dir "$env:programfiles";cd "$env:programfiles";pwd
|
||||
$o = ssh test_target "dir \`"`$env:programfiles\`";cd \`"`$env:programfiles\`";pwd"
|
||||
# actual command line ssh target dir "$env:programfiles\";cd "$env:programfiles\";pwd
|
||||
$o = ssh test_target "dir `"`$env:programfiles\`";cd `"`$env:programfiles\`";pwd"
|
||||
$LASTEXITCODE | Should Be 0
|
||||
#$o -contains "Program Files" | Should Be $True
|
||||
$match = $o -match "Program Files"
|
||||
|
@ -263,8 +262,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
|
|||
$o | Should Contain "cmd"
|
||||
}
|
||||
It "$tC.$tI - cmd as default shell and double quotes in cmdline" {
|
||||
# actual command line ssh target echo "\"hello\""
|
||||
$o = ssh test_target 'echo "\"hello\""'
|
||||
# actual command line ssh target echo "hello"
|
||||
$o = ssh test_target echo "`"hello`""
|
||||
$o | Should Be "`"hello`""
|
||||
}
|
||||
It "$tC.$tI - single quotes in powershell cmdlet" -skip:$skip {
|
||||
|
@ -286,8 +285,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
|
|||
Remove-ItemProperty -Path $dfltShellRegPath -Name $dfltShellCmdOptionRegKeyName -ErrorAction SilentlyContinue
|
||||
}
|
||||
It "$tC.$tI - shellhost as default shell and multiple double quotes in cmdline" {
|
||||
# actual command line ssh target \"cmd\" /c \"echo \"hello\"\"
|
||||
$o = ssh test_target `\`"cmd`\`" /c `\`"echo \`"hello\`"`\`"
|
||||
# actual command line ssh target "cmd" /c "echo "hello""
|
||||
$o = ssh test_target `"cmd`" /c `"echo `"hello`"`"
|
||||
$o | Should Be "`"hello`""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ Match User matchuser
|
|||
{
|
||||
Stop-SSHDTestDaemon -Port $port
|
||||
}
|
||||
if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6))
|
||||
if($IsWindows -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
|
||||
|
@ -153,7 +153,7 @@ Match User matchuser
|
|||
|
||||
AfterAll {
|
||||
$PrincipalContext.Dispose()
|
||||
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
|
||||
{
|
||||
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
|
||||
}
|
||||
|
|
|
@ -23,18 +23,18 @@ Describe "E2E scenarios for ssh-shellhost" -Tags "CI" {
|
|||
}
|
||||
|
||||
It "$tC.$tI - various quote tests" -skip:$skip {
|
||||
$o = ssh-shellhost -c cmd /c echo hello
|
||||
$o | Should Be "hello"
|
||||
$o = ssh-shellhost -c `"cmd /c echo hello`"
|
||||
$o | Should Be "hello"
|
||||
$o = ssh-shellhost -c cmd /c echo `"hello`"
|
||||
$o | Should Be "`"hello`""
|
||||
$o = ssh-shellhost -c `"cmd /c echo `"hello`"`"
|
||||
$o | Should Be "`"hello`""
|
||||
$o = ssh-shellhost -c `"cmd /c echo `"hello`"
|
||||
$o | Should Be "`"hello"
|
||||
$o = ssh-shellhost -c `"`"cmd`" /c echo `"hello`"`"
|
||||
$o | Should Be "`"hello`""
|
||||
$o = ssh-shellhost -c cmd /c echo hello
|
||||
$o | Should Be "hello"
|
||||
$o = ssh-shellhost -c "cmd /c echo hello"
|
||||
$o | Should Be "hello"
|
||||
$o = ssh-shellhost -c cmd /c echo "hello"
|
||||
$o | Should Be "hello"
|
||||
$o = ssh-shellhost -c "cmd /c echo `"hello`""
|
||||
$o | Should Be "`\`"hello`\`""
|
||||
$o = ssh-shellhost -c "cmd /c echo `"hello"
|
||||
$o | Should Be "`\`"hello"
|
||||
$o = ssh-shellhost -c "cmd" /c echo "hello"
|
||||
$o | Should Be "hello"
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue