From a6b83477ece5b4655167531b54d539f49964e234 Mon Sep 17 00:00:00 2001 From: SteveL-MSFT Date: Mon, 24 Jul 2017 16:09:52 -0700 Subject: [PATCH 1/5] [Feature] Fixed error message using a null resourcemanager With most recent CoreFx supporting STA, removed special CoreClr code paths Added test coverage Removed some dead commented out code that was never used --- src/Microsoft.WSMan.Management/CredSSP.cs | 45 ----------------- src/Microsoft.WSMan.Management/WsManHelper.cs | 15 +++--- .../CredSSP-nonAdmin.Tests.ps1 | 27 +++++++++++ .../CredSSP.Tests.ps1 | 48 +++++++++++++++++++ 4 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 create mode 100644 test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 diff --git a/src/Microsoft.WSMan.Management/CredSSP.cs b/src/Microsoft.WSMan.Management/CredSSP.cs index 44984e0f7b0..29b71c14f3c 100644 --- a/src/Microsoft.WSMan.Management/CredSSP.cs +++ b/src/Microsoft.WSMan.Management/CredSSP.cs @@ -55,29 +55,6 @@ public string Role set { role = value; } } private string role; - - /*/// - /// Role can either "Client" or "Server". - /// - [Parameter(ParameterSetName = Client, Mandatory = true, Position = 0)] - public SwitchParameter ClientRole - { - get { return isClient; } - set { isClient = value; } - } - private bool isClient; - - /// - /// - /// - [Parameter(ParameterSetName = Server, Mandatory = true, Position = 0)] - public SwitchParameter ServerRole - { - get { return isServer; } - set { isServer = value; } - } - private bool isServer;*/ - #endregion #region Utilities @@ -165,7 +142,6 @@ private void DisableClientSideSettings() } m_SessionObj.Put(helper.CredSSP_RUri, inputXml, 0); -#if !CORECLR if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { this.DeleteUserDelegateSettings(); @@ -178,14 +154,6 @@ private void DisableClientSideSettings() thread.Start(); thread.Join(); } -#else - { - ThreadStart start = new ThreadStart(this.DeleteUserDelegateSettings); - Thread thread = new Thread(start); - thread.Start(); - thread.Join(); - } -#endif if (!helper.ValidateCreadSSPRegistryRetry(false, null, applicationname)) { @@ -493,8 +461,6 @@ protected override void BeginProcessing() throw new InvalidOperationException(message); } #endif - //If not running elevated, then throw an "elevation required" error message. - WSManHelper.ThrowIfNotAdministrator(); // DelegateComputer cannot be specified when Role is other than client if ((delegatecomputer != null) && !Role.Equals(Client, StringComparison.OrdinalIgnoreCase)) @@ -613,7 +579,6 @@ private void EnableClientSideSettings() //push the xml string with credssp enabled xmldoc.LoadXml(m_SessionObj.Put(helper.CredSSP_RUri, newxmlcontent, 0)); -#if !CORECLR // No ApartmentState In CoreCLR // set the Registry using GroupPolicyObject if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { @@ -627,14 +592,6 @@ private void EnableClientSideSettings() thread.Start(); thread.Join(); } -#else - { - ThreadStart start = new ThreadStart(this.UpdateCurrentUserRegistrySettings); - Thread thread = new Thread(start); - thread.Start(); - thread.Join(); - } -#endif if (helper.ValidateCreadSSPRegistryRetry(true, delegatecomputer, applicationname)) { @@ -941,8 +898,6 @@ protected override void BeginProcessing() throw new InvalidOperationException(message); } #endif - //If not running elevated, then throw an "elevation required" error message. - WSManHelper.ThrowIfNotAdministrator(); IWSManSession m_SessionObj = null; try diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index 555f031bb41..a1c6ab05a10 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -80,7 +80,6 @@ internal class WSManHelper //string for operation internal string WSManOp = null; - private ResourceManager _resourceMgr = null; private PSCmdlet cmdletname; private NavigationCmdletProvider _provider; @@ -172,7 +171,7 @@ static internal string FormatResourceMsgFromResourcetextS(string rscname, internal string FormatResourceMsgFromResourcetext(string resourceName, params object[] args) { - return FormatResourceMsgFromResourcetextS(this._resourceMgr, resourceName, args); + return FormatResourceMsgFromResourcetextS(g_resourceMgr, resourceName, args); } static private string FormatResourceMsgFromResourcetextS( @@ -394,7 +393,7 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, { if (!File.Exists(filepath)) { - throw new FileNotFoundException(_resourceMgr.GetString("InvalidFileName")); + throw new FileNotFoundException(g_resourceMgr.GetString("InvalidFileName")); } resultString = ReadFile(filepath); return resultString; @@ -446,11 +445,11 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, XmlNodeList nodes = xmlfile.SelectNodes(xpathString); if (nodes.Count == 0) { - throw new ArgumentException(_resourceMgr.GetString("NoResourceMatch")); + throw new ArgumentException(g_resourceMgr.GetString("NoResourceMatch")); } else if (nodes.Count > 1) { - throw new ArgumentException(_resourceMgr.GetString("MultipleResourceMatch")); + throw new ArgumentException(g_resourceMgr.GetString("MultipleResourceMatch")); } else { @@ -459,14 +458,14 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, { if (node.ChildNodes.Count > 1) { - throw new ArgumentException(_resourceMgr.GetString("NOAttributeMatch")); + throw new ArgumentException(g_resourceMgr.GetString("NOAttributeMatch")); } else { XmlNode tmpNode = node.ChildNodes[0];//.Item[0]; if (!tmpNode.NodeType.ToString().Equals("text", StringComparison.OrdinalIgnoreCase)) { - throw new ArgumentException(_resourceMgr.GetString("NOAttributeMatch")); + throw new ArgumentException(g_resourceMgr.GetString("NOAttributeMatch")); } } } @@ -962,7 +961,7 @@ internal void CreateWsManConnection(string ParameterSetName, Uri connectionuri, } catch (IndexOutOfRangeException) { - AssertError(_resourceMgr.GetString("NotProperURI"), false, connectionuri); + AssertError(g_resourceMgr.GetString("NotProperURI"), false, connectionuri); } catch (Exception ex) { diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 new file mode 100644 index 00000000000..1ec045ca232 --- /dev/null +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 @@ -0,0 +1,27 @@ +Describe "CredSSP cmdlet tests non-admin" -Tags 'Feature' { + + $isAdmin = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) + + It "Error returned if runas non-admin: " -Skip:(!$IsWindows -or $isAdmin) -TestCases @( + @{cmdline = "Enable-WSManCredSSP -Role Server -Force";cmd = "EnableWSManCredSSPCommand"}, + @{cmdline = "Disable-WSManCredSSP -Role Server";cmd = "DisableWSManCredSSPCommand"}, + @{cmdline = "Get-WSManCredSSP";cmd = "GetWSmanCredSSPCommand"} + ) { + param ($cmdline, $cmd) + { Invoke-Expression $cmdline } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" + } + + It "Call cmdlet as API" -Skip:(!$IsWindows) { + $credssp = [Microsoft.WSMan.Management.EnableWSManCredSSPCommand]::new() + $credssp.Role = "Client" + $credssp.Role | Should BeExactly "Client" + $credssp.DelegateComputer = "foo","bar" + $credssp.DelegateComputer -join ',' | Should Be "foo,bar" + $credssp.Force = $true + $credssp.Force | Should Be $true + + $credssp = [Microsoft.WSMan.Management.DisableWSManCredSSPCommand]::new() + $credssp.Role = "Server" + $credssp.Role | Should BeExactly "Server" + } +} diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 new file mode 100644 index 00000000000..d2c4e19e82b --- /dev/null +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -0,0 +1,48 @@ +Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { + + It "Error returned if invalid parameters: " -Skip:(!$IsWindows) -TestCases @( + @{params=@{Role="Client"};Description="Client role, no DelegateComputer"}, + @{params=@{Role="Server";DelegateComputer="."};Description="Server role w/ DelegateComputer"} + ) { + param ($params) + { Enable-WSManCredSSP @params } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.EnableWSManCredSSPCommand" + } + + It "Enable-WSManCredSSP works: " -Skip:(!$IsWindows) -TestCases @( + @{params=@{Role="Client";DelegateComputer="*"};description="client"}, + @{params=@{Role="Server"};description="server"} + ) { + param ($params) + $c = Enable-WSManCredSSP @params -Force + $c.CredSSP | Should Be $true + + $c = Get-WSManCredSSP + if ($params.Role -eq "Client") + { + $c[0] | Should Match "The machine is configured to allow delegating fresh credentials to the following target\(s\):wsman/\*" + } + else + { + $c[1] | Should Match "This computer is configured to receive credentials from a remote client computer" + } + } + + It "Disable-WSManCredSSP works: " -Skip:(!$IsWindows) -TestCases @( + @{Role="Client"}, + @{Role="Server"} + ) { + param ($role) + Disable-WSManCredSSP -Role $role | Should BeNullOrEmpty + + $c = Get-WSManCredSSP + if ($role -eq "Client") + { + $c[0] | Should Match "The machine is not configured to allow delegating fresh credentials." + } + else + { + $c[1] | Should Match "This computer is not configured to receive credentials from a remote client computer" + } + } +} + From e61c05a59e13626ac45ac510ca451fe2d2de2826 Mon Sep 17 00:00:00 2001 From: "Steve Lee [MSFT]" Date: Tue, 25 Jul 2017 20:32:02 -0700 Subject: [PATCH 2/5] [Feature] merged tests to one file, use runas to have relevant tests run as non-elevated --- src/Microsoft.WSMan.Management/WsManHelper.cs | 22 +++---- .../CredSSP-nonAdmin.Tests.ps1 | 27 --------- .../CredSSP.Tests.ps1 | 59 +++++++++++++++++-- 3 files changed, 66 insertions(+), 42 deletions(-) delete mode 100644 test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index a1c6ab05a10..d33423ddf00 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -86,7 +86,7 @@ internal class WSManHelper private FileStream _fs; private StreamReader _sr; - private static ResourceManager g_resourceMgr = new ResourceManager("Microsoft.WSMan.Management.resources.WsManResources", typeof(WSManHelper).GetTypeInfo().Assembly); + private static ResourceManager _resourceMgr = new ResourceManager("Microsoft.WSMan.Management.resources.WsManResources", typeof(WSManHelper).GetTypeInfo().Assembly); // @@ -152,26 +152,26 @@ internal static void ThrowIfNotAdministrator() System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(currentIdentity); if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { - string message = g_resourceMgr.GetString("ErrorElevationNeeded"); + string message = _resourceMgr.GetString("ErrorElevationNeeded"); throw new InvalidOperationException(message); } } internal string GetResourceMsgFromResourcetext(string rscname) { - return g_resourceMgr.GetString(rscname); + return _resourceMgr.GetString(rscname); } static internal string FormatResourceMsgFromResourcetextS(string rscname, params object[] args) { - return FormatResourceMsgFromResourcetextS(g_resourceMgr, rscname, args); + return FormatResourceMsgFromResourcetextS(_resourceMgr, rscname, args); } internal string FormatResourceMsgFromResourcetext(string resourceName, params object[] args) { - return FormatResourceMsgFromResourcetextS(g_resourceMgr, resourceName, args); + return FormatResourceMsgFromResourcetextS(_resourceMgr, resourceName, args); } static private string FormatResourceMsgFromResourcetextS( @@ -393,7 +393,7 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, { if (!File.Exists(filepath)) { - throw new FileNotFoundException(g_resourceMgr.GetString("InvalidFileName")); + throw new FileNotFoundException(_resourceMgr.GetString("InvalidFileName")); } resultString = ReadFile(filepath); return resultString; @@ -445,11 +445,11 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, XmlNodeList nodes = xmlfile.SelectNodes(xpathString); if (nodes.Count == 0) { - throw new ArgumentException(g_resourceMgr.GetString("NoResourceMatch")); + throw new ArgumentException(_resourceMgr.GetString("NoResourceMatch")); } else if (nodes.Count > 1) { - throw new ArgumentException(g_resourceMgr.GetString("MultipleResourceMatch")); + throw new ArgumentException(_resourceMgr.GetString("MultipleResourceMatch")); } else { @@ -458,14 +458,14 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, { if (node.ChildNodes.Count > 1) { - throw new ArgumentException(g_resourceMgr.GetString("NOAttributeMatch")); + throw new ArgumentException(_resourceMgr.GetString("NOAttributeMatch")); } else { XmlNode tmpNode = node.ChildNodes[0];//.Item[0]; if (!tmpNode.NodeType.ToString().Equals("text", StringComparison.OrdinalIgnoreCase)) { - throw new ArgumentException(g_resourceMgr.GetString("NOAttributeMatch")); + throw new ArgumentException(_resourceMgr.GetString("NOAttributeMatch")); } } } @@ -961,7 +961,7 @@ internal void CreateWsManConnection(string ParameterSetName, Uri connectionuri, } catch (IndexOutOfRangeException) { - AssertError(g_resourceMgr.GetString("NotProperURI"), false, connectionuri); + AssertError(_resourceMgr.GetString("NotProperURI"), false, connectionuri); } catch (Exception ex) { diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 deleted file mode 100644 index 1ec045ca232..00000000000 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP-nonAdmin.Tests.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -Describe "CredSSP cmdlet tests non-admin" -Tags 'Feature' { - - $isAdmin = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) - - It "Error returned if runas non-admin: " -Skip:(!$IsWindows -or $isAdmin) -TestCases @( - @{cmdline = "Enable-WSManCredSSP -Role Server -Force";cmd = "EnableWSManCredSSPCommand"}, - @{cmdline = "Disable-WSManCredSSP -Role Server";cmd = "DisableWSManCredSSPCommand"}, - @{cmdline = "Get-WSManCredSSP";cmd = "GetWSmanCredSSPCommand"} - ) { - param ($cmdline, $cmd) - { Invoke-Expression $cmdline } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" - } - - It "Call cmdlet as API" -Skip:(!$IsWindows) { - $credssp = [Microsoft.WSMan.Management.EnableWSManCredSSPCommand]::new() - $credssp.Role = "Client" - $credssp.Role | Should BeExactly "Client" - $credssp.DelegateComputer = "foo","bar" - $credssp.DelegateComputer -join ',' | Should Be "foo,bar" - $credssp.Force = $true - $credssp.Force | Should Be $true - - $credssp = [Microsoft.WSMan.Management.DisableWSManCredSSPCommand]::new() - $credssp.Role = "Server" - $credssp.Role | Should BeExactly "Server" - } -} diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 index d2c4e19e82b..751e91fea5c 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -1,6 +1,26 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { - It "Error returned if invalid parameters: " -Skip:(!$IsWindows) -TestCases @( + BeforeAll { + $powershell = Join-Path $PSHOME "powershell" + + $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() + if ( ! $IsWindows ) { + $PSDefaultParameterValues["it:skip"] = $true + } + } + + AfterAll { + $global:PSDefaultParameterValues = $originalDefaultParameterValues + } + + BeforeEach { + $errtxt = "$testdrive/error.txt" + Remove-Item $errtxt -Force -ErrorAction SilentlyContinue + $donefile = "$testdrive/done" + Remove-Item $donefile -Force -ErrorAction SilentlyContinue + } + + It "Error returned if invalid parameters: " -TestCases @( @{params=@{Role="Client"};Description="Client role, no DelegateComputer"}, @{params=@{Role="Server";DelegateComputer="."};Description="Server role w/ DelegateComputer"} ) { @@ -8,7 +28,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { { Enable-WSManCredSSP @params } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.EnableWSManCredSSPCommand" } - It "Enable-WSManCredSSP works: " -Skip:(!$IsWindows) -TestCases @( + It "Enable-WSManCredSSP works: " -TestCases @( @{params=@{Role="Client";DelegateComputer="*"};description="client"}, @{params=@{Role="Server"};description="server"} ) { @@ -27,7 +47,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { } } - It "Disable-WSManCredSSP works: " -Skip:(!$IsWindows) -TestCases @( + It "Disable-WSManCredSSP works: " -TestCases @( @{Role="Client"}, @{Role="Server"} ) { @@ -44,5 +64,36 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { $c[1] | Should Match "This computer is not configured to receive credentials from a remote client computer" } } -} + It "Call cmdlet as API" { + $credssp = [Microsoft.WSMan.Management.EnableWSManCredSSPCommand]::new() + $credssp.Role = "Client" + $credssp.Role | Should BeExactly "Client" + $credssp.DelegateComputer = "foo", "bar" + $credssp.DelegateComputer -join ',' | Should Be "foo,bar" + $credssp.Force = $true + $credssp.Force | Should Be $true + + $credssp = [Microsoft.WSMan.Management.DisableWSManCredSSPCommand]::new() + $credssp.Role = "Server" + $credssp.Role | Should BeExactly "Server" + } + + It "Error returned if runas non-admin: " -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" + $startTime = Get-Date + while (((Get-Date) - $startTime).TotalSeconds -lt 5 -and -not (Test-Path "$donefile")) + { + Start-Sleep -Milliseconds 100 + } + $errtxt | Should Exist + $err = Get-Content $errtxt + $err | Should Be "System.InvalidOperationException,Microsoft.WSMan.Management.$cmd" + } +} From efa769f708e9b57af76121e697820e0fbd278ffd Mon Sep 17 00:00:00 2001 From: "Steve Lee [MSFT]" Date: Fri, 28 Jul 2017 16:55:53 -0700 Subject: [PATCH 3/5] [Feature] Get-CredSSP returns text so only run that test if current culture is en-US --- .../Microsoft.WSMan.Management/CredSSP.Tests.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 index 751e91fea5c..95e869a42de 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -7,6 +7,12 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { if ( ! $IsWindows ) { $PSDefaultParameterValues["it:skip"] = $true } + + $notEnglish = $false + if ([System.Globalization.CultureInfo]::CurrentCulture.Name -ne "en-US") + { + $notEnglish = $true + } } AfterAll { @@ -28,7 +34,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { { Enable-WSManCredSSP @params } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.EnableWSManCredSSPCommand" } - It "Enable-WSManCredSSP works: " -TestCases @( + It "Enable-WSManCredSSP works: " -Skip:($NotEnglish) -TestCases @( @{params=@{Role="Client";DelegateComputer="*"};description="client"}, @{params=@{Role="Server"};description="server"} ) { @@ -47,7 +53,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { } } - It "Disable-WSManCredSSP works: " -TestCases @( + It "Disable-WSManCredSSP works: " -Skip:($NotEnglish) -TestCases @( @{Role="Client"}, @{Role="Server"} ) { From 7d1c523b2c6546d13848160acace354e193c7d31 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Mon, 7 Aug 2017 15:30:39 -0700 Subject: [PATCH 4/5] [Feature] Update test to fix code exclusion --- .../Microsoft.WSMan.Management/CredSSP.Tests.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 index 95e869a42de..bd064e95f50 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -2,16 +2,19 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { BeforeAll { $powershell = Join-Path $PSHOME "powershell" + $notEnglish = $false $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - if ( ! $IsWindows ) { + if ( ! $IsWindows ) + { $PSDefaultParameterValues["it:skip"] = $true } - - $notEnglish = $false - if ([System.Globalization.CultureInfo]::CurrentCulture.Name -ne "en-US") + else { - $notEnglish = $true + if ([System.Globalization.CultureInfo]::CurrentCulture.Name -ne "en-US") + { + $notEnglish = $true + } } } From cf9ee3fd17d0df16f33591b72363d6bec7462818 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 8 Aug 2017 16:08:26 -0700 Subject: [PATCH 5/5] [Feature] Fix Skipping on test cases that already had a Skip value --- .../CredSSP.Tests.ps1 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 index bd064e95f50..09afa49b281 100644 --- a/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.WSMan.Management/CredSSP.Tests.ps1 @@ -3,9 +3,10 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { BeforeAll { $powershell = Join-Path $PSHOME "powershell" $notEnglish = $false + $IsToBeSkipped = !$IsWindows; $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - if ( ! $IsWindows ) + if ( $IsToBeSkipped ) { $PSDefaultParameterValues["it:skip"] = $true } @@ -23,10 +24,13 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { } BeforeEach { - $errtxt = "$testdrive/error.txt" - Remove-Item $errtxt -Force -ErrorAction SilentlyContinue - $donefile = "$testdrive/done" - Remove-Item $donefile -Force -ErrorAction SilentlyContinue + if ( ! $IsToBeSkipped ) + { + $errtxt = "$testdrive/error.txt" + Remove-Item $errtxt -Force -ErrorAction SilentlyContinue + $donefile = "$testdrive/done" + Remove-Item $donefile -Force -ErrorAction SilentlyContinue + } } It "Error returned if invalid parameters: " -TestCases @( @@ -37,7 +41,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { { Enable-WSManCredSSP @params } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.WSMan.Management.EnableWSManCredSSPCommand" } - It "Enable-WSManCredSSP works: " -Skip:($NotEnglish) -TestCases @( + It "Enable-WSManCredSSP works: " -Skip:($NotEnglish -or $IsToBeSkipped) -TestCases @( @{params=@{Role="Client";DelegateComputer="*"};description="client"}, @{params=@{Role="Server"};description="server"} ) { @@ -56,7 +60,7 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' { } } - It "Disable-WSManCredSSP works: " -Skip:($NotEnglish) -TestCases @( + It "Disable-WSManCredSSP works: " -Skip:($NotEnglish -or $IsToBeSkipped) -TestCases @( @{Role="Client"}, @{Role="Server"} ) {