Skip to content

Commit e1432f0

Browse files
authored
Fix CI Failures caused by moving from WindowsPowerShell to PowerShell 7
Fix CI Failures
2 parents d9a9b3c + 127afa0 commit e1432f0

12 files changed

+46
-96
lines changed

regress/pesterTests/Authorized_keys_fileperm.Tests.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ Describe "Tests for authorized_keys file permission" -Tags "CI" {
3232
#skip when the task schedular (*-ScheduledTask) cmdlets does not exist
3333
$ts = (get-command get-ScheduledTask -ErrorAction SilentlyContinue)
3434
$skip = $ts -eq $null
35-
$platform = Get-Platform
36-
if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6))
35+
if($IsWindows -and ([Environment]::OSVersion.Version.Major -le 6))
3736
{
3837
#suppress the firewall blocking dialogue on win7
3938
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" {
4342
AfterEach { $tI++ }
4443

4544
AfterAll {
46-
$platform = Get-Platform
47-
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
45+
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
4846
{
4947
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
5048
}

regress/pesterTests/CommonUtils.psm1

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,6 @@ Add-Type -TypeDefinition @"
99
}
1010
"@
1111

12-
function Get-Platform {
13-
# Use the .NET Core APIs to determine the current platform; if a runtime
14-
# exception is thrown, we are on FullCLR, not .NET Core.
15-
try {
16-
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
17-
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
18-
19-
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
20-
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
21-
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
22-
} catch {
23-
try {
24-
$IsLinux = $false
25-
$IsOSX = $false
26-
$IsWindows = $true
27-
}
28-
catch { }
29-
}
30-
if($IsOSX) {
31-
[PlatformType]::OSX
32-
} elseif($IsLinux) {
33-
[PlatformType]::Linux
34-
} else {
35-
[PlatformType]::Windows
36-
}
37-
}
38-
3912
function Set-FilePermission
4013
{
4114
param(
@@ -94,8 +67,7 @@ function Set-FilePermission
9467
function Add-PasswordSetting
9568
{
9669
param([string] $pass)
97-
$platform = Get-Platform
98-
if ($platform -eq [PlatformType]::Windows) {
70+
if ($IsWindows) {
9971
if (-not($env:DISPLAY)) {$env:DISPLAY = 1}
10072
$askpass_util = Join-Path $PSScriptRoot "utilities\askpass_util\askpass_util.exe"
10173
$env:SSH_ASKPASS=$askpass_util
@@ -157,8 +129,8 @@ function Stop-SSHDTestDaemon
157129
{
158130
foreach ($ps in $p) {
159131
$pss =$ps.ToString() -split "\s+";
160-
$pid = $pss[$pss.length -1]
161-
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
132+
$processid = $pss[$pss.length -1]
133+
Stop-Process -Id $processid -Force -ErrorAction SilentlyContinue
162134
}
163135
#if still running, wait a little while for task to complete
164136
$num = 0

regress/pesterTests/FileBasedLogging.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Describe "Tests for admin and non-admin file based logs" -Tags "CI" {
4848
{
4949
Stop-SSHDTestDaemon -Port $port
5050
}
51-
if(($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6))
51+
if($IsWindows -and ([Environment]::OSVersion.Version.Major -le 6))
5252
{
5353
#suppress the firewall blocking dialogue on win7
5454
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" {
5858
AfterEach { $tI++ }
5959

6060
AfterAll {
61-
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
61+
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
6262
{
6363
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
6464
}
@@ -131,11 +131,11 @@ Describe "Tests for admin and non-admin file based logs" -Tags "CI" {
131131

132132
if($OpenSSHTestInfo["NoLibreSSL"])
133133
{
134-
ssh-keygen.exe -t ed25519 -f $KeyFilePath -Z -P `"`" aes128-ctr
134+
ssh-keygen.exe -t ed25519 -f $KeyFilePath -Z -P "" aes128-ctr
135135
}
136136
else
137137
{
138-
ssh-keygen.exe -t ed25519 -f $KeyFilePath -P `"`"
138+
ssh-keygen.exe -t ed25519 -f $KeyFilePath -P ""
139139
}
140140
Copy-Item "$keyFilePath.pub" $authorizedkeyPath -Force -ErrorAction SilentlyContinue
141141
Repair-AuthorizedKeyPermission -Filepath $authorizedkeyPath -confirm:$false

regress/pesterTests/Hostkey_fileperm.Tests.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ Describe "Tests for host keys file permission" -Tags "CI" {
2121
$ssouser = $OpenSSHTestInfo["SSOUser"]
2222
$script:logNum = 0
2323
Remove-Item -Path (Join-Path $testDir "*$logName") -Force -ErrorAction SilentlyContinue
24-
$platform = Get-Platform
25-
$skip = ($platform -eq [PlatformType]::Windows) -and ([Environment]::OSVersion.Version.Major -le 6) -and ([Environment]::OSVersion.Version.Minor -lt 2)
26-
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
24+
$skip = $IsWindows -and ([Environment]::OSVersion.Version.Major -le 6) -and ([Environment]::OSVersion.Version.Minor -lt 2)
25+
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
2726
{
2827
#suppress the firewall blocking dialogue on win7
2928
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" {
3231

3332
AfterEach { $tI++ }
3433
AfterAll {
35-
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
34+
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
3635
{
3736
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
3837
}

regress/pesterTests/Log_fileperm.Tests.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Describe "Tests for log file permission" -Tags "CI" {
2525

2626
Remove-Item (Join-Path $testDir "*$logName") -Force -ErrorAction SilentlyContinue
2727

28-
$platform = Get-Platform
29-
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
28+
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
3029
{
3130
#suppress the firewall blocking dialogue on win7
3231
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" {
8483

8584
AfterEach {$tI++;}
8685
AfterAll {
87-
if(($platform -eq [PlatformType]::Windows) -and ($psversiontable.BuildVersion.Major -le 6))
86+
if($IsWindows -and ($psversiontable.BuildVersion.Major -le 6))
8887
{
8988
netsh advfirewall firewall delete rule name="sshd" program="$($OpenSSHTestInfo['OpenSSHBinPath'])\sshd.exe" protocol=any dir=in
9089
}

regress/pesterTests/PlatformAbstractLayer.psm1

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,11 @@ Enum PlatformType {
1919
function Set-Platform {
2020
# Use the .NET Core APIs to determine the current platform; if a runtime
2121
# exception is thrown, we are on FullCLR, not .NET Core.
22-
try {
23-
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
24-
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
25-
26-
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
27-
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
28-
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
29-
} catch {
30-
try {
31-
$IsLinux = $false
32-
$IsOSX = $false
33-
$IsWindows = $true
34-
}
35-
catch { }
36-
}
37-
if($IsOSX) {
22+
if($IsMacOS) {
3823
[PlatformType]::OSX
3924
} elseif($IsLinux) {
4025
[PlatformType]::Linux
41-
} else {
26+
} elseif($IsWindows) {
4227
[PlatformType]::Windows
4328
}
4429
}

regress/pesterTests/PortForwarding.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ Describe "E2E scenarios for port forwarding" -Tags "CI" {
1515
{
1616
$null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue
1717
}
18-
$platform = Get-Platform
1918
#skip on ps 2 becase non-interactive cmd require a ENTER before it returns on ps2
20-
$skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2)
19+
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
2120
}
2221

2322
BeforeEach {

regress/pesterTests/SCP.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Describe "Tests for scp command" -Tags "CI" {
206206
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
207207
$equal | Should Be $true
208208

209-
if($Options.contains("-p ") -and ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -gt 2))
209+
if($Options.contains("-p ") -and $IsWindows -and ($PSVersionTable.PSVersion.Major -gt 2))
210210
{
211211
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir).LastWriteTime.DateTime (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ).LastWriteTime.DateTime).Length -eq 0
212212
$equal | Should Be $true

regress/pesterTests/SFTP.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ Describe "SFTP Test Cases" -Tags "CI" {
3636
Remove-item (Join-Path $rootDirectory "*.$batchFileName") -Force -ErrorAction SilentlyContinue
3737
Remove-item (Join-Path $rootDirectory "*.log") -Force -ErrorAction SilentlyContinue
3838

39-
$platform = Get-Platform
40-
$skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2)
39+
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
4140

4241
$testData1 = @(
4342
@{

regress/pesterTests/SSH.Tests.ps1

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
2727
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($ssouser, $rights, "ContainerInherit,Objectinherit", "None", "Allow")
2828
$acl.SetAccessRule($accessRule)
2929
Set-Acl -Path $testDir -AclObject $acl
30-
$platform = Get-Platform
3130
#skip on ps 2 becase non-interactive cmd require a ENTER before it returns on ps2
32-
$skip = ($platform -eq [PlatformType]::Windows) -and ($PSVersionTable.PSVersion.Major -le 2)
31+
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
3332

3433
<#$testData = @(
3534
@{
@@ -153,8 +152,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
153152
}
154153

155154
It "$tC.$tI - multiple double quotes in cmdline" {
156-
# actual command line ssh target \"cmd\" /c \"echo hello\"
157-
$o = ssh test_target `\`"cmd`\`" /c `\`"echo hello`\`"
155+
# actual command line ssh target "cmd" /c "echo hello"
156+
$o = ssh test_target `"cmd`" /c `"echo hello`"
158157
$o | Should Be "hello"
159158
}
160159

@@ -220,19 +219,19 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
220219
}
221220
It "$tC.$tI - powershell as default shell and double quotes in cmdline" {
222221
# actual command line ssh target echo `"hello`"
223-
$o = ssh test_target echo ``\`"hello``\`"
224-
$o | Should Be "`"hello`""
222+
$o = ssh test_target echo `"hello`"
223+
$o | Should Be "hello"
225224
}
226225
It "$tC.$tI - multiple commands with double quotes in powershell cmdlet" -skip:$skip {
227-
# actual command line ssh target cd "$env:programfiles";pwd
228-
$o = ssh test_target "cd \`"`$env:programfiles\`";pwd"
226+
# actual command line ssh target cd "$env:programfiles\";pwd
227+
$o = ssh test_target "cd `"`$env:programfiles\`";pwd"
229228
$LASTEXITCODE | Should Be 0
230229
$match = $o -match "Program Files"
231230
$match.count | Should be 1
232231
}
233232
It "$tC.$tI - multiple commands with double quotes in powershell cmdlet" -skip:$skip {
234-
# actual command line ssh target dir "$env:programfiles";cd "$env:programfiles";pwd
235-
$o = ssh test_target "dir \`"`$env:programfiles\`";cd \`"`$env:programfiles\`";pwd"
233+
# actual command line ssh target dir "$env:programfiles\";cd "$env:programfiles\";pwd
234+
$o = ssh test_target "dir `"`$env:programfiles\`";cd `"`$env:programfiles\`";pwd"
236235
$LASTEXITCODE | Should Be 0
237236
#$o -contains "Program Files" | Should Be $True
238237
$match = $o -match "Program Files"
@@ -263,8 +262,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
263262
$o | Should Contain "cmd"
264263
}
265264
It "$tC.$tI - cmd as default shell and double quotes in cmdline" {
266-
# actual command line ssh target echo "\"hello\""
267-
$o = ssh test_target 'echo "\"hello\""'
265+
# actual command line ssh target echo "hello"
266+
$o = ssh test_target echo "`"hello`""
268267
$o | Should Be "`"hello`""
269268
}
270269
It "$tC.$tI - single quotes in powershell cmdlet" -skip:$skip {
@@ -286,8 +285,8 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
286285
Remove-ItemProperty -Path $dfltShellRegPath -Name $dfltShellCmdOptionRegKeyName -ErrorAction SilentlyContinue
287286
}
288287
It "$tC.$tI - shellhost as default shell and multiple double quotes in cmdline" {
289-
# actual command line ssh target \"cmd\" /c \"echo \"hello\"\"
290-
$o = ssh test_target `\`"cmd`\`" /c `\`"echo \`"hello\`"`\`"
288+
# actual command line ssh target "cmd" /c "echo "hello""
289+
$o = ssh test_target `"cmd`" /c `"echo `"hello`"`"
291290
$o | Should Be "`"hello`""
292291
}
293292
}

0 commit comments

Comments
 (0)