Commit graph

46 commits

Author SHA1 Message Date
Aditya Patwardhan 15f6abe944 Added functionality to retry in Invoke-RestMethod and Invoke-WebRequest. (#5760)
Added two parameters, RetryCount and RetryIntervalSec to enable retry functionality. When retrying a verbose message is sent out to inform the user.
2018-06-29 09:06:53 +05:00
Dan Thompson ce3cb68551 Make Select-Object/ForEach-Object/Where-Object see dynamic properties (#6898)
Dynamic (DLR) objects work in some places today, but not others.  This change expands that support to ForEach-Object, Where-Object and the family of cmdlets that use 'MshExpression' (Select-Object, etc.).

This change addresses both wildcard and non-wildcard cases. In wildcard cases, it uses the existing support of generating PSDynamicMember objects for names returned by GetDynamicMemberNames.

In non-wildcard cases, a dynamic property access is attempted whether or not the name shows up in GetDynamicMemberNames, but a truly "blind" access is only attempted if we see that the base object is an IDMOP. If the dynamic access fails, you'll get the same or a similar error experience as before ("The property 'Blarg' cannot be found", or no error at all, depending on the cmdlet and the strict mode setting).

The included test coverage includes a stub for the.ForEach operator--once people are happy with this change, I can continue by adding support there.

This change should allegedly also have positive perf impact, though in actual perf testing, although it does seem ever-so-slightly faster, I found it difficult to measure much difference at all.
2018-06-12 23:48:34 -07:00
Christoph Bergmeister fa544c33db Update links that contain 'en-us' culture (#7013)
Update links that contain 'en-us' culture to remove 'en-us' culture (if possible) and in some cases update to newer re-directed link to docs.microsoft.com
2018-06-08 10:49:03 +05:00
Klaudia Algiz facb228451 Remove ShouldBeErrorId custom function. (#6891) 2018-05-23 07:57:03 +05:00
Dan Travison ec0f1116db Add PowerShell logging tests for macOS and Linux (#6025)
This PR fixes the logging issue on Linux where logging is initialized before `-settingsFile` is parsed causing custom log settings to be ignored. (see ConsoleHost.cs and ManagedEntrance.cs)

The PR also includes basic logging tests for Linux and MacOS. PSSyslog.psm1 contains the functions to retrieve selected logged items (based on PowerShell's log id and a timestamp) and Logging.Tests.ps1 contains tests for Linux and MacOS.
2018-03-29 14:46:08 -07:00
Mark Kraus d20d53eaac Add -Resume Feature to Web Cmdlets (#6447)
Fixes #5964

Adds -Resume switch to Invoke-WebRequest and Invoke-RestMethod

-Resume requires -OutFile

Enables the ability to resume downloading a partially or incompletely downloaded file.

File Size is the only indicator of local and remote file parity.

If the local file is smaller than the remote file and the remote endpoint supports resume, the local file will be appended with the remaining bytes.

If the local file is larger than the remote file, the local file will be overwritten

If the remote server does not support resume, the local file will be overwritten

If the local file is the same size as the remote file, the remote endpoint will return a 416 status code. This response is special-cased as a success in this instance. The local file remains untouched and it is assumed the file was already successfully downloaded previously.

If the local file does not exist it will be created and the entire remote file will be requested.

Added tests for all code new code paths (I'm pretty sure anyway)

Added /Resume Controller to WebListener

Documented /Resume Controller

Updated .spelling to reflect terms in WebListener docs

Note: I had to change the way GetResponse() tracks the current URI as we now have 3 places where the call is taking place. I don't foresee this causing any regressions. This area needs some refactoring. especially if we want to implement a retry mechanism
2018-03-26 12:23:24 -07:00
James Truher [MSFT] 30e9e309dc Rename some tests because they are duplicates (#6312)
Also remove a couple of language tests which were actually duplicated
Change the one loop which loops through test cases to include an iteration number to remove test name duplication
2018-03-07 10:25:49 -08: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
Mark Kraus 7d003f4f67 Change Web Cmdlet Tests to Use 127.0.0.1 not Localhost (#6069)
Change Web Cmdlets Tests to Use 127.0.0.1 instead of localhost due to dotnet/corefx#24104
This provides a decent speed boost to the WebCmdlet tests (Faster in dozens of times).
2018-02-01 08:26:05 +04:00
Mark Kraus 47c4a0a74b Test: Add Verbosity and more accurate timeout implementation for Start-WebListener (#6013)
- Add verbosity to the WebListener when it fails to assist in troubleshooting
- Switch the WebListener initialization timeout to count cycles instead of using fixed dates to work around possible VM CI sleep/ issues.
2018-01-31 14:55:16 -08:00
Mark Kraus 3f9564e665 Replace HttpListener Link Header Tests with WebListener (#5806)
- Add Link controller to WebListener
- Replace HttpListener Link tests with WebListener
- Update WebListener Documentation
- Enable cross-platform multiple Link header tests
2018-01-16 09:23:22 -08:00
Mark Kraus 19197e11f3 Replace Remaining HttpBin.org Tests with WebListener (#5665)
•Replaces all remaining test that rely on httpbin.org
•Adds Put, Post, Patch, and Delete tests to WebListener by means of routes to Get test and modifications to the Get controller.
•Adds responsephrase option to the Response test to accommodate error message tests
•removed redundant GET tests from irm and iwr tests.
•Fixed markdown linting errors in README.md for WebListener
2017-12-13 19:28:05 +04:00
Mark Kraus 95a8a64260 Replace HttpListener Response Tests with WebListener (#5540)
* Add Response Controller

* [Feature] Replace HttpListener Response tests with WebListener
2017-12-04 09:52:14 -08:00
Mark Kraus ecf0f8c151 Add SslProtocol Support to WebCmdlets (#5329)
closes #2662

This feature adds the ability to restrict the SSL/TLS protocol used when making the web request. In 5.1 the user could make use of .NET API's to enforce this on the Web Cmdlets. With the move to HttpClient in PowerShell Core, those APIs have no impact. The user still has requirements to ensure specific protocols are used.

The public enum WebSslProtocol is added as a wrapper to the underlying SslProtocols enum. Neither it nor SecurityProtocolType can be used because Ssl3 and Ssl2 are not supported by HttpClientHandler.SslProtocols. While it may not be intuitive to a PowerShell user to use -bor or "Tls, Tls11" to set multiple options, the general use case for this will be a single protocol.

Adds -SslProtocol parameter to Web Cmdlets
Adds WebSslProtocol Enum to support limited subset of SslProtocol enum supported by HttpClientHandler
Adds TLS 1.1 and TLS 1.0 listening ports to WebListener
2017-11-13 10:45:46 -08:00
Mark Kraus ee7edb7427 Add error on Legacy Credential over non-HTTPS for Web Cmdlets (#5402)
- Add an error when a user tries to use `-Credential` (legacy usage without `-Authentication`) or `-UseDefaultCredentials` over a non-HTTPS URI
- User can bypass error with `-AllowUnencryptedAuthentication`
- `-UseDefaultCredentials` can only be reliably tested on Windows as support on other platforms depends on a Kerberos infrastructure. 
- Add `/Auth/` tests to WebListener for challenge authentication Basic, Negotiate, and NTLM

Incidentally, this increases test coverage for the web cmdlets as `-Credential` and `-UseDefaultCredentials` were not being tested.
2017-11-10 08:11:57 -08:00
Dongbo Wang 3771c88da3
Always run test with crossgen'ed assemblies in CI (#5315) 2017-11-02 18:03:34 -07:00
James Truher [MSFT] d43b2cf958 Remove DCOM support from *-Computer cmdlets (#5277)
Since DCOM is not supported in corefx there was a great deal of dead code in the computer cmdlets.
This PR removes all vestiges of DCOM support from:

- Rename-Computer
- Restart-Computer
- Stop-Computer

removing about 4500 lines of dead code. Also, tests are updated to provide more complete coverage.
I also removed test-connection completely to make way for @iSazonov upcoming PR to improve coverage in tests, I created some test hook code which will test the cmdlet code without actually calling the WMI method to restart/rename/stop the system
2017-11-01 10:59:41 -07:00
Steve Lee 4bc52d2358 Use consistent '(c)' for copyright symbol (#5210)
- Remove the year about copyright
- Fix casing of `All rights reserved`
- Replace Unicode characters representing single quote with a single quote
2017-10-26 14:12:19 -07:00
Mark Kraus b4e8e9d06b Replace HttpBin.org/response-headers Tests with WebListener (#5058) 2017-10-18 12:24:02 -07:00
Mark Kraus 15a6c5748b Replace httpbin.org/gzip Tests with WebListener and Re-Enable Deflate Tests (#4948)
* Add Gzip and Deflate Support to WebListener

* [Feature] Run Feature tests

* [Feature] Address PR Feedback

* [Feature] Re-Run CI

* [feature] Update WebListener Index page

* [Feature] Run Feature tests

* [Feature] Re-run CI
2017-10-02 13:46:53 -07:00
Aditya Patwardhan 1e271ea187 Add Remoting and Job tests (#4928) 2017-10-02 13:43:43 -07:00
Steve Lee 2639cd89ce Autocorrected CRLF to LF (#4943)
Also, fix `Parser.Tests.ps1` after correcting CRLF.
2017-09-29 16:28:15 -07:00
Mark Kraus dd02aac3d7 [feature] Fix TestValue to avoid double // in Urls (#4920)
•Adds logic in  Get-WebListenerUrl  to only apply the  TestValue  part of the path if it was supplied.
2017-09-26 09:05:55 +04:00
Mark Kraus b30da378e7 Replace httpbin.org/delay Tests with WebListener (#4905) 2017-09-25 12:50:15 -07:00
Mark Kraus 65cf571b54 Replace httpbin.org/encoding Tests with WebListener (#4869) 2017-09-22 10:09:49 -07:00
Paul Higinbotham 7c8b7eff52 Port tests for constrained language mode (#4816)
* Port tests for constrained language mode
* Added 'RequireAdminOnWindows' for registry access
* Restored Wait-UntilTrue to current state
2017-09-19 14:53:29 -07:00
Mark Kraus a2dd0ca4b5 Replace httpbin.org/redirect Tests with WebListener (#4852) 2017-09-18 09:26:01 -07:00
Steve Lee 4ad313aafb Add tests for Get-Module over remoting (#4787)
Some additional tests that are remoting specific based on code coverage
2017-09-12 17:12:52 -07:00
Dongbo Wang c06ffc4a5c Add a generic file watcher function in HelpersCommon.psm1 (#4775)
Add a generic file watcher function in HelpersCommon.psm1 and update some tests to use the `Wait-FileToBePresent`.
2017-09-12 13:05:47 -07:00
Mark Kraus fd3a003765 Add Multipart Support to Web Cmdlets (#4782)
Partially implements  #2112
- Adds `System.Net.Http.MultipartFormDataContent` as a possible type for `-Body`
- Adds `/Multipart/` test to WebListener 

This allows for the user to create their own `Http.MultipartFormDataContent` object and submit it. Since `multipart/form-data` submissions are highly flexible, adding direct support for it to the CmdLets may over-complicate the command parameters and a limited implementation would not address the broad scope of use cases. This at least allows the user to submit multipart forms using the Web Cmdlets and not have to manage their own `HttpClient`. Once this is introduced, limited multipart implementations can be expanded to use the code in this PR.
2017-09-12 09:41:36 -07:00
Mark Kraus f41461825a Replace httpbin.org/get tests With WebListener (#4738)
* Adds the /Get/ functionality to Weblistener
* Replaces the tests that rely on httpbin.org/get with WebListener


* [Feature] Move HttpBin/Get Tests to WebListener

* [Feature] update .spelling

* [Feature] Address PR Feedback

* [Feature] Add and document Home & /

* Readme Update

* [Feature] Should Match -> Should Be

Rerun CI

* [Feature] Rebase and Rerun CI
2017-09-08 07:53:04 +04:00
Steve Lee 7c9b188c13 Rename $IsOSX to $IsMacOS (#4757) 2017-09-07 10:34:40 -07:00
James Truher [MSFT] e0b7c23384 Report the same number of tests when run by Travis via cron (#4731) 2017-08-31 15:03:20 -07:00
Mark Kraus 3b2d169c5e Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622)
Introduce new test module 'WebListener.psm1'.
Now web HTTPS tests can use it to exclude using external sites.

PowerShell/PowerShell#4609

* [Feature] Add Tests for Web Cmdlet Certificate Authentication

PowerShell/PowerShell#4609

* [feature] Add new app to Publish-PSTestTools refactor tests

also add ASP.NET to .spelling

* [feature] spelling fix

* [feature] revert badssl changes

* [feature] Impliment suggestions

* [feature] Spelling, var rename, port 8443 to 8083

rebase fix conflict

* [feature] Rename to HttpsListener and Module-ize

.

* [feature] password protect ClientCert to fix macOS import issue

* [feature] Rename to WebListener 

* Rename HttpsListener to WebListener
* Switch Listener from Razor pages to MVC
* Address PR feedback
* Adjust tests

* [feature] Address PR feedback

* [feature] Replace missing smeicolons

* [feature] Address PR Feedback

* [feature] Cleanup and minor fix

* Enum was not used
* GetStatus() was not accessing the correct property chain
* Added -Test param to make URL generation smoother in test code and to fix double / issues

* [feature] More minor fixes

* Https when it matters.
* Expand property... not exclude..
* Remove superfluous and outdated ToString() override

* [Feature] Move ClientCeret.pfx to WebListener Module

* Move the cert
* Adjust Get-WebListenerClientCertificate 
* Remove cert from csproj
* ActionResult -> JsonResult (was mistakenly left as ActionResult during testing)..

* [Feature] Move ServerCert.pfx to Module

* Move cert
* Upate csproj
* Update module
* Add/Update README.md's

CI Retest.
2017-08-31 13:30:35 +04:00
Mark Kraus 297bba3fa1 Add support for Content Headers to BasicHtmlWebResponseObject and HtmlWebResponseObject (#4494) 2017-08-21 10:48:25 -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 b70460fb93 updated webcmdlets CI tests to not depend on external website (#4279)
* updated webcmdlets CI tests to not depend on external website

* When used in background runspace, validate listener is working before returning

* fix possible infinite loop waiting for listener to start
2017-07-18 12:33:40 -07:00
Dan Travison ea758a53af Add -SkipHeaderValidation switch to Invoke-WebRequest and Invoke-RestMethod to support adding headers without validating the header value. (#4085)
* Add -SkipHeaderValidation switch to Invoke-WebRequest and Invoke-RestMethod to support adding headers without validating the header value.

* Fix whitespace
2017-07-14 10:24:20 -07:00
Dan Travison 039ed6764d Strip authorization header on redirects with web cmdlets (#3885)
Invoke-WebRequest and Invoke-RestMethod cmdlets will now strip authorization header on redirect unless the new parameter `-PreserveAuthorizationOnRedirect` is specified.

The FullCLR implementation uses WebRequest to perform the request which silently strips the Authorization header when a redirect occurs.

The CoreCLR implementation uses HttpClient to perform the request which does not strip the authorization header. The change explicitly handles the initial redirect, removes the authorization header and submits the request to location in the response.

Fixes #2227
2017-06-15 15:52:08 -07:00
James Truher [MSFT] bc807322ed Alter test httplistener to use a new runspace rather than a job (#3966)
This improves the performance of the listener by not relying on a new
process starting up to run the listener. It improves the debugability
of tests by providing more direct access to the session executing
the listener. It also reverses the blocking nature of starting the
listener. By default, Start-HttpListener will no longer block, you need
to use -Foreground to have Start-HttpListener block. Lastly, create
a way to catch errors if the listener has a problem. If code in the
listener throws, it emits an error record.
2017-06-09 10:12:46 -07:00
Steve Lee 40446c80a7 Support Link Header pagination in WebCmdlets (#3828)
* Support Link Header pagination in WebCmdlets to make it easier for the end user implementing:
https://github.com/PowerShell/PowerShell-RFC/blob/master/2-Draft-Accepted/RFC0021-Link-header-based-pagination-for-WebCmdlets.md

When the response includes a Link Header (https://tools.ietf.org/html/rfc5988#page-6), for Invoke-WebRequest we
create a RelationLink property that is a Dictionary representing the URLs and rel attributes and ensure the
URLs are absolute to make it easier for the developer to use.  For Invoke-RestMethod, we expose a -FollowRelLink
switch to automatically follow 'next' rel links to the end until we hit the optional -MaxRelLink parameter value.

* removed unnecessary refs to namespaces

* addressed code review feedback
2017-05-24 15:54:02 -07:00
Steve Lee f0b03bc57d Test HttpListener so that PowerShell Core tests don't have to rely on an internet web service (#3778) 2017-05-18 15:02:19 -07:00
Ilya e00161a8af Add autoload for TestLanguage.psm1 TestHelpers.psm1 (#3456)
* Add autoload for TestHelpers.psm1

Test.Helpers.psm1 was renamed to TestHelpers.psm1

* Resolve conflit and rebase Add autoload for TestLanguage.psm1

* Remove unneeded comments from PSD1 files

* Rename test modules

Remove approved verbs (Get-Verb) from module names.

* Enhance ShouldBeErrorId to output exception into pipeline for later analysis

* Remove unneeded comments

* Resolve merge conflict
2017-05-17 11:09:27 -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
Ilya a99fb531e6 Add autoload for test modules (#3342)
Related #3238

1. Add autoload for test modules
2. Move TestHostCS.psm1 to 'test\tools\Modules\' folder
3. Remove explicit load TestHostCS.psm1 from test files
2017-03-26 21:46:39 -07:00