Skip to content

Conversation

@chunqingchen
Copy link
Contributor

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

{
return ("Windows NT");
OperatingSystem osInfo = Environment.OSVersion;
return (osInfo.Platform.ToString());
Copy link
Contributor

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" {
Copy link
Contributor

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)
Copy link
Contributor

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.

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+.*'
}

@iSazonov
Copy link
Collaborator

@chunqingchen Sorry, It is dup of #4937

@daxian-dbw
Copy link
Member

@chunqingchen I will close this PR as it's a duplicate of #4937

@daxian-dbw daxian-dbw closed this Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User Agent Statically Reports "Windows NT" as the platform.

4 participants