Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ internal static string Platform
{
get
{
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.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ Describe "Environment-Variables" -Tags "CI" {
$ENV:TESTENVIRONMENTVARIABLE | Should Be $expected

}

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

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

$platform | Should BeExactly $PSVersionTable.platform
}
}