-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Change UserAgent App WindowsPowerShell -> PowerShell #4914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change UserAgent App WindowsPowerShell -> PowerShell #4914
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -720,7 +720,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |||
$result = ExecuteRequestWithOutFile -cmdletName "Invoke-WebRequest" -uri $uri | |||
$jsonContent = $result.Output | ConvertFrom-Json | |||
$jsonContent.headers.Host | Should Be $uri.Authority | |||
$jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$jsonContent.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match would work with WindowsPowerShell
as well. This should be ^PowerShell
.
In addition to that, it should be MatchExactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User-Agent can be PowerShell/6.0.0-Beta.8
or PowerShell/6.0.0
- so if we use MatchExactly the pattern should be "^PowerShell/\d+\.\d+\.\d+.*"
We use the pattern many times - it make sense to use a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was doing an imprecise partial match before.
It's actually more like Mozilla/5.0 (Windows NT; Microsoft Windows 10.0.15063 ; en-US) WindowsPowerShell/6.0.0
and it will be more dynamic "soon"
we could pull the exact one through reflection in BeforeAll
. Honestly, I'm not even sure this is a good test. Should Be $uri.Authority
should be sufficient, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@@ -1322,7 +1322,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
$result = ExecuteWebCommand -command $command | |||
|
|||
# Validate response | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -1334,7 +1334,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
|
|||
# Validate response | |||
$result.Output.headers.Host | Should Be $Uri.Authority | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -1347,7 +1347,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
|
|||
# Validate response | |||
$result.Output.headers.Host | Should Be $uri.Authority | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -1360,7 +1360,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
|
|||
# Validate response | |||
$result.Output.headers.Host | Should Match $uri.Authority | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -1435,7 +1435,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
$result = ExecuteWebCommand -command $command | |||
|
|||
# Validate response | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -1497,7 +1497,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
|
|||
# Validate response | |||
$result.Output.url | Should Match $uri | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -1525,7 +1525,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
|
|||
# Validate response | |||
$result.Output.url | Should Match $uri | |||
$result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$result.Output.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -1560,7 +1560,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |||
$result = ExecuteRequestWithOutFile -cmdletName "Invoke-RestMethod" -uri $uri | |||
$jsonContent = $result.Output | ConvertFrom-Json | |||
$jsonContent.headers.Host | Should Be $uri.Authority | |||
$jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$jsonContent.headers.'User-Agent' | Should Match "PowerShell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
Test fails due to #4919 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment
@@ -421,6 +421,9 @@ $PendingCertificateTest = $false | |||
if ( $IsMacOS ) { $PendingCertificateTest = $true } | |||
if ( test-path /etc/centos-release ) { $PendingCertificateTest = $true } | |||
|
|||
# Get the default UserAgent through reflection | |||
$DefaultUserAgent = [Microsoft.PowerShell.Commands.PSUserAgent].GetProperty('UserAgent',@('Static','NonPublic')).GetValue($null,$null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is dummy test: if C# code will be changed the test will be automatically passed. I believe we should use explicit desired pattern.
Also please move to BeforeAll
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the purpose of the tests. They are just testing the response from the server to ensure that expected data sent is also returned. if we want to test the patterns in the UserAgent, that would be a separate set of tests for the PSUserAgent
class.
I will add a separate describe block for PSUserAgent
tests and a test for the App
member (there will be other tests possibly for #4193). I will create a separate issue to add and track adding other tests for PSUserAgent
.
Describe "PSUserAgent Tests" { | ||
It "App Should Match ^PowerShell/\d+\.\d+\.\d+.*" { | ||
$ 9E12 app = [Microsoft.PowerShell.Commands.PSUserAgent].GetProperty('App',@('Static','NonPublic')).GetValue($null,$null) | ||
$app | Should Match '^PowerShell/\d+\.\d+\.\d+.*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I don't see the point of checking internal property - we are free to change (add/remove) internals in any time. We should test public API. Here "public API" is User-Agent which we send to a server and get it back. We should test the User-Agent format if we want to control the User-Agent. So it is good to use regex pattern. I think that check User-Agent 14 times it's redundant - we need to have one check for each web cmdlet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, the point of most of those tests is not to test the User-Agent that is sent. Most of those assertions are being used to ensure meaningful data is returned in a response after a set of parameters has been used to make web requests. The only reason I updated them at all was because the change from WindowsPowerShell
to PowerShell
would have caused all these tests to false fail.
I will change the two tests that are explicitly about the User-Agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mentioned $uri.Authority
is sufficient. So I'd remove $DefaultUserAgent
at all. I unlike it as you see 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with that. This entire file needs to be more deeply analyzed and cleaned up. Maybe after I'm done making radical changes to it every day 😆.
Remove all assertions for User-Agent that are not specifically about the User-Agent header.
@@ -463,7 +463,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |||
|
|||
# Validate response content | |||
$jsonContent = $result.Output.Content | ConvertFrom-Json | |||
$jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell" | |||
$jsonContent.headers.'User-Agent' | Should Match '(?<!Windows)PowerShell\/\d+\.\d+\.\d+.*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might use MatchExactly
which does a case sensitive match (-cmatch
). Especially since you're explicitly not matching WindowsPowerShell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fixes #4911
PowerShell