Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions src/Microsoft.WSMan.Management/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Security;
#if !CORECLR
using System.ServiceProcess;
#endif

namespace Microsoft.WSMan.Management
{
Expand Down Expand Up @@ -113,11 +111,8 @@ string ICmdletProviderSupportsHelp.GetHelpMaml(string helpItemName, string path)

try
{
//XmlDocument in CoreCLR does not have file path parameter, use XmlReader
XmlReaderSettings readerSettings = new XmlReaderSettings();
#if !CORECLR
readerSettings.XmlResolver = null;
#endif
using (XmlReader reader = XmlReader.Create(helpFile, readerSettings))
{
document.Load(reader);
Expand Down Expand Up @@ -4463,10 +4458,6 @@ private void AssertError(string ErrorMessage, bool IsWSManError)
/// <returns></returns>
private bool IsWSManServiceRunning()
{
#if CORECLR
// TODO once s78 comes in undo this
return true;
#else
ServiceController svc = new ServiceController("WinRM");
if (svc != null)
{
Expand All @@ -4476,7 +4467,6 @@ private bool IsWSManServiceRunning()
}
}
return false;
#endif
}

/// <summary>
Expand Down Expand Up @@ -4515,8 +4505,6 @@ private bool IsPathLocalMachine(string host)
hostfound = true;
}

// Domain look up not available on CoreCLR?
#if !CORECLR
//Check is TestMac
if (!hostfound)
{
Expand Down Expand Up @@ -4559,7 +4547,6 @@ private bool IsPathLocalMachine(string host)
}
}
}
#endif
return hostfound;
}

