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
This commit is contained in:
Travis Plunk 2018-03-19 15:36:56 -07:00 committed by GitHub
parent b49fb7f1b3
commit ae636df526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 27 deletions

View file

@ -250,31 +250,19 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
} }
} }
It "Access-denied test for '<cmdline>" -Skip:(-not $IsWindows) -TestCases @( It "Access-denied test for <cmdline>" -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. # 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-Item $protectedPath2 -ErrorAction Stop"; expectedError = "ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetItemCommand"}
@{cmdline = "Get-ChildItem $protectedPath"; expectedError = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"} @{cmdline = "Get-ChildItem $protectedPath -ErrorAction Stop"; expectedError = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"}
@{cmdline = "New-Item -Type File -Path $newItemPath"; expectedError = "NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand"} @{cmdline = "New-Item -Type File -Path $newItemPath -ErrorAction Stop"; expectedError = "NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand"}
@{cmdline = "Rename-Item -Path $protectedPath -NewName bar"; expectedError = "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"}, @{cmdline = "Rename-Item -Path $protectedPath -NewName bar -ErrorAction Stop"; expectedError = "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"},
@{cmdline = "Move-Item -Path $protectedPath -Destination bar"; expectedError = "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand"}, @{cmdline = "Move-Item -Path $protectedPath -Destination bar -ErrorAction Stop"; expectedError = "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand"},
@{cmdline = "Remove-Item -Path $protectedPath"; expectedError = "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand"} @{cmdline = "Remove-Item -Path $protectedPath -ErrorAction Stop"; expectedError = "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand"}
) { ) {
param ($cmdline, $expectedError) param ($cmdline, $expectedError)
# generate a filename to use for the error and done text files to avoid test output collision $scriptBlock = [scriptblock]::Create($cmdline)
# when a timeout occurs waiting for powershell. $scriptBlock | Should -Throw -ErrorId $expectedError
$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
} }
} }

View file

@ -93,18 +93,18 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' {
$credssp.Role = "Server" $credssp.Role = "Server"
$credssp.Role | Should BeExactly "Server" $credssp.Role | Should BeExactly "Server"
} }
}
It "Error returned if runas non-admin: <cmdline>" -TestCases @( Describe "CredSSP cmdlet error cases tests" -Tags 'Feature' {
It "Error returned if runas non-admin: <cmdline>" -Skip:(!$IsWindows) -TestCases @(
@{cmdline = "Enable-WSManCredSSP -Role Server -Force"; cmd = "EnableWSManCredSSPCommand"}, @{cmdline = "Enable-WSManCredSSP -Role Server -Force"; cmd = "EnableWSManCredSSPCommand"},
@{cmdline = "Disable-WSManCredSSP -Role Server"; cmd = "DisableWSManCredSSPCommand"}, @{cmdline = "Disable-WSManCredSSP -Role Server"; cmd = "DisableWSManCredSSPCommand"},
@{cmdline = "Get-WSManCredSSP"; cmd = "GetWSmanCredSSPCommand"} @{cmdline = "Get-WSManCredSSP"; cmd = "GetWSmanCredSSPCommand"}
) { ) {
param ($cmdline, $cmd) param ($cmdline, $cmd)
runas.exe /trustlevel:0x20000 "$powershell -nop -c try { $cmdline } catch { `$_.FullyQualifiedErrorId | Out-File $errtxt }; New-Item -Type File -Path $donefile" $scriptBlock = [scriptblock]::Create($cmdline)
Wait-FileToBePresent -File $donefile -TimeoutInSeconds 5 -IntervalInMilliseconds 100 $scriptBlock | should -Throw -ErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd"
$errtxt | Should Exist
$err = Get-Content $errtxt
$err | Should Be "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd"
} }
} }