-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Platform should return cross platform values under PSUserAgent #4945
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
Conversation
| { | ||
| return ("Windows NT"); | ||
| OperatingSystem osInfo = Environment.OSVersion; | ||
| return (osInfo.Platform.ToString()); |
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 wont work. System.Platformid does not contain commonly accepted values for the platform part of a User-Agent header. For example, macOS should be Macintosh and all (recent) Windows should be Windows NT, and most Linux should be Linux or X11.
|
|
||
| } | ||
|
|
||
| It "User Agent should reflect current plafformID" { |
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 test should be in test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
|
|
||
| It "User Agent should reflect current plafformID" { | ||
| $bingdings = [System.Reflection.BindingFlags]::NonPublic -bxor [System.Reflection.BindingFlags]::Static | ||
| $platform = [Microsoft.PowerShell.Commands.PSUserAgent].GetProperty('Platform',$bingdings).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.
We should probably not use reflection. Instead we should make a web call and ensure the User-Agent request header contains the desired data.
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
Lines 456 to 467 in b07f24e
| It "Invoke-WebRequest returns User-Agent" { | |
| $uri = Get-WebListenerUrl -Test 'Get' | |
| $command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 5" | |
| $result = ExecuteWebCommand -command $command | |
| ValidateResponse -response $result | |
| # Validate response content | |
| $jsonContent = $result.Output.Content | ConvertFrom-Json | |
| $jsonContent.headers.'User-Agent' | Should MatchExactly '(?<!Windows)PowerShell\/\d+\.\d+\.\d+.*' | |
| } |
|
@chunqingchen Sorry, It is dup of #4937 |
|
@chunqingchen I will close this PR as it's a duplicate of #4937 |
resolve #4913
Repro:
$bingdings = [System.Reflection.BindingFlags]::NonPublic -bxor [System.Reflection.BindingFlags]::Static
[Microsoft.PowerShell.Commands.PSUserAgent].GetProperty('Platform',$bingdings).GetValue($null,$null)
Before fix:
the returned string is fixed to "WindowsNT"
After fix:
the returned string is the current OS's platformID