diff --git a/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 b/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 index f129d3516..098957bf0 100644 --- a/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 +++ b/regress/pesterTests/Authorized_keys_fileperm.Tests.ps1 @@ -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 } diff --git a/regress/pesterTests/CommonUtils.psm1 b/regress/pesterTests/CommonUtils.psm1 index eff6779d3..109dc5543 100644 --- a/regress/pesterTests/CommonUtils.psm1 +++ b/regress/pesterTests/CommonUtils.psm1 @@ -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 diff --git a/regress/pesterTests/FileBasedLogging.tests.ps1 b/regress/pesterTests/FileBasedLogging.tests.ps1 index dd065af07..a78254a58 100644 --- a/regress/pesterTests/FileBasedLogging.tests.ps1 +++ b/regress/pesterTests/FileBasedLogging.tests.ps1 @@ -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 diff --git a/regress/pesterTests/Hostkey_fileperm.Tests.ps1 b/regress/pesterTests/Hostkey_fileperm.Tests.ps1 index eb0e9fb34..a6408829e 100644 --- a/regress/pesterTests/Hostkey_fileperm.Tests.ps1 +++ b/regress/pesterTests/Hostkey_fileperm.Tests.ps1 @@ -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 } diff --git a/regress/pesterTests/Log_fileperm.Tests.ps1 b/regress/pesterTests/Log_fileperm.Tests.ps1 index 2edce87fa..1c00f200a 100644 --- a/regress/pesterTests/Log_fileperm.Tests.ps1 +++ b/regress/pesterTests/Log_fileperm.Tests.ps1 @@ -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 } diff --git a/regress/pesterTests/PlatformAbstractLayer.psm1 b/regress/pesterTests/PlatformAbstractLayer.psm1 index a340d1653..9d59bfa15 100644 --- a/regress/pesterTests/PlatformAbstractLayer.psm1 +++ b/regress/pesterTests/PlatformAbstractLayer.psm1 @@ -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 } } diff --git a/regress/pesterTests/PortForwarding.Tests.ps1 b/regress/pesterTests/PortForwarding.Tests.ps1 index 68f38d2f2..0fe4b5269 100644 --- a/regress/pesterTests/PortForwarding.Tests.ps1 +++ b/regress/pesterTests/PortForwarding.Tests.ps1 @@ -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 { diff --git a/regress/pesterTests/SCP.Tests.ps1 b/regress/pesterTests/SCP.Tests.ps1 index 54623c5a1..3648ac73d 100644 --- a/regress/pesterTests/SCP.Tests.ps1 +++ b/regress/pesterTests/SCP.Tests.ps1 @@ -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 diff --git a/regress/pesterTests/SFTP.Tests.ps1 b/regress/pesterTests/SFTP.Tests.ps1 index 8d8957e7b..a0a35f380 100644 --- a/regress/pesterTests/SFTP.Tests.ps1 +++ b/regress/pesterTests/SFTP.Tests.ps1 @@ -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 = @( @{ diff --git a/regress/pesterTests/SSH.Tests.ps1 b/regress/pesterTests/SSH.Tests.ps1 index 618a925b2..015727134 100644 --- a/regress/pesterTests/SSH.Tests.ps1 +++ b/regress/pesterTests/SSH.Tests.ps1 @@ -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`"" } } diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index be1e2542f..47a825959 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -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 } diff --git a/regress/pesterTests/ShellHost.Tests.ps1 b/regress/pesterTests/ShellHost.Tests.ps1 index a85edf22f..8a68cacbc 100644 --- a/regress/pesterTests/ShellHost.Tests.ps1 +++ b/regress/pesterTests/ShellHost.Tests.ps1 @@ -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" }