Skip to content

Commit

Permalink
Load index from validated msix for unpackaged context (#2139)
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft authored May 16, 2022
1 parent 4df817b commit 0b1142f
Show file tree
Hide file tree
Showing 24 changed files with 721 additions and 85 deletions.
13 changes: 13 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ cmake
cmdlet
cmdlets
cmp
CMSG
CNG
cnt
codepage
Expand Down Expand Up @@ -187,6 +188,9 @@ getline
github
githubusercontent
globals
HCCE
hcertstore
HCRYPTMSG
hfile
HGLOBAL
HIDECANCEL
Expand All @@ -207,6 +211,7 @@ hstring
html
http
https
HWND
Hyperlink
IActivation
IApplication
Expand Down Expand Up @@ -280,6 +285,7 @@ logsql
logto
LONGLONG
LPCGUID
LPCSTR
LPVOID
mailto
MAJORVERSION
Expand Down Expand Up @@ -352,6 +358,7 @@ nuspec
OAuth
ODR
ofstream
Oid
opencode
opensource
openxmlformats
Expand Down Expand Up @@ -383,6 +390,7 @@ PGP
php
PII
pipssource
PKCS
placeholders
png
posix
Expand Down Expand Up @@ -494,6 +502,7 @@ src
srwlock
sscanf
sstream
STATEACTION
STATFLAG
STATSTG
STDAPI
Expand All @@ -518,6 +527,7 @@ STRINGID
STRINGIFY
STRINGIZE
stringstream
STRSAFE
strstr
strtoll
subcontext
Expand Down Expand Up @@ -630,6 +640,7 @@ wcout
wcsicmp
webpage
wekyb
WHOLECHAIN
wil
wildcards
WINAPI
Expand All @@ -641,6 +652,7 @@ winmeta
winres
winrt
winsqlite
WINTRUST
wix
wmain
WNS
Expand All @@ -655,6 +667,7 @@ wrl
WStr
wstring
wstringstream
WTD
www
xamarin
xaml
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ EXEHASH
experimentalfeatures
fcb
fd
fdw
fedorapeople
fileinuse
fintimes
Expand Down Expand Up @@ -281,7 +282,9 @@ parametermap
pathparts
pathpaths
Patil
pb
PCs
pcwsz
pdp
PEGI
pfn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace AppInstaller::CLI::Workflow
if (result.Status() == GetEntitlementStatus::Succeeded)
{
context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementSuccess << std::endl;
AICLI_LOG(CLI, Info, << "Get entitlement succeeded.");
}
else if (result.Status() == GetEntitlementStatus::NetworkError)
{
Expand Down
4 changes: 3 additions & 1 deletion src/AppInstallerCLIPackage/AppInstallerCLIPackage.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
<None Include="Register-WingetdevAutoComplete.ps1" />
<PRIResource Include="Shared\Strings\en-us\winget.resw" />
<PRIResource Include="Shared\Strings\en-us\winget.resw">
<SubType>Designer</SubType>
</PRIResource>
<PRIResource Include="shared\strings\de-DE\winget.resw" Condition="Exists('shared\strings\de-DE\winget.resw')" />
<PRIResource Include="shared\strings\es-ES\winget.resw" Condition="Exists('shared\strings\es-ES\winget.resw')" />
<PRIResource Include="shared\strings\fr-FR\winget.resw" Condition="Exists('shared\strings\fr-FR\winget.resw')" />
Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,15 @@
<CopyFileToFolders Include="TestData\index.1.0.0.0.msix">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\index.1.0.0.0.signed.msix">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\index.2.0.0.0.msix">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\index.2.0.0.0.signed.msix">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\TestSignedApp.msix">
<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 @@ -408,9 +408,15 @@
<CopyFileToFolders Include="TestData\index.1.0.0.0.msix">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\index.1.0.0.0.signed.msix">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\index.2.0.0.0.msix">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\index.2.0.0.0.signed.msix">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\TestSignedApp.msix">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand Down
70 changes: 50 additions & 20 deletions src/AppInstallerCLITests/MsixInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "pch.h"
#include "TestCommon.h"
#include <AppInstallerMsixInfo.h>
#include <AppInstallerDownloader.h>
#include <AppInstallerRuntime.h>

using namespace std::string_literals;
using namespace std::string_view_literals;
Expand All @@ -11,51 +13,40 @@ using namespace AppInstaller;

constexpr std::string_view s_MsixFile_1 = "index.1.0.0.0.msix";
constexpr std::string_view s_MsixFile_2 = "index.2.0.0.0.msix";
constexpr std::string_view s_MsixFileSigned_1 = "index.1.0.0.0.signed.msix";

TEST_CASE("MsixInfo_GetPackageFamilyName", "[msixinfo]")
{
TestDataFile index(s_MsixFile_1);
Msix::MsixInfo msix(index.GetPath().u8string());
Msix::MsixInfo msix(index.GetPath());

std::string expectedFullName = "AppInstallerCLITestsFakeIndex_1.0.0.0_neutral__125rzkzqaqjwj";
std::string actualFullName = msix.GetPackageFullName();

REQUIRE(expectedFullName == actualFullName);
}

TEST_CASE("MsixInfo_WriteManifestAndCompareToSelf", "[msixinfo]")
TEST_CASE("MsixInfo_CompareToSelf", "[msixinfo]")
{
TestDataFile index(s_MsixFile_1);
Msix::MsixInfo msix(index.GetPath().u8string());
Msix::MsixInfo msix(index.GetPath());

TempFile manifest{ "msixtest_manifest"s, ".xml"s };
ProgressCallback callback;

msix.WriteManifestToFile(manifest, callback);

REQUIRE(!msix.IsNewerThan(manifest));
REQUIRE(!msix.IsNewerThan(index.GetPath().u8string()));
}

TEST_CASE("MsixInfo_WriteManifestAndCompareToOlder", "[msixinfo]")
TEST_CASE("MsixInfo_CompareToOlder", "[msixinfo]")
{
TestDataFile index1(s_MsixFile_1);
Msix::MsixInfo msix1(index1.GetPath().u8string());

TempFile manifest{ "msixtest_manifest"s, ".xml"s };
ProgressCallback callback;

msix1.WriteManifestToFile(manifest, callback);

TestDataFile index2(s_MsixFile_2);
Msix::MsixInfo msix2(index2.GetPath().u8string());
Msix::MsixInfo msix2(index2.GetPath());

REQUIRE(msix2.IsNewerThan(manifest));
REQUIRE(msix2.IsNewerThan(index1));
}

TEST_CASE("MsixInfo_WriteFile", "[msixinfo]")
{
TestDataFile index(s_MsixFile_1);
Msix::MsixInfo msix(index.GetPath().u8string());
Msix::MsixInfo msix(index.GetPath());

TempFile file{ "msixtest_file"s, ".bin"s };
ProgressCallback callback;
Expand All @@ -64,3 +55,42 @@ TEST_CASE("MsixInfo_WriteFile", "[msixinfo]")

REQUIRE(1 == std::filesystem::file_size(file));
}

TEST_CASE("MsixInfo_ValidateMsixTrustInfo", "[msixinfo]")
{
if (!Runtime::IsRunningAsAdmin())
{
WARN("Test requires admin privilege. Skipped.");
return;
}

TestDataFile notSigned{ s_MsixFile_1 };
Msix::WriteLockedMsixFile notSignedWriteLocked{ notSigned };
REQUIRE_FALSE(notSignedWriteLocked.ValidateTrustInfo(false));

TestDataFile testSigned{ s_MsixFileSigned_1 };
Msix::WriteLockedMsixFile testSignedWriteLocked{ testSigned };

// Remove the cert if already trusted
bool certExistsBeforeTest = UninstallCertFromSignedPackage(testSigned);

REQUIRE_FALSE(testSignedWriteLocked.ValidateTrustInfo(false));

// Add the cert to trusted
InstallCertFromSignedPackage(testSigned);

REQUIRE(testSignedWriteLocked.ValidateTrustInfo(false));
REQUIRE_FALSE(testSignedWriteLocked.ValidateTrustInfo(true));

TestCommon::TempFile microsoftSigned{ "testIndex"s, ".msix"s };
ProgressCallback callback;
Utility::Download("https://cdn.winget.microsoft.com/cache/source.msix", microsoftSigned.GetPath(), Utility::DownloadType::Index, callback);

Msix::WriteLockedMsixFile microsoftSignedWriteLocked{ microsoftSigned };
REQUIRE(microsoftSignedWriteLocked.ValidateTrustInfo(true));

if (!certExistsBeforeTest)
{
UninstallCertFromSignedPackage(testSigned);
}
}
Loading

0 comments on commit 0b1142f

Please sign in to comment.