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

Load index from validated msix for unpackaged context #2139

Merged
merged 14 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
12 changes: 12 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 @@ -186,6 +187,9 @@ getline
github
githubusercontent
globals
HCCE
hcertstore
HCRYPTMSG
hfile
HGLOBAL
HIDECANCEL
Expand All @@ -206,6 +210,7 @@ hstring
html
http
https
HWND
Hyperlink
IActivation
IApplication
Expand Down Expand Up @@ -279,6 +284,7 @@ logsql
logto
LONGLONG
LPCGUID
LPCSTR
LPVOID
mailto
MAJORVERSION
Expand Down Expand Up @@ -351,6 +357,7 @@ nuspec
OAuth
ODR
ofstream
Oid
opencode
opensource
openxmlformats
Expand Down Expand Up @@ -382,6 +389,7 @@ PGP
php
PII
pipssource
PKCS
placeholders
png
posix
Expand Down Expand Up @@ -492,6 +500,7 @@ src
srwlock
sscanf
sstream
STATEACTION
STATFLAG
STATSTG
STDAPI
Expand All @@ -516,6 +525,7 @@ STRINGID
STRINGIFY
STRINGIZE
stringstream
STRSAFE
strstr
strtoll
subcontext
Expand Down Expand Up @@ -639,6 +649,7 @@ winmeta
winres
winrt
winsqlite
WINTRUST
wix
wmain
WNS
Expand All @@ -653,6 +664,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 @@ -278,7 +279,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 @@ -314,9 +314,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
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
50 changes: 34 additions & 16 deletions src/AppInstallerCLITests/MsixInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "pch.h"
#include "TestCommon.h"
#include <AppInstallerMsixInfo.h>
#include "AppInstallerDownloader.h"

using namespace std::string_literals;
using namespace std::string_view_literals;
Expand All @@ -11,6 +12,7 @@ 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]")
{
Expand All @@ -23,33 +25,21 @@ TEST_CASE("MsixInfo_GetPackageFamilyName", "[msixinfo]")
REQUIRE(expectedFullName == actualFullName);
}

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

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());

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

TEST_CASE("MsixInfo_WriteFile", "[msixinfo]")
Expand All @@ -64,3 +54,31 @@ TEST_CASE("MsixInfo_WriteFile", "[msixinfo]")

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

TEST_CASE("MsixInfo_ValidateMsixTrustInfo", "[msixinfo]")
{
TestDataFile notSigned{ s_MsixFile_1 };
REQUIRE_FALSE(Msix::ValidateMsixTrustInfo(notSigned));

TestDataFile testSigned{ s_MsixFileSigned_1 };

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

REQUIRE_FALSE(Msix::ValidateMsixTrustInfo(testSigned));

// Add the cert to trusted
InstallCertFromSignedPackage(testSigned);
REQUIRE(Msix::ValidateMsixTrustInfo(testSigned));
REQUIRE_FALSE(Msix::ValidateMsixTrustInfo(testSigned, 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);
REQUIRE(Msix::ValidateMsixTrustInfo(microsoftSigned, true));

if (!certExistsBeforeTest)
{
UninstallCertFromSignedPackage(testSigned);
}
}
72 changes: 41 additions & 31 deletions src/AppInstallerCLITests/PreIndexedPackageSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ namespace fs = std::filesystem;

constexpr std::string_view s_RepositorySettings_UserSources = "usersources"sv;

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_Msix_FamilyName = "AppInstallerCLITestsFakeIndex_125rzkzqaqjwj";
constexpr std::string_view s_AppxManifestFileName = "AppxManifest.xml"sv;
constexpr std::string_view s_MsixFile_1 = "index.1.0.0.0.signed.msix";
constexpr std::string_view s_MsixFile_2 = "index.2.0.0.0.signed.msix";
constexpr std::string_view s_Msix_FamilyName = "AppInstallerCLITestsFakeIndex_8wekyb3d8bbwe";
constexpr std::string_view s_IndexMsixName = "source.msix"sv;
constexpr std::string_view s_IndexFileName = "index.db"sv;

void CopyIndexFileToDirectory(const fs::path& from, const fs::path& to)
{
Expand Down Expand Up @@ -71,6 +69,8 @@ TEST_CASE("PIPS_Add", "[pips]")
TestDataFile index(s_MsixFile_1);
CopyIndexFileToDirectory(index, dir);

bool shouldCleanCert = InstallCertFromSignedPackage(index);

SourceDetails details;
details.Name = "TestName";
details.Type = AppInstaller::Repository::Microsoft::PreIndexedPackageSourceFactory::Type();
Expand All @@ -82,15 +82,15 @@ TEST_CASE("PIPS_Add", "[pips]")
fs::path state = GetPathToFileDir();
REQUIRE(fs::exists(state));

fs::path manifest = state;
manifest /= s_AppxManifestFileName;
REQUIRE(fs::exists(manifest));
REQUIRE(fs::file_size(manifest) > 0);
fs::path indexMsix = state;
indexMsix /= s_IndexMsixName;
REQUIRE(fs::exists(indexMsix));
REQUIRE(fs::file_size(indexMsix) > 0);

fs::path indexFile = state;
indexFile /= s_IndexFileName;
REQUIRE(fs::exists(indexFile));
REQUIRE(fs::file_size(indexFile) > 0);
if (shouldCleanCert)
{
UninstallCertFromSignedPackage(index);
}
}

TEST_CASE("PIPS_UpdateSameVersion", "[pips]")
Expand All @@ -101,6 +101,8 @@ TEST_CASE("PIPS_UpdateSameVersion", "[pips]")
TestDataFile index(s_MsixFile_1);
CopyIndexFileToDirectory(index, dir);

bool shouldCleanCert = InstallCertFromSignedPackage(index);

SourceDetails details;
details.Name = "TestName";
details.Type = AppInstaller::Repository::Microsoft::PreIndexedPackageSourceFactory::Type();
Expand All @@ -117,6 +119,11 @@ TEST_CASE("PIPS_UpdateSameVersion", "[pips]")

UpdateSource(details.Name, callback);
REQUIRE(!progressCalled);

if (shouldCleanCert)
{
UninstallCertFromSignedPackage(index);
}
}

