Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/AppInstallerCLITests/HttpClientHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <winget/Certificates.h>
#include <winget/HttpClientHelper.h>
#include <CertificateResources.h>
#include <winget/JsonUtil.h>

using namespace AppInstaller::Http;
using namespace AppInstaller::Runtime;
Expand Down Expand Up @@ -79,3 +80,12 @@ TEST_CASE("HttpClientHelper_PinningConfiguration", "[RestSource]")

REQUIRE_THROWS_HR(helper.HandleGet(L"https://github.com"), APPINSTALLER_CLI_ERROR_PINNED_CERTIFICATE_MISMATCH);
}

TEST_CASE("HttpClientHelper_CallerCharacters", "[RestSource]")
{
HttpClientHelper::HttpRequestHeaders headers;
headers.emplace(web::http::header_names::user_agent, AppInstaller::JSON::GetUtilityString(AppInstaller::Runtime::GetUserAgent("\xe6\xb5\x8b\xe8\xaf\x95")));

HttpClientHelper helper;
REQUIRE_THROWS_HR(helper.HandleGet(L"https://github.com", headers), APPINSTALLER_CLI_ERROR_RESTAPI_UNSUPPORTED_MIME_TYPE);
}
4 changes: 3 additions & 1 deletion src/AppInstallerCommonCore/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,11 @@ namespace AppInstaller::Runtime

Utility::LocIndString GetUserAgent(std::string_view caller)
{
auto escapedCaller = winrt::Windows::Foundation::Uri::EscapeComponent(Utility::ConvertToUTF16(caller));

std::ostringstream strstr;
strstr <<
caller <<
Utility::ConvertToUTF8(escapedCaller) <<
" WindowsPackageManager/" << GetClientVersion() <<
" DesktopAppInstaller/" << GetPackageVersion();
return Utility::LocIndString{ strstr.str() };
Expand Down