From 735bcca4d0977defe1246976f4501e553c513a0e Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Wed, 28 Sep 2016 18:28:01 -0700 Subject: [PATCH] Allow ExecutionPolicy tests to throw specific type of error Split LocalMachine test case into two separate tests: - One without overriden policy (throws exception) - One with overriden policy --- .../ExecutionPolicy.Tests.ps1 | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/ExecutionPolicy.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Security/ExecutionPolicy.Tests.ps1 index 68e70398b9..ef312b9c80 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/ExecutionPolicy.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/ExecutionPolicy.Tests.ps1 @@ -1021,7 +1021,25 @@ ZoneId=$FileType } } - It "-Scope LocalMachine is Settable" { + It '-Scope LocalMachine is Settable, but overridden' { + # setup + Set-ExecutionPolicy -Scope Process -ExecutionPolicy Undefined + Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Restricted + $errorId = $null + try + { + Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy ByPass + } + catch [System.Security.SecurityException] { + $errorId = $_.FullyQualifiedErrorId + } + + $errorId | Should Be 'ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand' + Get-ExecutionPolicy -Scope LocalMachine | Should Be "ByPass" + } + + It '-Scope LocalMachine is Settable' { + Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Undefined Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy ByPass Get-ExecutionPolicy -Scope LocalMachine | Should Be "ByPass" }