Skip to content

Commit

Permalink
Skip stub packages for msix installer validation (#3468)
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft authored Jul 25, 2023
1 parent f6e453e commit 3be680c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,9 @@
<CopyFileToFolders Include="TestData\Installer-Good.msixbundle">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Installer-Good-WithStub.msixbundle">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Installer-Signed-Good.msix">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
Expand All @@ -832,6 +835,9 @@
<CopyFileToFolders Include="TestData\Manifest-Good-MsixBundleInstaller.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Good-MsixBundleInstaller-WithStub.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Bad-InconsistentMsixBundleInstallerFields.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,9 @@
<CopyFileToFolders Include="TestData\Installer-Good.msixbundle">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Installer-Good-WithStub.msixbundle">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Installer-Signed-Good.msix">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand All @@ -867,6 +870,9 @@
<CopyFileToFolders Include="TestData\Manifest-Good-MsixBundleInstaller.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Good-MsixBundleInstaller-WithStub.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Bad-InconsistentMsixBundleInstallerFields.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PackageIdentifier: AppInstallerCliTest.GoodMsixBundleInstaller
PackageVersion: 43690.48059.52428.56797
PackageLocale: es-MX
PackageName: es-MX package name
Publisher: es-MX publisher
PackageFamilyName: FakeInstallerForTesting_125rzkzqaqjwj
MinimumOSVersion: 10.0.16299.0
InstallerType: msix
Installers:
- Architecture: x64
InstallerUrl: Installer-Good-WithStub.msixbundle
ManifestType: merged
ManifestVersion: 1.0.0
14 changes: 14 additions & 0 deletions src/AppInstallerCLITests/YamlManifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,20 @@ TEST_CASE("ReadManifestAndValidateMsixBundleInstallers_Success", "[ManifestValid
REQUIRE(0 == errors.size());
}

TEST_CASE("ReadManifestAndValidateMsixBundleInstallers_WithStub_Success", "[ManifestValidation]")
{
TestDataFile testFile("Manifest-Good-MsixBundleInstaller-WithStub.yaml");
Manifest manifest = YamlParser::CreateFromPath(testFile);

// Update the installer path for testing
REQUIRE(1 == manifest.Installers.size());
TestDataFile msixFile(manifest.Installers[0].Url.c_str());
manifest.Installers[0].Url = msixFile.GetPath().u8string();

auto errors = ValidateManifestInstallers(manifest);
REQUIRE(0 == errors.size());
}

TEST_CASE("ReadManifestAndValidateMsixBundleInstallers_InconsistentFields", "[ManifestValidation]")
{
TestDataFile testFile("Manifest-Bad-InconsistentMsixBundleInstallerFields.yaml");
Expand Down
18 changes: 13 additions & 5 deletions src/AppInstallerCommonCore/MsixInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ namespace AppInstaller::Msix
return Utility::ConvertToUTF8(GetPackageFullNameWide());
}

std::vector<ComPtr<IAppxPackageReader>> MsixInfo::GetAppPackages() const
std::vector<ComPtr<IAppxPackageReader>> MsixInfo::GetAppPackages(bool includeStub) const
{
if (!m_isBundle)
{
Expand All @@ -648,11 +648,19 @@ namespace AppInstaller::Msix
APPX_BUNDLE_PAYLOAD_PACKAGE_TYPE packageType;
THROW_IF_FAILED(packageInfo->GetPackageType(&packageType));

// Check flat bundle case.
UINT64 offset;
THROW_IF_FAILED(packageInfo->GetOffset(&offset));
const bool isContained = offset != 0;
bool isContained = offset != 0;

if (isContained && packageType == APPX_BUNDLE_PAYLOAD_PACKAGE_TYPE::APPX_BUNDLE_PAYLOAD_PACKAGE_TYPE_APPLICATION)
// Check stub package case.
ComPtr<IAppxBundleManifestPackageInfo4> packageInfo4;
THROW_IF_FAILED(packageInfo.As(&packageInfo4));
BOOL isStub = FALSE;
THROW_IF_FAILED(packageInfo4->GetIsStub(&isStub));

if (isContained && (includeStub || !isStub) &&
packageType == APPX_BUNDLE_PAYLOAD_PACKAGE_TYPE::APPX_BUNDLE_PAYLOAD_PACKAGE_TYPE_APPLICATION)
{
wil::unique_cotaskmem_string fileName;
THROW_IF_FAILED(packageInfo->GetFileName(&fileName));
Expand Down Expand Up @@ -680,10 +688,10 @@ namespace AppInstaller::Msix
return packages;
}

std::vector<MsixPackageManifest> MsixInfo::GetAppPackageManifests() const
std::vector<MsixPackageManifest> MsixInfo::GetAppPackageManifests(bool includeStub) const
{
std::vector<MsixPackageManifest> manifests;
auto packages = GetAppPackages();
auto packages = GetAppPackages(includeStub);
for (const auto& package : packages)
{
ComPtr<IAppxManifestReader> manifestReader;
Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerCommonCore/Public/AppInstallerMsixInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ namespace AppInstaller::Msix
void WriteToFileHandle(std::string_view packageFile, HANDLE target, IProgressCallback& progress);

// Get application package manifests from msix and msixbundle.
std::vector<MsixPackageManifest> GetAppPackageManifests() const;
std::vector<MsixPackageManifest> GetAppPackageManifests(bool includeStub = false) const;

private:
bool m_isBundle;
Microsoft::WRL::ComPtr<IStream> m_stream;
Microsoft::WRL::ComPtr<IAppxBundleReader> m_bundleReader;
Microsoft::WRL::ComPtr<IAppxPackageReader> m_packageReader;

// Get application packages.
std::vector<Microsoft::WRL::ComPtr<IAppxPackageReader>> GetAppPackages() const;
// Get application packages. Ignore stub packages if any.
std::vector<Microsoft::WRL::ComPtr<IAppxPackageReader>> GetAppPackages(bool includeStub = false) const;
};

struct GetCertContextResult
Expand Down

0 comments on commit 3be680c

Please sign in to comment.