Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate against NestedInstaller / Base Installer is not Archive #5236

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,12 @@
<CopyFileToFolders Include="TestData\ManifestV1_10-Bad-SchemaHeaderURLPatternMismatch.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Bad-NonArchive-NestedInstallerType.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Bad-NonArchive-NestedInstallerFiles.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AppInstallerCLICore\AppInstallerCLICore.vcxproj">
Expand Down
10 changes: 8 additions & 2 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
Expand Down Expand Up @@ -1068,5 +1068,11 @@
<CopyFileToFolders Include="TestData\ManifestV1_10-Bad-SchemaHeaderURLPatternMismatch.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Bad-NonArchive-NestedInstallerType.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Bad-NonArchive-NestedInstallerFiles.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Bad manifest. NestedInstallerFiles used with non-archive InstallerType
# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/winget-cli/refs/heads/master/schemas/JSON/manifests/v1.10.0/manifest.singleton.1.10.0.json
PackageIdentifier: AppInstallerCliTest.TestMsixInstaller
PackageVersion: 1.0.0.0
PackageLocale: en-US
PackageName: AppInstaller Test MSIX Installer
ShortDescription: AppInstaller Test MSIX Installer
Publisher: Microsoft Corporation
Moniker: AICLITestMsix
License: Test
Installers:
- Architecture: x64
InstallerUrl: https://github.com/microsoft/msix-packaging/blob/master/src/test/testData/unpack/TestAppxPackage_x64.appx?raw=true
InstallerType: msix
InstallerSha256: 6a2d3683fa19bf00e58e07d1313d20a5f5735ebbd6a999d33381d28740ee07ea
PackageFamilyName: 20477fca-282d-49fb-b03e-371dca074f0f_8wekyb3d8bbwe
NestedInstallerFiles:
- RelativeFilePath: Test
ManifestType: singleton
ManifestVersion: 1.10.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Bad manifest. NestedInstallerType used with non-archive InstallerType
# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/winget-cli/refs/heads/master/schemas/JSON/manifests/v1.10.0/manifest.singleton.1.10.0.json
PackageIdentifier: AppInstallerCliTest.TestMsixInstaller
PackageVersion: 1.0.0.0
PackageLocale: en-US
PackageName: AppInstaller Test MSIX Installer
ShortDescription: AppInstaller Test MSIX Installer
Publisher: Microsoft Corporation
Moniker: AICLITestMsix
License: Test
Installers:
- Architecture: x64
InstallerUrl: https://github.com/microsoft/msix-packaging/blob/master/src/test/testData/unpack/TestAppxPackage_x64.appx?raw=true
InstallerType: msix
InstallerSha256: 6a2d3683fa19bf00e58e07d1313d20a5f5735ebbd6a999d33381d28740ee07ea
PackageFamilyName: 20477fca-282d-49fb-b03e-371dca074f0f_8wekyb3d8bbwe
NestedInstallerType: portable
ManifestType: singleton
ManifestVersion: 1.10.0
2 changes: 2 additions & 0 deletions src/AppInstallerCLITests/YamlManifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ TEST_CASE("ReadBadManifests", "[ManifestValidation]")
{ "InstallFlowTest_LicenseAgreement.yaml", "Field usage requires verified publishers. [Agreement]", false, GetTestManifestValidateOption(false, true) },
{ "Manifest-Bad-ApproximateVersionInPackageVersion.yaml", "Approximate version not allowed. [PackageVersion]" },
{ "Manifest-Bad-ApproximateVersionInArpVersion.yaml", "Approximate version not allowed. [DisplayVersion]" },
{ "Manifest-Bad-NonArchive-NestedInstallerType.yaml", "Field usage requires InstallerType to be an archive type. [NestedInstallerType]" },
{ "Manifest-Bad-NonArchive-NestedInstallerFiles.yaml", "Field usage requires InstallerType to be an archive type. [NestedInstallerFiles]" },
};

for (auto const& testCase : TestCases)
Expand Down
13 changes: 13 additions & 0 deletions src/AppInstallerCommonCore/Manifest/ManifestValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace AppInstaller::Manifest
{ AppInstaller::Manifest::ManifestError::SchemaHeaderManifestTypeMismatch , "The manifest type in the schema header does not match the ManifestType property value in the manifest."sv },
{ AppInstaller::Manifest::ManifestError::SchemaHeaderManifestVersionMismatch, "The manifest version in the schema header does not match the ManifestVersion property value in the manifest."sv },
{ AppInstaller::Manifest::ManifestError::SchemaHeaderUrlPatternMismatch, "The schema header URL does not match the expected pattern."sv },
{ AppInstaller::Manifest::ManifestError::InvalidArchiveField, "Field usage requires InstallerType to be an archive type."sv },
};

return ErrorIdToMessageMap;
Expand Down Expand Up @@ -333,6 +334,18 @@ namespace AppInstaller::Manifest
}
}
}
else
{
// If base installer is not an archive type, NestedInstaller fields should not be present
if (installer.NestedInstallerType != InstallerTypeEnum::Unknown)
{
resultErrors.emplace_back(ManifestError::InvalidArchiveField, "NestedInstallerType");
}
if (installer.NestedInstallerFiles.size() != 0)
{
resultErrors.emplace_back(ManifestError::InvalidArchiveField, "NestedInstallerFiles");
}
}

// Check empty string before calling IsValidUrl to avoid duplicate error reporting.
if (!installer.Url.empty() && IsValidURL(NULL, Utility::ConvertToUTF16(installer.Url).c_str(), 0) == S_FALSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace AppInstaller::Manifest
WINGET_DEFINE_RESOURCE_STRINGID(SchemaHeaderManifestTypeMismatch);
WINGET_DEFINE_RESOURCE_STRINGID(SchemaHeaderManifestVersionMismatch);
WINGET_DEFINE_RESOURCE_STRINGID(SchemaHeaderUrlPatternMismatch);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidArchiveField);
}

struct ValidationError
Expand Down
Loading