You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
closes#6728
Breaking change approved in #6728
This PR switches the logic of when the Web Cmdlets handle redirects when the Authorization header is present. .NET Core 2.1 no longer sends the Authorization header by default (dotnet/corefx#26864). however, we introduced the ability to do so leveraging the previous default behavior through the use of the -PreserveAuthorizationOnRedirect switch.
This PR also corrects a bug introduced 6.0.0 where certain redirect types redirect from POST to GET were set which should have passed through POST to POST and some were improperly passing through POST to POST which should have been doing POST to GET. This correction is a breaking change. It was made apparent as now the redirection behavior is being managed by CoreFX which is doing the correct behavior, tests were added for both when CoreFX and the Web Cmdlets manage redirection.
It "Validates Invoke-WebRequest with -PreserveAuthorizationOnRedirect preserves the authorization header on redirect: <redirectType> <redirectedMethod>"-Pending -TestCases $redirectTests {
744
+
It "Validates Invoke-WebRequest with -PreserveAuthorizationOnRedirect preserves the authorization header on redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
# NOTE: Only testing redirection of POST -> GET for unique underlying values of HttpStatusCode.
775
775
# Some names overlap in underlying value.
776
-
It "Validates Invoke-WebRequest strips the authorization header redirects and switches from POST to GET when it handles the redirect: <redirectType> <redirectedMethod>"-Pending -TestCases $redirectTests {
776
+
It "Validates Invoke-WebRequest strips the authorization header redirects and switches from POST to GET when it handles the redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
$response.Content.Method| Should -Be $redirectedMethod
788
788
}
789
789
790
+
It "Validates Invoke-WebRequest -PreserveAuthorizationOnRedirect keeps the authorization header redirects and switches from POST to GET when it handles the redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
# ensure user-agent is present (i.e., no false positives )
797
+
$response.Content.Headers."User-Agent"| Should -Not-BeNullOrEmpty
798
+
# ensure Authorization header has been removed.
799
+
$response.Content.Headers."Authorization"| Should -BeExactly 'test'
800
+
# ensure POST was changed to GET for selected redirections and remains as POST for others.
801
+
$response.Content.Method| Should -Be $redirectedMethod
802
+
}
803
+
790
804
It "Validates Invoke-WebRequest handles responses without Location header for requests with Authorization header and redirect: <redirectType>"-TestCases $redirectTests {
791
805
param($redirectType,$redirectedMethod)
792
806
# Skip relative test as it is not a valid response type.
It "Validates Invoke-RestMethod with -PreserveAuthorizationOnRedirect preserves the authorization header on redirect: <redirectType> <redirectedMethod>"-Pending -TestCases $redirectTests {
2034
+
It "Validates Invoke-RestMethod with -PreserveAuthorizationOnRedirect preserves the authorization header on redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
# NOTE: Only testing redirection of POST -> GET for unique underlying values of HttpStatusCode.
2053
2067
# Some names overlap in underlying value.
2054
-
It "Validates Invoke-RestMethod strips the authorization header redirects and switches from POST to GET when it handles the redirect: <redirectType> <redirectedMethod>"-Pending -TestCases $redirectTests {
2068
+
It "Validates Invoke-RestMethod strips the authorization header redirects and switches from POST to GET when it handles the redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
# ensure user-agent is present (i.e., no false positives )
2061
2075
$response.Content.Headers."User-Agent"| Should -Not-BeNullOrEmpty
2062
2076
# ensure Authorization header has been removed.
2063
-
$response.Content."Authorization"| Should -BeNullOrEmpty
2077
+
$response.Content.Headers."Authorization"| Should -BeNullOrEmpty
2078
+
# ensure POST was changed to GET for selected redirections and remains as POST for others.
2079
+
$response.Content.Method| Should -Be $redirectedMethod
2080
+
}
2081
+
2082
+
It "Validates Invoke-RestMethod -PreserveAuthorizationOnRedirect keeps the authorization header redirects and switches from POST to GET when it handles the redirect: <redirectType> <redirectedMethod>"-TestCases $redirectTests {
0 commit comments