From 3c90af89a2910636808797d0d415a7083ce7f455 Mon Sep 17 00:00:00 2001 From: Yanbing Date: Wed, 2 Aug 2017 17:16:06 -0700 Subject: [PATCH] Updates needed for running test on windows inbox (#189) Test updates needed for running test on windows inbox --- contrib/win32/openssh/OpenSSHTestHelper.psm1 | 17 +++++--- regress/pesterTests/KeyUtils.Tests.ps1 | 41 +++++++++++++++---- .../pesterTests/Userkey_fileperm.Tests.ps1 | 9 +++- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/contrib/win32/openssh/OpenSSHTestHelper.psm1 b/contrib/win32/openssh/OpenSSHTestHelper.psm1 index bd1a341f0..1d46420bb 100644 --- a/contrib/win32/openssh/OpenSSHTestHelper.psm1 +++ b/contrib/win32/openssh/OpenSSHTestHelper.psm1 @@ -313,12 +313,12 @@ function Install-OpenSSHUtilsModule } $modulePath = Join-Path -Path $env:ProgramFiles -ChildPath WindowsPowerShell\Modules - if(-not (Test-Path $targetDirectory -PathType Container)) + if(-not (Test-Path "$targetDirectory" -PathType Container)) { - New-Item -ItemType Directory -Path $targetDirectory -Force -ErrorAction SilentlyContinue | out-null + New-Item -ItemType Directory -Path "$targetDirectory" -Force -ErrorAction SilentlyContinue | out-null } - Copy-item $manifestFile -Destination $targetDirectory -Force -ErrorAction SilentlyContinue | out-null - Copy-item $moduleFile -Destination $targetDirectory -Force -ErrorAction SilentlyContinue | out-null + Copy-item "$manifestFile" -Destination "$targetDirectory" -Force -ErrorAction SilentlyContinue | out-null + Copy-item "$moduleFile" -Destination "$targetDirectory" -Force -ErrorAction SilentlyContinue | out-null if ($PSVersionTable.PSVersion.Major -lt 4) { @@ -506,13 +506,18 @@ function Get-UnitTestDirectory Run OpenSSH pester tests. #> function Invoke-OpenSSHE2ETest -{ +{ + [CmdletBinding()] + param + ( + [ValidateSet('CI', 'Scenario')] + [string]$pri = "CI") # Discover all CI tests and run them. Import-Module pester -force -global Push-Location $Script:E2ETestDirectory Write-Log -Message "Running OpenSSH E2E tests..." $testFolders = @(Get-ChildItem *.tests.ps1 -Recurse | ForEach-Object{ Split-Path $_.FullName} | Sort-Object -Unique) - Invoke-Pester $testFolders -OutputFormat NUnitXml -OutputFile $Script:E2ETestResultsFile -Tag 'CI' + Invoke-Pester $testFolders -OutputFormat NUnitXml -OutputFile $Script:E2ETestResultsFile -Tag $pri -PassThru Pop-Location } diff --git a/regress/pesterTests/KeyUtils.Tests.ps1 b/regress/pesterTests/KeyUtils.Tests.ps1 index d4f33e260..f51645f5b 100644 --- a/regress/pesterTests/KeyUtils.Tests.ps1 +++ b/regress/pesterTests/KeyUtils.Tests.ps1 @@ -18,7 +18,15 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" { } $keypassphrase = "testpassword" - $keytypes = @("rsa","dsa","ecdsa","ed25519") + $WindowsInBox = $OpenSSHTestInfo["WindowsInBox"] + if($WindowsInBox) + { + $keytypes = @("ed25519") + } + else + { + $keytypes = @("rsa","dsa","ecdsa","ed25519") + } $ssouser = $OpenSSHTestInfo["SSOUser"] @@ -117,8 +125,15 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" { foreach($type in $keytypes) { $keyPath = Join-Path $testDir "id_$type" - remove-item $keyPath -ErrorAction SilentlyContinue - ssh-keygen -t $type -P $keypassphrase -f $keyPath + remove-item $keyPath -ErrorAction SilentlyContinue + if($OpenSSHTestInfo["WindowsInBox"]) + { + ssh-keygen -t $type -P $keypassphrase -f $keyPath -Z aes128-ctr + } + else + { + ssh-keygen -t $type -P $keypassphrase -f $keyPath + } ValidateKeyFile -FilePath $keyPath ValidateKeyFile -FilePath "$keyPath.pub" } @@ -224,7 +239,15 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" { $keyFileName = "sshadd_userPermTestkey_ed25519" $keyFilePath = Join-Path $testDir $keyFileName Remove-Item -path "$keyFilePath*" -Force -ErrorAction SilentlyContinue - ssh-keygen.exe -t ed25519 -f $keyFilePath -P $keypassphrase + if($OpenSSHTestInfo["WindowsInBox"]) + { + ssh-keygen.exe -t ed25519 -f $keyFilePath -P $keypassphrase -Z aes128-ctr + } + else + { + ssh-keygen.exe -t ed25519 -f $keyFilePath -P $keypassphrase + } + #set up SSH_ASKPASS Add-PasswordSetting -Pass $keypassphrase $tI=1 @@ -331,7 +354,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" { } Context "$tC - ssh-keyscan test cases" { - BeforeAll { + BeforeAll { $tI=1 $port = $OpenSSHTestInfo["Port"] Remove-item (join-path $testDir "$tC.$tI.out.txt") -force -ErrorAction SilentlyContinue @@ -341,23 +364,23 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" { } AfterAll{$tC++} - It "$tC.$tI - ssh-keyscan with default arguments" { + It "$tC.$tI - ssh-keyscan with default arguments" -Skip:$WindowsInBox { cmd /c "ssh-keyscan -p $port 127.0.0.1 2>&1 > $outputFile" $outputFile | Should Contain '.*ssh-rsa.*' } - It "$tC.$tI - ssh-keyscan with -p" { + It "$tC.$tI - ssh-keyscan with -p" -Skip:$WindowsInBox { cmd /c "ssh-keyscan -p $port 127.0.0.1 2>&1 > $outputFile" $outputFile | Should Contain '.*ssh-rsa.*' } - It "$tC.$tI - ssh-keyscan with -f" { + It "$tC.$tI - ssh-keyscan with -f" -Skip:$WindowsInBox { Set-Content -Path tmp.txt -Value "127.0.0.1" cmd /c "ssh-keyscan -p $port -f tmp.txt 2>&1 > $outputFile" $outputFile | Should Contain '.*ssh-rsa.*' } - It "$tC.$tI - ssh-keyscan with -f -t" { + It "$tC.$tI - ssh-keyscan with -f -t" -Skip:$WindowsInBox { Set-Content -Path tmp.txt -Value "127.0.0.1" cmd /c "ssh-keyscan -p $port -f tmp.txt -t rsa,dsa 2>&1 > $outputFile" $outputFile | Should Contain '.*ssh-rsa.*' diff --git a/regress/pesterTests/Userkey_fileperm.Tests.ps1 b/regress/pesterTests/Userkey_fileperm.Tests.ps1 index 7e013b9cb..0ea561d2f 100644 --- a/regress/pesterTests/Userkey_fileperm.Tests.ps1 +++ b/regress/pesterTests/Userkey_fileperm.Tests.ps1 @@ -50,7 +50,14 @@ Describe "Tests for user Key file permission" -Tags "CI" { $keyFileName = "sshtest_userPermTestkey_ed25519" $keyFilePath = Join-Path $testDir $keyFileName Remove-Item -path "$keyFilePath*" -Force -ErrorAction SilentlyContinue - ssh-keygen.exe -t ed25519 -f $keyFilePath -P $keypassphrase + if($OpenSSHTestInfo["WindowsInBox"]) + { + ssh-keygen.exe -t ed25519 -f $keyFilePath -P $keypassphrase -Z aes128-ctr + } + else + { + ssh-keygen.exe -t ed25519 -f $keyFilePath -P $keypassphrase + } $pubKeyUserProfilePath = Join-Path $pubKeyUserProfile .ssh if(-not (Test-Path $pubKeyUserProfilePath -PathType Container)) {