TEST_CASE("PIPS_UpdateNewVersion", "[pips]")
Expand All @@ -127,6 +134,8 @@ TEST_CASE("PIPS_UpdateNewVersion", "[pips]")
TestDataFile indexMsix1(s_MsixFile_1);
CopyIndexFileToDirectory(indexMsix1, dir);

bool shouldCleanCert = InstallCertFromSignedPackage(indexMsix1);

SourceDetails details;
details.Name = "TestName";
details.Type = AppInstaller::Repository::Microsoft::PreIndexedPackageSourceFactory::Type();
Expand All @@ -138,13 +147,9 @@ TEST_CASE("PIPS_UpdateNewVersion", "[pips]")
fs::path state = GetPathToFileDir();
REQUIRE(fs::exists(state));

fs::path manifestPath = state;
manifestPath /= s_AppxManifestFileName;
std::string manifestContents1 = GetContents(manifestPath);

fs::path indexPath = state;
indexPath /= s_IndexFileName;
std::string indexContents1 = GetContents(indexPath);
fs::path indexMsix = state;
indexMsix /= s_IndexMsixName;
std::string indexContents1 = GetContents(indexMsix);

TestDataFile indexMsix2(s_MsixFile_2);
CopyIndexFileToDirectory(indexMsix2, dir);
Expand All @@ -155,11 +160,13 @@ TEST_CASE("PIPS_UpdateNewVersion", "[pips]")
UpdateSource(details.Name, callback);
REQUIRE(progressCalled);

std::string manifestContents2 = GetContents(manifestPath);
REQUIRE(manifestContents1 != manifestContents2);

std::string indexContents2 = GetContents(indexPath);
std::string indexContents2 = GetContents(indexMsix);
REQUIRE(indexContents1 != indexContents2);

if (shouldCleanCert)
{
UninstallCertFromSignedPackage(indexMsix1);
}
}

TEST_CASE("PIPS_Remove", "[pips]")
Expand All @@ -170,6 +177,8 @@ TEST_CASE("PIPS_Remove", "[pips]")
TestDataFile index(s_MsixFile_1);
CopyIndexFileToDirectory(index, dir);

bool shouldCleanCert = InstallCertFromSignedPackage(index);

SourceDetails details;
details.Name = "TestName";
details.Type = AppInstaller::Repository::Microsoft::PreIndexedPackageSourceFactory::Type();
Expand All @@ -181,14 +190,15 @@ TEST_CASE("PIPS_Remove", "[pips]")
fs::path state = GetPathToFileDir();
REQUIRE(fs::exists(state));

fs::path manifest = state;
manifest /= s_AppxManifestFileName;
REQUIRE(fs::exists(manifest));

fs::path indexFile = state;
indexFile /= s_IndexFileName;
REQUIRE(fs::exists(indexFile));
fs::path indexMsix = state;
indexMsix /= s_IndexMsixName;
REQUIRE(fs::exists(indexMsix));

RemoveSource(details.Name, callback);
REQUIRE(!fs::exists(state));

if (shouldCleanCert)
{
UninstallCertFromSignedPackage(index);
}
}
Loading