winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9d8aafc1e9ca314e54a866ba5a39ec612c553f8b
parent 9d93f82d2c80a593d396fb0c6994f660a8308fff
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date:   Tue, 27 Sep 2022 16:49:56 -0700

Fix installer renaming failure from encoded url (#2555)


Diffstat:
Msrc/AppInstallerCLICore/Workflows/DownloadFlow.cpp | 2+-
Msrc/AppInstallerCLITests/AppInstallerCLITests.vcxproj | 3+++
Msrc/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters | 3+++
Asrc/AppInstallerCLITests/TestData/InstallFlowTest_EncodedUrl.yaml | 18++++++++++++++++++
Msrc/AppInstallerCLITests/WorkFlow.cpp | 32++++++++++++++++++++++++++++++++
5 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp b/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp @@ -69,7 +69,7 @@ namespace AppInstaller::CLI::Workflow // Assuming that we find a safe stem value in the URI, use it. // This should be extremely common, but just in case fall back to the older name style. - if (filename.has_stem() && ((filename.string().size() + installerExtension.size()) < MAX_PATH)) + if (filename.has_stem() && ((filename.wstring().size() + installerExtension.size()) < MAX_PATH)) { filename = filename.stem(); } diff --git a/src/AppInstallerCLITests/AppInstallerCLITests.vcxproj b/src/AppInstallerCLITests/AppInstallerCLITests.vcxproj @@ -257,6 +257,9 @@ <CopyFileToFolders Include="TestData\Manifest-Good.yaml"> <DeploymentContent>true</DeploymentContent> </CopyFileToFolders> + <CopyFileToFolders Include="TestData\InstallFlowTest_EncodedUrl.yaml"> + <DeploymentContent>true</DeploymentContent> + </CopyFileToFolders> <CopyFileToFolders Include="TestData\InstallFlowTest_Exe.yaml"> <DeploymentContent>true</DeploymentContent> </CopyFileToFolders> diff --git a/src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters b/src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters @@ -516,6 +516,9 @@ <CopyFileToFolders Include="TestData\InstallFlowTest_Msix_DownloadFlow.yaml"> <Filter>TestData</Filter> </CopyFileToFolders> + <CopyFileToFolders Include="TestData\InstallFlowTest_EncodedUrl.yaml"> + <Filter>TestData</Filter> + </CopyFileToFolders> <CopyFileToFolders Include="TestData\InstallFlowTest_Exe.yaml"> <Filter>TestData</Filter> </CopyFileToFolders> diff --git a/src/AppInstallerCLITests/TestData/InstallFlowTest_EncodedUrl.yaml b/src/AppInstallerCLITests/TestData/InstallFlowTest_EncodedUrl.yaml @@ -0,0 +1,18 @@ +Id: AppInstallerCliTest.UrlEncodeTest +Version: 1.0.0.0 +Name: AppInstaller Test Exe Installer +Publisher: Microsoft Corporation +AppMoniker: AICLITestExe +License: Test +ProductCode: AppInstallerCliTest.TestExeInstaller +Installers: + - Arch: x64 + Url: https://EncodedUrlTest/%E6%B5%8B%E8%AF%95.exe + InstallerType: exe + Sha256: 65DB2F2AC2686C7F2FD69D4A4C6683B888DC55BFA20A0E32CA9F838B51689A3B + Switches: + Custom: /encodedUrl + SilentWithProgress: /silentwithprogress + Silent: /silence + Update: /update +ManifestVersion: 0.1.0 diff --git a/src/AppInstallerCLITests/WorkFlow.cpp b/src/AppInstallerCLITests/WorkFlow.cpp @@ -886,6 +886,38 @@ TEST_CASE("ExeInstallFlowWithTestManifest", "[InstallFlow][workflow]") REQUIRE(installResultStr.find("/silentwithprogress") != std::string::npos); } +TEST_CASE("InstallFlow_RenameFromEncodedUrl", "[InstallFlow][workflow]") +{ + TestCommon::TempFile installResultPath("TestExeInstalled.txt"); + + std::ostringstream installOutput; + TestContext context{ installOutput, std::cin }; + auto previousThreadGlobals = context.SetForCurrentThread(); + OverrideForCheckExistingInstaller(context); + context.Override({ DownloadInstallerFile, [](TestContext& context) + { + context.Add<Data::HashPair>({ {}, {} }); + auto installerPath = std::filesystem::temp_directory_path(); + installerPath /= "EncodedUrlTest.exe"; + std::filesystem::copy(TestDataFile("AppInstallerTestExeInstaller.exe"), installerPath, std::filesystem::copy_options::overwrite_existing); + context.Add<Data::InstallerPath>(installerPath); + } }); + OverrideForUpdateInstallerMotw(context); + context.Args.AddArg(Execution::Args::Type::Manifest, TestDataFile("InstallFlowTest_EncodedUrl.yaml").GetPath().u8string()); + + InstallCommand install({}); + install.Execute(context); + INFO(installOutput.str()); + + // Verify Installer is called and parameters are passed in. + REQUIRE(std::filesystem::exists(installResultPath.GetPath())); + std::ifstream installResultFile(installResultPath.GetPath()); + REQUIRE(installResultFile.is_open()); + std::string installResultStr; + std::getline(installResultFile, installResultStr); + REQUIRE(installResultStr.find("/encodedUrl") != std::string::npos); +} + TEST_CASE("InstallFlowNonZeroExitCode", "[InstallFlow][workflow]") { TestCommon::TempFile installResultPath("TestExeInstalled.txt");