Expand Down Expand Up @@ -4857,14 +4844,7 @@ private ArrayList ProcessPluginInitParamLevel(XmlDocument xmldoc)
if (attributecol[i].LocalName.Equals("Value", StringComparison.OrdinalIgnoreCase))
{
String ValueAsXML = attributecol[i].Value;
#if CORECLR
//SecurityElement.Escape() not supported on .NET Core, use WebUtility.HtmlEncode() to replace.
//During the encoding, single quote "\'" convert to "&#39;", then manually convert "&#39;" to "&apos;" since we are encode xml not html;
Value = System.Net.WebUtility.HtmlEncode(ValueAsXML);
Value = Value.Replace("&#39;", "&apos;");
#else
Value = SecurityElement.Escape(ValueAsXML);
#endif
}
}
objInitParam.Properties.Add(new PSNoteProperty(Name, Value));
Expand Down Expand Up @@ -5007,6 +4987,11 @@ private string ConstructPluginXml(PSObject objinputparam, string ResourceURI, st
private object ValidateAndGetUserObject(string configurationName, object value)
{
PSObject basePsObject = value as PSObject;
PSCredential psCredential = null;
if (basePsObject == null)
{
psCredential = value as PSCredential;
}

if (configurationName.Equals(WSManStringLiterals.ConfigRunAsPasswordName, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -5031,6 +5016,10 @@ private object ValidateAndGetUserObject(string configurationName, object value)
{
return basePsObject.BaseObject as PSCredential;
}
else if (psCredential != null)
{
return psCredential;
}
else
{
string error = String.Format(
Expand Down Expand Up @@ -5058,18 +5047,9 @@ private string GetStringFromSecureString(object propertyValue)

if (value != null)
{
#if !CORECLR
//coreCLR only supports marshal for unicode
IntPtr ptr = Marshal.SecureStringToBSTR(value);
passwordValueToAdd = Marshal.PtrToStringAuto(ptr);
Marshal.ZeroFreeBSTR(ptr);
#else
IntPtr ptr = SecureStringMarshal.SecureStringToCoTaskMemUnicode(value);
passwordValueToAdd = Marshal.PtrToStringUni(ptr);
Marshal.ZeroFreeCoTaskMemAnsi(ptr);
#endif


}

return passwordValueToAdd;
Expand Down Expand Up @@ -6256,7 +6236,7 @@ function Start-WSManServiceD15A7957836142a18627D7E1D342DD82
{{
if ($force -or $pscmdlet.ShouldContinue($queryForStart, $captionForStart))
{{
Restart WinRM -Force -Confirm:$false
Restart-Service WinRM -Force -Confirm:$false
return $true
}}
return $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
<ProjectReference Include="..\Microsoft.WSMan.Runtime\Microsoft.WSMan.Runtime.csproj" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.4.0" />
</ItemGroup>

<PropertyGroup>
Expand Down
62 changes: 62 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,65 @@ Describe "Tab completion tests with remote Runspace" -Tags Feature {
$res.CompletionMatches[0].CompletionText | Should Be $expected
}
}

Describe "WSMan Config Provider tab complete tests" -Tags Feature,RequireAdminOnWindows {

BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:skip"] = !$IsWindows
}

AfterAll {
$Global:PSDefaultParameterValues = $originalDefaultParameterValues
}

It "Tab completion works correctly for Listeners" {
$path = "wsman:\localhost\listener\listener"
$res = TabExpansion2 -inputScript $path -cursorColumn $path.Length
$listener = Get-ChildItem WSMan:\localhost\Listener
$res.CompletionMatches.Count | Should Be $listener.Count
for ($i = 0; $i -lt $res.CompletionMatches.Count; $i++) {
$res.CompletionMatches[$i].ListItemText | Should Be $listener[$i].Name
}
}

It "Tab completion gets dynamic parameters for '<path>' using '<parameter>'" -TestCases @(
@{path = ""; parameter = "-co"; expected = "ConnectionURI"},
@{path = ""; parameter = "-op"; expected = "OptionSet"},
@{path = ""; parameter = "-au"; expected = "Authentication"},
@{path = ""; parameter = "-ce"; expected = "CertificateThumbprint"},
@{path = ""; parameter = "-se"; expected = "SessionOption"},
@{path = ""; parameter = "-ap"; expected = "ApplicationName"},
@{path = ""; parameter = "-po"; expected = "Port"},
@{path = ""; parameter = "-u"; expected = "UseSSL"},
@{path = "localhost\plugin"; parameter = "-pl"; expected = "Plugin"},
@{path = "localhost\plugin"; parameter = "-sd"; expected = "SDKVersion"},
@{path = "localhost\plugin"; parameter = "-re"; expected = "Resource"},
@{path = "localhost\plugin"; parameter = "-ca"; expected = "Capability"},
@{path = "localhost\plugin"; parameter = "-xm"; expected = "XMLRenderingType"},
@{path = "localhost\plugin"; parameter = "-fi"; expected = @("FileName", "File")},
@{path = "localhost\plugin"; parameter = "-ru"; expected = "RunAsCredential"},
@{path = "localhost\plugin"; parameter = "-us"; expected = "UseSharedProcess"},
@{path = "localhost\plugin"; parameter = "-au"; expected = "AutoRestart"},
@{path = "localhost\plugin"; parameter = "-pr"; expected = "ProcessIdleTimeoutSec"},
@{path = "localhost\Plugin\microsoft.powershell\Resources\"; parameter = "-re"; expected = "ResourceUri"},
@{path = "localhost\Plugin\microsoft.powershell\Resources\"; parameter = "-ca"; expected = "Capability"}
) {
param($path, $parameter, $expected)
$script = "new-item wsman:\$path $parameter"
$res = TabExpansion2 -inputScript $script -cursorColumn $script.Length
$res.CompletionMatches.Count | Should Be $expected.Count
$completionOptions = ""
foreach ($completion in $res.CompletionMatches) {
$completionOptions += $completion.ListItemText
}
$completionOptions | Should Be ([string]::Join("", $expected))
}

It "Tab completion get dynamic parameters for initialization parameters" -Pending -TestCases @(
@{path = "localhost\Plugin\microsoft.powershell\InitializationParameters\"; parameter = "-pa"; expected = @("ParamName", "ParamValue")}
) {
# https://github.com/PowerShell/PowerShell/issues/4744
# TODO: move to test cases above once working
}
}
Loading