Commit graph

51 commits

Author SHA1 Message Date
Steve Lee 2ae0e4d9dd
Update ServerRemoteHost Version to be same as PSVersion (#15809) 2021-08-04 15:01:18 -07:00
Steve Lee 6d7fbed02b
Suppress Write-Progress in ConsoleHost if output is redirected and fix tests (#14716) 2021-02-08 09:42:53 -08:00
Paul Higinbotham caff9011af
Disable libmi dependent tests for macOS. (#14446) 2020-12-16 17:35:35 -08:00
xtqqczze f4382202ae
Use correct casing for cmdlet name and cmdlet parameter name in *.ps1 files (#12584) 2020-05-07 17:00:30 +05:00
Steve Lee b7cb335f03
Update copyright notice to latest guidance (#12190) 2020-03-24 11:08:37 -07:00
James Truher [MSFT] 349783fe36
Make sure to test whether we skip a test using consistent logic (#11892) 2020-02-19 14:20:35 -08:00
Aditya Patwardhan a578347b5a
Update Get-PlatformInfo helper and tests for Debian 10, 11 and CentOS 8 (#11842) 2020-02-12 18:35:24 -08:00
xtqqczze 920b671fb4 Unify pester test syntax for the arguments of -BeOfType (#11558) 2020-01-24 11:00:37 -08:00
xtqqczze 94a73caa41 Correct case of $IsWindows special variable 2020-01-13 19:27:21 +00:00
xtqqczze 47a3b4e293 Correct case of $true special variable 2020-01-13 19:25:09 +00:00
xtqqczze 4f5bb46268 Remove BOM, insert newline at EOF 2020-01-13 18:36:47 +00:00
xtqqczze 743983390e Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace

```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```

* Capitalise and apply hyphen to 'Not' parameter

```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```

* Capitalise and apply hyphen to 'Be' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```

* Capitalise and apply hyphen to 'BeExactly' parameter

$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'

* Capitalise and apply hyphen to 'BeGreaterThan' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```

* Use 'BeTrue' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```

* Use 'BeFalse' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```

* Capitalise and apply hyphen to 'Match' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```

* Capitalise and apply hyphen to 'Throw' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```

* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```

* Capitalise 'Because' parameter

```powershell
$_ -ireplace '\s-because\b',' -Because'
```

* Fix 'BeNullOrEmpty'
2020-01-11 20:41:59 +05:00
Paul Higinbotham b19e2b9d4c Various test fixes for debugger and remoting (#11528) 2020-01-08 16:23:38 -08:00
Paul Higinbotham f22bad1d58 Fix SSH remoting test to work on all platforms (#11500) 2020-01-07 14:01:06 -08:00
Paul Higinbotham e81bd1dfda Re-add check for Invoke-Command job dispose. (#11388) 2019-12-20 12:13:34 -08:00
Patrick Meinecke beb8b44420 Use type conversion in SSHConnection hashtables when value doesn't match expected type (#10720)
Before the change if the hashtable value does not match the expected type exactly, an exception is thrown stating that the value was null.
2019-10-15 22:16:49 +05:00
James Truher [MSFT] 3943f18c28 Alpine validation changes (#10428) 2019-08-24 11:35:34 -07:00
Steve Lee b63696572f Fix skipping of tests in RemoteSession.Basic.Tests.ps1 (#9304)
Moved check if able to write to $PSHome as way to skip test to `BeforeAll` which already contained a check if running on Windows.

## PR Context

As part https://github.com/PowerShell/PowerShell/pull/9279, tests were updated to be skipped if the test requires writing to `$PSHome` but is not able to.  However, these tests already had a skip mechanism in place so the additional check caused the test to run when it should have skipped.

Co-authored-by: Travis Plunk <github@ez13.net>
2019-04-05 17:00:41 -07:00
Steve Lee b8317de469 Update tests to account for when $PSHOME is readonly (#9279)
Co-Authored-By: SteveL-MSFT <slee@microsoft.com>


Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
2019-04-04 23:01:01 -07:00
Paul Higinbotham 06571637e4 Add SkipCA and SkipCN check requirement to WinRM/OMI HTTPS connection (#8279) 2018-11-27 16:16:00 -08:00
Travis Plunk 79f21b41de
Consolidation of all Windows PowerShell work ported to PSCore6 (#8257)
Consolidation of all Windows PowerShell work ported to PSCore6

* Added ps1 file import restriction.  Refactored InvokeLanguageModeTestingSupportCmdlet to HelpersSecurity module
* JEA loop back fix.  Debugger running commands in CL mode.
* Support for new AMSI codes.  Changed to use AMSI buffer API.  Unhandled exception fix.
* Fixes for module bugs while running in ConstrainedLanguage mode
* Untrusted input tracking work
* Configuration keyword bug fix, PSRP protocol version check for reconstruct reconnect, Sharing InitialSessionState in runspace pool.
* Restricted remote session in UMCI, Applocker detection collision, Help command exposing functions, Null reference exception fix.
* Added mitigation for debugger function exposure
2018-11-13 16:16:29 -08:00
Paul Higinbotham d4bf5c87bc Fix tests running in Azure DevOps (#8220) 2018-11-09 15:11:02 -08:00
Paul Higinbotham 20f3a6a337 Experimental feature: Implicit remoting batching perf improvement (#8038) 2018-10-30 09:55:39 -07:00
Dan Travison 23832e5e95 Update 'SSHConnectionInfo Class Tests' $skipTest expression to use collection semantics instead of relying on $null (which causes a type cast exception). (#7610) 2018-08-23 15:10:39 -07:00
Dan Travison 936626b7e8 Update PowerShell to reference 'psrp.1.4.5-0' on Unix build (#7350) 2018-07-25 10:04:00 -07:00
Dan Travison 5e8b23e127 Allow Basic Auth over HTTPS (#6890)
* [FEATURE] Allow Basic Auth over HTTPS

* WSManTransportManager.cs: Simplify HTTPS check
Update comment in test to refer to the right exception type.

* Disable test until limi crash fo selected connection error paths is fixed

* Use Hex format for defining the expected HRESULT
2018-06-27 15:27:41 -07:00
Klaudia Algiz 2df9aac811 Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests (#6682)
Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests.
Get rid of try { } catch { } formula to assert that errors were thrown.
Small fixes in tests to obey the new Pester -Parameter syntax.
2018-05-17 14:42:04 -07:00
Ilya 84344cbb32 Update PowerShell to build with .NET Core SDK 2.1.300-rc1-008662 (#6718)
* Build Update
- Change `TargetFramework` to `netcoreapp2.1` and removed unnecessary `RuntimeFrameworkVersion` from `PowerShell.Common.props`
- Update dotnet SDK to 2.1.300-rc1-008662
- Update `TypeGen` target in `Build.psm1` to work with 2.1
- Rename macOS runtime to `osx-x64` as the old build logic expects 10.12 and breaks running on 10.13 system.
- Remove `PackageReference` to `System.Memory` as it's part of dotnetcore 2.1
- Update search for `crossgen` executable to find the matching version

* Test Update
- Update test tools `WebListener` to latest `asp.net core`
- Marked `AuthHeader Redirect` tests as `Pending` due to change in CoreFX
2018-05-02 16:58:39 -07:00
Dan Travison 385cc1b796 Disallow Basic Auth over HTTP on Unix (#6787)
Disallow Basic Auth over HTTP on Unix

Fix: #6779
2018-05-02 14:29:10 -07:00
Klaudia Algiz 090f8761e8 Use new Pester syntax: -Parameter for Pester tests in engine. (#6298)
* Use new Pester syntax: -Parameter for Pester tests in engine.
2018-03-14 12:13:32 -07:00
Steve Lee c1c5344a88 Update copyright and license headers (#6134)
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files.

Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks.

Separate PR coming to update contribution document for new source files: #6140

Manually reviewed each change.

Fix #6073
2018-02-13 09:23:53 -08:00
Chunqing Chen dd5fba3313 Exclude PSHostProcess cmdlets from Unix platforms (#5105)
- Exclude 'Get-PSHostProcessInfo', 'Enter-PSHostProcess' and 'Exit-PSHostProcess' from Unix platforms.
- Update tests and add additional cmdlets need to be excluded
2017-10-18 09:26:24 -07:00
Aditya Patwardhan 486fb97123 Test fixes and code coverage automation fixes. (#5046)
* Test fixes and updates to code coverage automation
* Fixed UpdatableHelpSystem tests and tab completion tests
* Fixed tab completion tests to better disambiguate root/interop namespace.
* Skip SSH test if ssh.exe is not present
2017-10-13 13:54:43 -07:00
Aditya Patwardhan 1e271ea187 Add Remoting and Job tests (#4928) 2017-10-02 13:43:43 -07:00
bergmeister ffd39b2853 PSScriptAnalyzer fixes by category (#4261)
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'ForEach-Object' (alias is '%' or 'foreach')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Where-Object' (alias is '?' or 'where')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Select-Object' (alias is 'select')
- Fix PSScriptAnalyzer warnings of type PSPossibleIncorrectComparisonWithNull. Essentially, $null has to be on the left-hand side when using it for comparison.
- A Test in ParameterBinding.Tests.ps1 needed adapting as this test used to rely on the wrong null comparison
- Replace a subset of tests of kind '($object -eq $null) | Should Be $true' with '$object | Should Be $null'
2017-07-21 21:03:49 -07:00
Steve Lee af0600ded2 Fix non-fatal (red) errors in test output (#3968) 2017-06-09 16:29:59 -07:00
Lee Spottiswood 1d42862e21 Adds Port parameter for SSH PSSessions (#3499)
* fixes summary block typo

* Adds support for Port parameter for SSH PSSessions

* Reverted back to master, modified based on PR feedback

* Update exception message

* remove unused line

* Add existing constructor back in as to not break public contract

* remove port check

* pass nested inner exception straight to Should

* dispose runspace after each test

* Add SSHHostParameterSet attribute for Invoke-Command Port property

* Update ParseSSHConnectionHashTable method to accept Port value as integer

* Add helper method for validating port in range. Refactor port parameter constructor overload to use original constructor

* rename method

* Adds GetSSHConnectionStringParameter and GetSSHConnectionIntParameter methods for retrieving SSHConnection hashtable values

* Adds method comments

* Adds helper method comment

* Change methods to add C# 7 patterns
2017-04-25 18:02:16 -07:00
Dongbo Wang 7a55bf98b2 Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 11:52:38 -07:00
Ilya 27b27cc43a Autoload TestRemoting.psm1 (#3430) 2017-03-29 10:11:02 -07:00
Chunqing Chen 1393f45640 Get-Help does not work in JEA sessions (#2988) 2017-03-23 11:30:26 -07:00
Chunqing Chen 3f274aad9c make transcripts include the configuration name in the transcript header (#2890)
* PowerShell transcripts should include the configuration name in the transcript header
* adding test case for PowerShell transcripts should include the configuration name in the transcript header #2890
2017-03-15 22:06:07 -07:00
Paul Higinbotham 7cea291475 Fix Invoke-Command remote debugging test failure in nightly build (#3294) 2017-03-09 20:14:26 -08:00
Paul Higinbotham ba62cf1ea2 Fixed typos that caused test to fail. (#3268) 2017-03-06 17:26:38 -08:00
Paul Higinbotham b4cb5e95a2 Implementation for Invoke-Command step-in remote debugging (#3015)
These changes provide the ability to debug remote running scripts started with the Invoke-Command cmdlet. The design is event based and provides new public events that allow subscribers to be notified when an Invoke-Command remote session is ready for debugging. Since Invoke-Command allows running scripts on multiple targets at once (fan-out) the notification event is raised for each remote session as it becomes ready for debugging. The subscriber to these events will be a script debugger implementation (such as PowerShell console, ISE, or VSCode) and will handle all debugging details such as simultaneously debugging multiple remote sessions at once in separate windows.

But these changes also include an internal implementation which is used by default if host debuggers don't want to handle the debugging details. This internal implementation is what PowerShell console, ISE uses so they can have this new behavior without having to modify their debugger implementations. The internal implementation serializes each remote session of Invoke-Command so that they can be debugged one at a time. The remote session debugger is "pushed" onto the internal debugger stack so that debugging transitions to the remote session. Existing debugging commands work so that the "quit" debugging command will stop the current remote session script from running and allow the next remote session to be debugged. Similarly the "continue" debugging command allows the script to continue running outside step mode and again go to the next remote session for debugging. The "stepout" debugging command steps out of all Invoke-Command remote sessions and lets the script continue to run for each remote session in parallel as they are normally run.

The purpose of Invoke-Command step-in remote debugging is allow seamless debugging of a local script that calls Invoke-Command on remote targets. But there is also a new Invoke-Command "-RemoteDebug" parameter that lets you Invoke-Command on the command line and have it drop directly into the debugger.

An example from the PowerShell command line looks like this:
```
PS C:\> C:\TestICM.ps1
Entering debug mode. Use h or ? for help.

Hit Command breakpoint on 'Invoke-Command'

At C:\TestICM.ps1:2 char:1
+ Invoke-Command -cn $computerName,paulhig-3 -File c:\LinuxScript.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[DBG]: PS C:\>> list

    1:  $computerName = "localhost"
    2:* Invoke-Command -cn $computerName,paulhig-3 -File c:\LinuxScript.ps1
    3:  "Test Complete!"

[DBG]: PS C:\>> stepin
At line:1 char:1
+ Write-Output "Running script on Linux!"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[paulhig-3]:[DBG]: [Process:14072]: [Runspace5]: PS C:\Users\paulhi\Documents>
```

Notice that the debugger "stepin" command transitioned from local script debugging to debugging the remote session on computer "paulhig-3", as can be seen by the change in the debugger prompt.

You can also do this from the command line to drop directly into the debugger
```
Invoke-Command -cn localhost -Script  $scriptblock -RemoteDebug
```

These changes also remove an old behavior that was incompatible with this new step-in feature. Previously if a remote session running script hit a break point it would stop in the debugger and go to the "disconnected session" state. This was to allow the user to reconnect using Enter-PSSession and then interactively debug the remote session script. This behavior has been removed and now the user needs to attach a debugger using the newer Debug-Runspace cmdlet.
2017-03-01 10:28:25 -08:00
Ilya 409ab7443f Fix GetType() bad pattern and related issues in tests (#3134)
* Fix GetType() bad pattern and related issues in tests

$var.GetType() can raise an exception in tests so we should check $var
before make the call. A large part of the tests does not make this
check.
I start with searching ".GetType()" but discovered many related issues
in tests (reduntant and unneeded tests, "throw" bad pattens, bugs,
formattings (sorry!) and so on) - I had to fix them too.

* Fix after code review
* Second wave of migration GetType() -> BeOfType
Removed 'GetType().Name' patterns.
2017-02-15 16:40:51 -08:00
Paul Higinbotham ca12001c8d Implement RoleDefinitions RoleCapabilityFiles keyword (#3067)
* Changes to implement remote endpoint RoleDefinition RoleCapabilityFiles keyword
* Fixed spelling error.  Added back missing resource string
* Updated tests from CR comments
* Simplified error tests per Code Review
* Test change from Code Review
2017-02-14 10:42:17 -08:00
Jason Shirk 02b5f357a2 Remove trailing whitespace (#3001) 2017-01-16 13:31:14 -08:00
Dongbo Wang 2fe10558a2 Add basic test to make sure 'New-PSSession' doesn't crash powershell 2016-12-06 11:33:07 -08:00
Paul Higinbotham d2bf6294ab SSH remoting cmdlet parameter set changes based on RFC 0010 (#2710)
* RFC 0010 SSH remoting cmdlet updates.

* Tweaks to SSH remoting cmdlets

* SSHTransport parameter is now optional instead of mandatory.  Aded fix for CoreCLR entry point when hosted in SSH as a subsystem.

* Added tests

* Code review feedback

* Code review comment changes

* Making SSHTransport switch parameter mandatory because otherwise existing Invoke-Command parameter set

* The new SSH parameter set was causing legacy positional based parameters to no longer work. This fix separates the SSH parameter sets from the existing WinRM parameter sets.

* Fixed region name spelling error.
2016-12-02 14:01:08 -08:00
James Truher [MSFT] 3f99de5784 Added tests to close code coverage in CIM area (#2528)
* Added tests to close code coverage in CIM area

Added CimAdapter.Tests for adaptation layer (code cribbed from BVT tests)
Added SessionOption.Tests.ps1 (Code cribbed from BVT tests)
Modified CimClass tests by adding more tests
Added CimSession.Tests for basic tests of New-CimSession cmdlet
Added CimInstance.Tests for basic tests of Get-CimInstance

* Add CI tags to tests

* unify test execution to use try/catch for marking tests as skipped

moved test which retrieves cimclass via method to feature as it is not
a common operation, this test can take some time as well
2016-11-17 11:46:07 -08:00