Skip to content

Expand test suite #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: latestw_all
Choose a base branch
from
Open
80 changes: 41 additions & 39 deletions contrib/win32/openssh/AzDOBuildTools/AzDOBuildTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Invoke-AzDOBuild
function Install-OpenSSH
{
[CmdletBinding()]
param (
param (
[Parameter(Mandatory=$true)]
[string]$SourceDir,

Expand All @@ -62,7 +62,7 @@ function Install-OpenSSH

Copy-Item -Path "$SourceDir/*" -Destination $OpenSSHDir -Recurse -Force -Verbose

Push-Location $OpenSSHDir
Push-Location $OpenSSHDir

try
{
Expand All @@ -81,8 +81,8 @@ function Install-OpenSSH
{
[Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE')
}
Start-Service -Name sshd

Start-Service -Name sshd
Start-Service -Name ssh-agent
}
finally
Expand All @@ -100,7 +100,7 @@ function Install-OpenSSH
function UnInstall-OpenSSH
{
[CmdletBinding()]
param (
param (
[string]$OpenSSHDir = "$env:SystemDrive\OpenSSH"
)

Expand All @@ -117,15 +117,15 @@ function UnInstall-OpenSSH
Stop-Service ssh-agent -Force
}
& "$OpenSSHDir\uninstall-sshd.ps1"

$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
$newMachineEnvironmentPath = $machinePath
if ($machinePath.ToLower().Contains($OpenSSHDir.ToLower()))
{
{
$newMachineEnvironmentPath = $newMachineEnvironmentPath.Replace("$OpenSSHDir;", '')
$env:Path = $env:Path.Replace("$OpenSSHDir;", '')
}

if ($newMachineEnvironmentPath -ne $machinePath)
{
[Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE')
Expand All @@ -136,7 +136,7 @@ function UnInstall-OpenSSH
Pop-Location
}

Remove-Item -Path $OpenSSHDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $OpenSSHDir -Recurse -Force -ErrorAction SilentlyContinue
}

#
Expand Down Expand Up @@ -181,7 +181,7 @@ function Invoke-OpenSSHTests
}

$xml = [xml](Get-Content $OpenSSHTestInfo["SetupTestResultsFile"] | out-string)
if ([int]$xml.'test-results'.failures -gt 0)
if ([int]$xml.'test-results'.failures -gt 0)
{
$errorMessage = "$($xml.'test-results'.failures) Setup Tests in regress\pesterTests failed. Detail test log is at $($OpenSSHTestInfo["SetupTestResultsFile"])."
Write-BuildMessage -Message $errorMessage -Category Error
Expand Down Expand Up @@ -218,31 +218,9 @@ function Invoke-OpenSSHTests
# Run all E2E tests.
Write-Verbose -Verbose -Message "Running E2E Tests..."
Set-OpenSSHTestEnvironment -Confirm:$false
Invoke-OpenSSHE2ETest
if (($OpenSSHTestInfo -eq $null) -or (-not (Test-Path $OpenSSHTestInfo["E2ETestResultsFile"])))
{
Write-BuildMessage -Message "Test result file $OpenSSHTestInfo["E2ETestResultsFile"] not found after tests." -Category Error
$AllTestsPassed = $false
}
else
{
$xml = [xml](Get-Content $OpenSSHTestInfo["E2ETestResultsFile"] | out-string)
if ([int]$xml.'test-results'.failures -gt 0)
{
$errorMessage = "$($xml.'test-results'.failures) E2E tests in regress\pesterTests failed. Detail test log is at $($OpenSSHTestInfo["E2ETestResultsFile"])."
Write-BuildMessage -Message $errorMessage -Category Error
$AllTestsPassed = $false
}
else
{
Write-BuildMessage -Message "All E2E tests passed!" -Category Information
}
}

# Bash tests.
Write-Verbose -Verbose -Message "Running Bash Tests..."

# Ensure CygWin is installed, and install from Chocolatey if needed.
# used for bash tests and default shell pester tests
$cygwinInstalled = $true
$cygwinInstallLocation = "$env:SystemDrive/cygwin"
if (! (Test-Path -Path "$cygwinInstallLocation/bin/sh.exe"))
Expand All @@ -269,9 +247,33 @@ function Invoke-OpenSSHTests
}
}

# Run UNIX bash tests.
if ($cygwinInstalled)
{
Invoke-OpenSSHE2ETest
if (($OpenSSHTestInfo -eq $null) -or (-not (Test-Path $OpenSSHTestInfo["E2ETestResultsFile"])))
{
Write-BuildMessage -Message "Test result file $OpenSSHTestInfo["E2ETestResultsFile"] not found after tests." -Category Error
$AllTestsPassed = $false
}
else
{
$xml = [xml](Get-Content $OpenSSHTestInfo["E2ETestResultsFile"] | out-string)
if ([int]$xml.'test-results'.failures -gt 0)
{
$errorMessage = "$($xml.'test-results'.failures) E2E tests in regress\pesterTests failed. Detail test log is at $($OpenSSHTestInfo["E2ETestResultsFile"])."
Write-BuildMessage -Message $errorMessage -Category Error
$AllTestsPassed = $false
}
else
{
Write-BuildMessage -Message "All E2E tests passed!" -Category Information
}
}

# Bash tests.
Write-Verbose -Verbose -Message "Running Bash Tests..."

# Run UNIX bash tests.
Write-Verbose -Verbose -Message "Starting Bash Tests..."
Invoke-OpenSSHBashTests
if (-not $Global:bash_tests_summary)
Expand Down Expand Up @@ -306,7 +308,7 @@ function Invoke-OpenSSHTests
else
{
$xml = [xml](Get-Content $OpenSSHTestInfo["UninstallTestResultsFile"] | out-string)
if ([int]$xml.'test-results'.failures -gt 0)
if ([int]$xml.'test-results'.failures -gt 0)
{
$errorMessage = "$($xml.'test-results'.failures) uninstall tests in regress\pesterTests failed. Detail test log is at $($OpenSSHTestInfo["UninstallTestResultsFile"])."
Write-BuildMessage -Message $errorMessage -Category Error
Expand All @@ -318,7 +320,7 @@ function Invoke-OpenSSHTests
$OpenSSHTestInfo | Export-Clixml -Path "$repoRoot/OpenSSHTestInfo.xml" -Depth 10

# Writing out warning when the $Error.Count is non-zero. Tests Should clean $Error after success.
if ($Error.Count -gt 0)
if ($Error.Count -gt 0)
{
Write-BuildMessage -Message "Tests Should always clean $Error variable after success." -Category Warning
}
Expand All @@ -339,7 +341,7 @@ function Invoke-OpenSSHTests
Collect OpenSSH pester test results into one directory
#>
function Copy-OpenSSHTestResults
{
{
param (
[Parameter(Mandatory=$true)]
[string] $ResultsPath
Expand All @@ -352,7 +354,7 @@ function Copy-OpenSSHTestResults

Write-Verbose -Verbose "Creating test results directory for artifacts upload: $ResultsPath"
$null = New-Item -Path $ResultsPath -ItemType Directory -Force

if (! (Test-Path -Path $ResultsPath))
{
Write-BuildMessage -Message "Unable to write to test results path for test artifacts upload: $ResultsPath" -Category Error
Expand Down Expand Up @@ -498,7 +500,7 @@ function Copy-UnitTests
function Install-UnitTests
{
[CmdletBinding()]
param (
param (
[Parameter(Mandatory=$true)]
[string]$SourceDir,

Expand Down
54 changes: 36 additions & 18 deletions regress/pesterTests/CommonUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add-Type -TypeDefinition @"
"@

function Set-FilePermission
{
{
param(
[parameter(Mandatory=$true)]
[string]$FilePath,
Expand All @@ -20,7 +20,7 @@ function Set-FilePermission
[System.Security.AccessControl.AccessControlType] $AccessType = "Allow",
[ValidateSet("Add", "Delete")]
[string]$Action = "Add"
)
)

$myACL = Get-ACL $FilePath
$account = Get-UserAccount -UserSid $UserSid
Expand All @@ -30,9 +30,9 @@ function Set-FilePermission
Enable-Privilege SeRestorePrivilege | out-null
Set-Acl -Path $FilePath -AclObject $myACL
$myACL = Get-ACL $FilePath
if($myACL.Access)
{

if($myACL.Access)
{
$myACL.Access | % {
if($_.IdentityReference.Equals($account))
{
Expand All @@ -43,18 +43,18 @@ function Set-FilePermission
Set-Acl -Path $FilePath -AclObject $myACL
$myACL = Get-ACL $FilePath
}

if(-not ($myACL.RemoveAccessRule($_)))
{
throw "failed to remove access of $($_.IdentityReference) rule in setup "
}
}
}
}
}
}
elseif($Perms)
{
$Perms | % {
$Perms | % {
$userACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($UserSid, $_, "None", "None", $AccessType)
$myACL.AddAccessRule($userACE)
Expand All @@ -64,7 +64,7 @@ function Set-FilePermission
Set-Acl -Path $FilePath -AclObject $myACL -confirm:$false
}

function Add-PasswordSetting
function Add-PasswordSetting
{
param([string] $pass)
if ($IsWindows) {
Expand All @@ -86,17 +86,17 @@ function Remove-PasswordSetting

$Taskfolder = "\OpenSSHTestTasks\"
$Taskname = "StartTestDaemon"

function Start-SSHDTestDaemon
{
param(
[string] $Arguments,
[string] $Workdir,
[string] $Port)
[string] $Port)

$Arguments += " -p $Port"
$ac = New-ScheduledTaskAction -Execute (join-path $workdir "sshd") -WorkingDirectory $workdir -Argument $Arguments
$task = Register-ScheduledTask -TaskName $Taskname -User system -Action $ac -TaskPath $Taskfolder -Force
$task = Register-ScheduledTask -TaskName $Taskname -User system -Action $ac -TaskPath $Taskfolder -Force
Start-ScheduledTask -TaskPath $Taskfolder -TaskName $Taskname
#sleep for 1 seconds for process to ready to listener
$num = 0
Expand All @@ -111,25 +111,25 @@ function Start-SSHDTestDaemon
function Stop-SSHDTestDaemon
{
param(
[string] $Port)
[string] $Port)

$task = Get-ScheduledTask -TaskPath $Taskfolder -TaskName $Taskname -ErrorAction SilentlyContinue
if($task)
{
if($task.State -eq "Running")
{
Stop-ScheduledTask -TaskPath $Taskfolder -TaskName $Taskname
}
}
Unregister-ScheduledTask -TaskPath $Taskfolder -TaskName $Taskname -Confirm:$false
}

#kill process listening on $Port
$p = netstat -anop TCP | select-string -Pattern "0.0.0.0:$Port"
if (-not($p -eq $null))
if (-not($p -eq $null))
{
foreach ($ps in $p) {
$pss =$ps.ToString() -split "\s+";
$processid = $pss[$pss.length -1]
$pss =$ps.ToString() -split "\s+";
$processid = $pss[$pss.length -1]
Stop-Process -Id $processid -Force -ErrorAction SilentlyContinue
}
#if still running, wait a little while for task to complete
Expand All @@ -142,4 +142,22 @@ function Stop-SSHDTestDaemon
}
}

}
}

function ConfigureDefaultShell {
param
(
[string] $default_shell_path,
[string] $dfltShellRegPath = "HKLM:\Software\OpenSSH",
[string] $dfltShellRegKeyName = "DefaultShell",
[string] $dfltShellCmdOptionRegKeyName = "DefaultShellCommandOption",
[string] $default_shell_cmd_option_val = $null
)
if (!(Test-Path $dfltShellRegPath)) {
New-Item -Path $dfltShellRegPath -Force | Out-Null
}
New-ItemProperty -Path $dfltShellRegPath -Name $dfltShellRegKeyName -Value $default_shell_path -PropertyType String -Force
if ($default_shell_cmd_option_val -ne $null) {
New-ItemProperty -Path $dfltShellRegPath -Name $dfltShellCmdOptionRegKeyName -Value $default_shell_cmd_option_val -PropertyType String -Force
}
}
Loading