From 5b7f72a8a8316f34c69ec45abb0afc6cf42ee990 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 14 Aug 2018 11:35:00 -0700 Subject: [PATCH 1/5] [Feature] Update reference to use packages from NuGet.org * Update psrp and libpsl reference to Microsoft.PowerShell.Native * Keep the reference to powershell.myget.org in nuget.config for PSDesiredStateConfiguration and PowerShellHelpFiles * Update hosting tests * Update hosting.tests.csproj in preparation on next release with version 6.1.0-rc.1 * Update Microsoft.Management.Infrastructure to version 1.0.0 --- .../System.Management.Automation.csproj | 4 +- src/powershell-unix/powershell-unix.csproj | 2 - .../powershell-win-core.csproj | 9 +- test/hosting/NuGet.Config | 1 - test/hosting/hosting.tests.csproj | 4 +- test/hosting/test_HostingBasic.cs | 91 ++++++++++++++++++- 6 files changed, 99 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/System.Management.Automation.csproj b/src/System.Management.Automation/System.Management.Automation.csproj index 676781b7707..3b9277a0506 100644 --- a/src/System.Management.Automation/System.Management.Automation.csproj +++ b/src/System.Management.Automation/System.Management.Automation.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/src/powershell-unix/powershell-unix.csproj b/src/powershell-unix/powershell-unix.csproj index 3d59eb197b7..f6b16e80d70 100644 --- a/src/powershell-unix/powershell-unix.csproj +++ b/src/powershell-unix/powershell-unix.csproj @@ -31,8 +31,6 @@ - - diff --git a/src/powershell-win-core/powershell-win-core.csproj b/src/powershell-win-core/powershell-win-core.csproj index 2e36ddb1478..49e815b2e21 100644 --- a/src/powershell-win-core/powershell-win-core.csproj +++ b/src/powershell-win-core/powershell-win-core.csproj @@ -24,10 +24,10 @@ PreserveNewest PreserveNewest - - preview\pwsh-preview.cmd - PreserveNewest - + + preview\pwsh-preview.cmd + PreserveNewest + @@ -40,7 +40,6 @@ - diff --git a/test/hosting/NuGet.Config b/test/hosting/NuGet.Config index c2c6e1b7c2d..c7d76968986 100644 --- a/test/hosting/NuGet.Config +++ b/test/hosting/NuGet.Config @@ -2,7 +2,6 @@ - diff --git a/test/hosting/hosting.tests.csproj b/test/hosting/hosting.tests.csproj index dfe9a9706fa..a63fe941a90 100644 --- a/test/hosting/hosting.tests.csproj +++ b/test/hosting/hosting.tests.csproj @@ -18,7 +18,9 @@ - + + + diff --git a/test/hosting/test_HostingBasic.cs b/test/hosting/test_HostingBasic.cs index 90fb8c2f28a..4918c56a21d 100644 --- a/test/hosting/test_HostingBasic.cs +++ b/test/hosting/test_HostingBasic.cs @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Xunit; using System; +using System.IO; using System.Management.Automation; +using System.Security; +using Microsoft.Management.Infrastructure; +using Xunit; namespace PowerShell.Hosting.SDK.Tests { @@ -51,5 +54,91 @@ public static void TestCommandFromCore() } } } + + /// Test is disabled since we do not have a CimCmdlets module released in the SDK. + + [SkippableFact] + public static void TestCommandFromMMI() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("[Microsoft.Management.Infrastructure.CimInstance]::new('Win32_Process')").Invoke(); + Assert.True(results.Count > 0); + } + } + + + [SkippableFact] + public static void TestCommandFromDiagnostics() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("Get-WinEvent -ListLog Application").Invoke(); + + foreach (dynamic item in results) + { + Assert.Equal("Application", item.LogName); + } + } + } + + [SkippableFact] + public static void TestCommandFromSecurity() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("ConvertTo-SecureString -String test -AsPlainText -Force").Invoke(); + Assert.IsType(results[0]); + } + } + + [SkippableFact] + public static void TestCommandFromWSMan() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("Test-WSMan").Invoke(); + + foreach (dynamic item in results) + { + Assert.Equal("Microsoft Corporation", item.ProductVendor); + } + } + } + + [Fact] + public static void TestCommandFromNative() + { + var fs = File.Create(Path.GetTempFileName()); + fs.Close(); + + string target = fs.Name; + string path = Path.GetTempFileName(); + + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + string command = $"New-Item -ItemType SymbolicLink -Path {path} -Target {target}"; + var results = ps.AddScript(command).Invoke(); + + foreach(var item in results) + { + Assert.Equal(path, item.FullName); + } + } + + if(File.Exists(path)) + { + File.Delete(path); + } + + if(File.Exists(target)) + { + File.Delete(target); + } + } } } From d826424b4e1ea21dff4c096679a66d06cb5a2916 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 14 Aug 2018 12:11:24 -0700 Subject: [PATCH 2/5] [Feature] Fix CodeFactor issues --- test/hosting/test_HostingBasic.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/hosting/test_HostingBasic.cs b/test/hosting/test_HostingBasic.cs index 4918c56a21d..c0f2875d86e 100644 --- a/test/hosting/test_HostingBasic.cs +++ b/test/hosting/test_HostingBasic.cs @@ -55,11 +55,10 @@ public static void TestCommandFromCore() } } - /// Test is disabled since we do not have a CimCmdlets module released in the SDK. - [SkippableFact] public static void TestCommandFromMMI() { + // Test is disabled since we do not have a CimCmdlets module released in the SDK. Skip.IfNot(Platform.IsWindows); using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) { @@ -68,7 +67,6 @@ public static void TestCommandFromMMI() } } - [SkippableFact] public static void TestCommandFromDiagnostics() { @@ -124,18 +122,18 @@ public static void TestCommandFromNative() string command = $"New-Item -ItemType SymbolicLink -Path {path} -Target {target}"; var results = ps.AddScript(command).Invoke(); - foreach(var item in results) + foreach (var item in results) { Assert.Equal(path, item.FullName); } } - if(File.Exists(path)) + if (File.Exists(path)) { File.Delete(path); } - if(File.Exists(target)) + if (File.Exists(target)) { File.Delete(target); } From 22ad731a2fb85bcc061bb1c50dc8fdda2cd3e77f Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 14 Aug 2018 13:11:41 -0700 Subject: [PATCH 3/5] [Feature] Address Steve's comments --- test/hosting/test_HostingBasic.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/hosting/test_HostingBasic.cs b/test/hosting/test_HostingBasic.cs index c0f2875d86e..164f1f02aae 100644 --- a/test/hosting/test_HostingBasic.cs +++ b/test/hosting/test_HostingBasic.cs @@ -119,6 +119,7 @@ public static void TestCommandFromNative() using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) { + // New-Item -ItemType SymbolicLink uses libpsl-native, hence using it for validating native dependencies. string command = $"New-Item -ItemType SymbolicLink -Path {path} -Target {target}"; var results = ps.AddScript(command).Invoke(); From 62446c9bd1f39606549ad91f323bdc22e1d2f473 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 16 Aug 2018 14:16:24 -0700 Subject: [PATCH 4/5] Update Microsoft.PowerShell.Native version for RC1 --- .../System.Management.Automation.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/System.Management.Automation.csproj b/src/System.Management.Automation/System.Management.Automation.csproj index 3b9277a0506..2c8fec76813 100644 --- a/src/System.Management.Automation/System.Management.Automation.csproj +++ b/src/System.Management.Automation/System.Management.Automation.csproj @@ -22,7 +22,7 @@ - + From 28fdb9d72970e8e94dd4c7ddb89ccecdae286eda Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 16 Aug 2018 15:02:52 -0700 Subject: [PATCH 5/5] [Feature]