From 08dbfd04f140111168a9c848e87f69f53f7ddb7f Mon Sep 17 00:00:00 2001 From: Yao Sun Date: Thu, 31 Oct 2024 23:59:05 -0700 Subject: [PATCH] ProductId and tests --- src/AppInstallerCLITests/YamlManifest.cpp | 14 ++++++++ .../Manifest/ManifestYamlPopulator.cpp | 2 ++ .../ManifestUnitTest/V1ManifestReadTest.cs | 1 + .../TestCollateral/V1_9ManifestMerged.yaml | 5 +-- src/WinGetUtilInterop/Manifest/V1/Manifest.cs | 36 +++++++++---------- .../Manifest/V1/ManifestInstaller.cs | 22 ++++++++---- 6 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/AppInstallerCLITests/YamlManifest.cpp b/src/AppInstallerCLITests/YamlManifest.cpp index deaa572c64..33b448c79c 100644 --- a/src/AppInstallerCLITests/YamlManifest.cpp +++ b/src/AppInstallerCLITests/YamlManifest.cpp @@ -1373,6 +1373,20 @@ TEST_CASE("WriteManifestWithMultipleLocale", "[ManifestCreation]") REQUIRE(generatedManifest.Localizations.size() == 2); } +TEST_CASE("WriteManifestWithMSStoreInstaller", "[ManifestCreation]") +{ + Manifest msstoreManifest = YamlParser::CreateFromPath(TestDataFile("DownloadFlowTest_MSStore.yaml")); + TempDirectory exportedDirectory{ "exported" }; + std::filesystem::path generatedManifestPath = exportedDirectory.GetPath() / "testManifestWithMultipleLocale.yaml"; + msstoreManifest.ManifestVersion = ManifestVer{ "1.1.0" }; + YamlWriter::OutputYamlFile(msstoreManifest, msstoreManifest.Installers[0], generatedManifestPath); + + REQUIRE(std::filesystem::exists(generatedManifestPath)); + Manifest generatedManifest = YamlParser::CreateFromPath(generatedManifestPath); + REQUIRE(generatedManifest.Installers[0].BaseInstallerType == InstallerTypeEnum::MSStore); + REQUIRE(!generatedManifest.Installers[0].ProductId.empty()); +} + YamlManifestInfo CreateYamlManifestInfo(std::string testDataFile) { YamlManifestInfo result; diff --git a/src/AppInstallerCommonCore/Manifest/ManifestYamlPopulator.cpp b/src/AppInstallerCommonCore/Manifest/ManifestYamlPopulator.cpp index 51379004da..ce448c09f9 100644 --- a/src/AppInstallerCommonCore/Manifest/ManifestYamlPopulator.cpp +++ b/src/AppInstallerCommonCore/Manifest/ManifestYamlPopulator.cpp @@ -310,6 +310,8 @@ namespace AppInstaller::Manifest { "InstallerUrl", [](const YAML::Node& value, const VariantManifestPtr& v)->ValidationErrors { variant_ptr(v)->Url = value.as(); return {}; } }, { "InstallerSha256", [](const YAML::Node& value, const VariantManifestPtr& v)->ValidationErrors { variant_ptr(v)->Sha256 = Utility::SHA256::ConvertToBytes(value.as()); return {}; } }, { "SignatureSha256", [](const YAML::Node& value, const VariantManifestPtr& v)->ValidationErrors { variant_ptr(v)->SignatureSha256 = Utility::SHA256::ConvertToBytes(value.as()); return {}; } }, + // No custom validation needed at field populating time since we have semantic validation later to block msstore and productId from community repo. + { "MSStoreProductIdentifier", [](const YAML::Node& value, const VariantManifestPtr& v)->ValidationErrors { variant_ptr(v)->ProductId = value.as(); return {}; } }, }; std::move(v1InstallerFields.begin(), v1InstallerFields.end(), std::inserter(result, result.end())); diff --git a/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs b/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs index 607a427082..ecff759994 100644 --- a/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs +++ b/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs @@ -384,6 +384,7 @@ private void ValidateManifestFields(Manifest manifest, TestManifestVersion manif if (manifestVersion >= TestManifestVersion.V190) { Assert.False(installer1.ArchiveBinariesDependOnPath); + Assert.Equal("fakeIdentifier", installer2.ProductId); } // Additional Localizations diff --git a/src/WinGetUtilInterop.UnitTests/TestCollateral/V1_9ManifestMerged.yaml b/src/WinGetUtilInterop.UnitTests/TestCollateral/V1_9ManifestMerged.yaml index 28e92896a4..3bf371df37 100644 --- a/src/WinGetUtilInterop.UnitTests/TestCollateral/V1_9ManifestMerged.yaml +++ b/src/WinGetUtilInterop.UnitTests/TestCollateral/V1_9ManifestMerged.yaml @@ -246,6 +246,7 @@ Installers: InstallerSha256: 69D84CA8899800A5575CE31798293CD4FEBAB1D734A07C2E51E56A28E0DF8C82 InstallerUrl: https://www.microsoft.com/msixsdk/msixsdkx64.exe InstallerType: exe - ProductCode: '{Bar}' + ProductCode: '{Bar}' + MSStoreProductIdentifier: fakeIdentifier ManifestType: merged -ManifestVersion: 1.7.0 \ No newline at end of file +ManifestVersion: 1.7.0 diff --git a/src/WinGetUtilInterop/Manifest/V1/Manifest.cs b/src/WinGetUtilInterop/Manifest/V1/Manifest.cs index 534d29af4a..811081064c 100644 --- a/src/WinGetUtilInterop/Manifest/V1/Manifest.cs +++ b/src/WinGetUtilInterop/Manifest/V1/Manifest.cs @@ -278,17 +278,17 @@ public class Manifest /// /// Gets or sets a value indicating whether the default installer behavior aborts terminal. /// - public bool InstallerAbortsTerminal { get; set; } + public bool? InstallerAbortsTerminal { get; set; } /// /// Gets or sets a value indicating whether the default installer behavior requires explicit install location. /// - public bool InstallLocationRequired { get; set; } + public bool? InstallLocationRequired { get; set; } /// /// Gets or sets a value indicating whether the default installer behavior requires explicit upgrade. /// - public bool RequireExplicitUpgrade { get; set; } + public bool? RequireExplicitUpgrade { get; set; } /// /// Gets or sets the default installer release date. @@ -303,7 +303,7 @@ public class Manifest /// /// Gets or sets a value indicating whether to display install warnings. /// - public bool DisplayInstallWarnings { get; set; } + public bool? DisplayInstallWarnings { get; set; } /// /// Gets or sets the default list of apps and features entries. @@ -318,33 +318,33 @@ public class Manifest /// /// Gets or sets the default list of installer expected return codes. /// - public List ExpectedReturnCodes { get; set; } - - /// - /// Gets or sets collection of ManifestInstaller. At least one is required. - /// - public List Installers { get; set; } - - /// - /// Gets or sets collection of additional ManifestLocalization. - /// - public List Localization { get; set; } - + public List ExpectedReturnCodes { get; set; } + /// /// Gets or sets a value indicating whether the installer is prohibited from being downloaded for offline installation. /// - public bool DownloadCommandProhibited { get; set; } + public bool? DownloadCommandProhibited { get; set; } /// /// Gets or sets a value indicating whether the install location should be added directly to the PATH environment variable. /// - public bool ArchiveBinariesDependOnPath { get; set; } + public bool? ArchiveBinariesDependOnPath { get; set; } /// /// Gets or sets the default repair behavior. /// public string RepairBehavior { get; set; } + /// + /// Gets or sets collection of ManifestInstaller. At least one is required. + /// + public List Installers { get; set; } + + /// + /// Gets or sets collection of additional ManifestLocalization. + /// + public List Localization { get; set; } + /// /// Deserialize a stream reader into a Manifest object. /// diff --git a/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs b/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs index 1f84a1da04..c6e326e3e3 100644 --- a/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs +++ b/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs @@ -35,7 +35,15 @@ public class ManifestInstaller /// /// Gets or sets the signature SHA256 for an appx/msix. Only used by appx/msix type. /// - public string SignatureSha256 { get; set; } + public string SignatureSha256 { get; set; } + + /// + /// Gets or sets the Store ProductId. Only used when InstallerType is MSStore. + /// + [YamlMember(Alias = "MSStoreProductIdentifier")] + public string ProductId { get; set; } + + // Common installer fields that may have defaults in manifest root level. /// /// Gets or sets the installer locale. @@ -131,17 +139,17 @@ public class ManifestInstaller /// /// Gets or sets a value indicating whether the installer behavior aborts terminal. /// - public bool InstallerAbortsTerminal { get; set; } + public bool? InstallerAbortsTerminal { get; set; } /// /// Gets or sets a value indicating whether the installer behavior requires explicit install location. /// - public bool InstallLocationRequired { get; set; } + public bool? InstallLocationRequired { get; set; } /// /// Gets or sets a value indicating whether the installer behavior requires explicit upgrade. /// - public bool RequireExplicitUpgrade { get; set; } + public bool? RequireExplicitUpgrade { get; set; } /// /// Gets or sets the installer release date. @@ -191,17 +199,17 @@ public class ManifestInstaller /// /// Gets or sets a value indicating whether to display install warnings. /// - public bool DisplayInstallWarnings { get; set; } + public bool? DisplayInstallWarnings { get; set; } /// /// Gets or sets a value indicating whether the installer is prohibited from being downloaded for offline installation. /// - public bool DownloadCommandProhibited { get; set; } + public bool? DownloadCommandProhibited { get; set; } /// /// Gets or sets a value indicating whether the install location should be added directly to the PATH environment variable. /// - public bool ArchiveBinariesDependOnPath { get; set; } + public bool? ArchiveBinariesDependOnPath { get; set; } /// /// Gets or sets the repair behavior.