From ae636df5260ea491609e9d3c2fb05152627f7b3c Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 19 Mar 2018 15:36:56 -0700 Subject: [PATCH] remove runas.exe from tests as we have tags to control this behavior (#6432) remove runas.exe from tests as we have tags to control this behavior - this should reduce the likelihood of errors --- .../FileSystem.Tests.ps1 | 30 ++++++------------- .../CredSSP.Tests.ps1 | 12 ++++---- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index 25ba4b5fd..974c69568 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -250,31 +250,19 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { } } - It "Access-denied test for '" -Skip:(-not $IsWindows) -TestCases @( + It "Access-denied test for " -Skip:(-not $IsWindows) -TestCases @( # NOTE: ensure the fileNameBase parameter is unique for each test case; it is used to generate a unique error and done file name. - @{cmdline = "Get-Item $protectedPath2"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"} - @{cmdline = "Get-ChildItem $protectedPath"; expectedError = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"} - @{cmdline = "New-Item -Type File -Path $newItemPath"; expectedError = "NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand"} - @{cmdline = "Rename-Item -Path $protectedPath -NewName bar"; expectedError = "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"}, - @{cmdline = "Move-Item -Path $protectedPath -Destination bar"; expectedError = "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand"}, - @{cmdline = "Remove-Item -Path $protectedPath"; expectedError = "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand"} + @{cmdline = "Get-Item $protectedPath2 -ErrorAction Stop"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"} + @{cmdline = "Get-ChildItem $protectedPath -ErrorAction Stop"; expectedError = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"} + @{cmdline = "New-Item -Type File -Path $newItemPath -ErrorAction Stop"; expectedError = "NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand"} + @{cmdline = "Rename-Item -Path $protectedPath -NewName bar -ErrorAction Stop"; expectedError = "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"}, + @{cmdline = "Move-Item -Path $protectedPath -Destination bar -ErrorAction Stop"; expectedError = "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand"}, + @{cmdline = "Remove-Item -Path $protectedPath -ErrorAction Stop"; expectedError = "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand"} ) { param ($cmdline, $expectedError) - # generate a filename to use for the error and done text files to avoid test output collision - # when a timeout occurs waiting for powershell. - $fileNameBase = ([string] $cmdline).GetHashCode().ToString() - $errFile = Join-Path -Path $TestDrive -ChildPath "$fileNameBase.error.txt" - $doneFile = Join-Path -Path $TestDrive -Childpath "$fileNameBase.done.txt" - - # Seed the error file with text indicating a timeout waiting for the command. - "Test timeout waiting for $cmdLine" | Set-Content -Path $errFile - - runas.exe /trustlevel:0x20000 "$powershell -nop -c try { $cmdline -ErrorAction Stop } catch { `$_.FullyQualifiedErrorId | Out-File $errFile }; New-Item -Type File -Path $doneFile" - Wait-FileToBePresent -File $doneFile -TimeoutInSeconds 15 -IntervalInMilliseconds 100 - - $err = Get-Content $errFile - $err | Should -Be $expectedError + $scriptBlock = [scriptblock]::Create($cmdline) + $scriptBlock | Should -Throw -ErrorId $expectedError } } diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 index 027373f63..ea1a6516e 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -93,18 +93,18 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { $credssp.Role = "Server" $credssp.Role | Should BeExactly "Server" } +} - It "Error returned if runas non-admin: " -TestCases @( +Describe "CredSSP cmdlet error cases tests" -Tags 'Feature' { + + It "Error returned if runas non-admin: " -Skip:(!$IsWindows) -TestCases @( @{cmdline = "Enable-WSManCredSSP -Role Server -Force"; cmd = "EnableWSManCredSSPCommand"}, @{cmdline = "Disable-WSManCredSSP -Role Server"; cmd = "DisableWSManCredSSPCommand"}, @{cmdline = "Get-WSManCredSSP"; cmd = "GetWSmanCredSSPCommand"} ) { param ($cmdline, $cmd) - runas.exe /trustlevel:0x20000 "$powershell -nop -c try { $cmdline } catch { `$_.FullyQualifiedErrorId | Out-File $errtxt }; New-Item -Type File -Path $donefile" - Wait-FileToBePresent -File $donefile -TimeoutInSeconds 5 -IntervalInMilliseconds 100 - $errtxt | Should Exist - $err = Get-Content $errtxt - $err | Should Be "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" + $scriptBlock = [scriptblock]::Create($cmdline) + $scriptBlock | should -Throw -ErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" } }