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

Support to Bypass Store Client App Policy When Called Through COM #3105

Merged
merged 9 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions doc/specs/#888 - Com Api.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ namespace Microsoft.Management.Deployment
String LogOutputPath;
/// Continues the install even if the hash in the catalog does not match the linked installer.
Boolean AllowHashMismatch;
/// Allows Store installs when Store is disabled.
Boolean BypassStorePolicy;
PaulJYim marked this conversation as resolved.
Show resolved Hide resolved
/// A string that will be passed to the installer.
/// IMPLEMENTATION NOTE: maps to "--override" in the winget cmd line
String ReplacementInstallerArguments;
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/ExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace AppInstaller::CLI::Execution
TreatSourceFailuresAsWarning = 0x8,
ShowSearchResultsOnPartialFailure = 0x10,
DisableInteractivity = 0x40,
BypassStorePolicy = 0x80,
};

DEFINE_ENUM_FLAG_OPERATORS(ContextFlag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ namespace AppInstaller::CLI::Workflow
}
else if (result.Status() == GetEntitlementStatus::ServerError)
{
bool bypassStorePolicy = WI_IsFlagSet(context.GetFlags(), Execution::ContextFlag::BypassStorePolicy);
PaulJYim marked this conversation as resolved.
Show resolved Hide resolved
if (bypassStorePolicy)
{
// Entitlement fails because the store is disabled
return true;
}
context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementServerError << std::endl;
AICLI_LOG(CLI, Error, << "Get entitlement failed Server error. ProductId: " << Utility::ConvertToUTF8(productId));
}
Expand Down Expand Up @@ -249,7 +255,9 @@ namespace AppInstaller::CLI::Workflow

// Policy check
AppInstallManager installManager;
if (installManager.IsStoreBlockedByPolicyAsync(s_StoreClientName, s_StoreClientPublisher).get())
bool bypassStorePolicy = WI_IsFlagSet(context.GetFlags(), Execution::ContextFlag::BypassStorePolicy);

if (installManager.IsStoreBlockedByPolicyAsync(s_StoreClientName, s_StoreClientPublisher).get() && !bypassStorePolicy)
PaulJYim marked this conversation as resolved.
Show resolved Hide resolved
PaulJYim marked this conversation as resolved.
Show resolved Hide resolved
{
context.Reporter.Error() << Resource::String::MSStoreStoreClientBlocked << std::endl;
AICLI_LOG(CLI, Error, << "Store client is blocked by policy. MSStore execution failed.");
Expand Down
23 changes: 23 additions & 0 deletions src/AppInstallerCLIE2ETests/Interop/InstallInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,5 +599,28 @@ public void GetApplicableInstaller()
Assert.AreEqual(PackageInstallerScope.User, packageInstallerInfo.Scope);
Assert.AreEqual("en-US", packageInstallerInfo.Locale);
}

/// <summary>
/// Test install with BypassStorePolicy Enabled.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Test]
public async Task InstallMsixStoreBypass()
PaulJYim marked this conversation as resolved.
Show resolved Hide resolved
{
// Find package
var searchResult = this.FindOnePackage(this.testSource, PackageMatchField.Name, PackageFieldMatchOption.Equals, "AppInstallerTest.CatalogPackageMetadata");

// Configure installation
var installOptions = this.TestFactory.CreateInstallOptions();
installOptions.BypassStorePolicy = true;
installOptions.AcceptPackageAgreements = true;

// Install
var installResult = await this.packageManager.InstallPackageAsync(searchResult.CatalogPackage, installOptions);

// Assert
Assert.AreEqual(InstallResultStatus.DownloadError, installResult.Status);
Assert.False(TestCommon.VerifyTestMsixInstalledAndCleanup());
}
}
}
8 changes: 8 additions & 0 deletions src/Microsoft.Management.Deployment/InstallOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ namespace winrt::Microsoft::Management::Deployment::implementation
{
m_allowHashMismatch = value;
}
bool InstallOptions::BypassStorePolicy()
{
return m_bypassStorePolicy;
}
void InstallOptions::BypassStorePolicy(bool value)
{
m_bypassStorePolicy = value;
}
hstring InstallOptions::ReplacementInstallerArguments()
{
return hstring(m_replacementInstallerArguments);
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.Management.Deployment/InstallOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace winrt::Microsoft::Management::Deployment::implementation
void LogOutputPath(hstring const& value);
bool AllowHashMismatch();
void AllowHashMismatch(bool value);
bool BypassStorePolicy();
void BypassStorePolicy(bool value);
hstring ReplacementInstallerArguments();
void ReplacementInstallerArguments(hstring const& value);
hstring AdditionalInstallerArguments();
Expand All @@ -47,6 +49,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
winrt::Microsoft::Management::Deployment::PackageInstallMode m_packageInstallMode = winrt::Microsoft::Management::Deployment::PackageInstallMode::Default;
std::wstring m_logOutputPath = L"";
bool m_allowHashMismatch = false;
bool m_bypassStorePolicy = false;
std::wstring m_replacementInstallerArguments = L"";
std::wstring m_additionalInstallerArguments = L"";
std::wstring m_correlationData = L"";
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.Management.Deployment/PackageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ namespace winrt::Microsoft::Management::Deployment::implementation
{
context->Args.AddArg(Execution::Args::Type::HashOverride);
}

if (options.BypassStorePolicy())
{
context->SetFlags(Execution::ContextFlag::BypassStorePolicy);
}

if (options.Force())
{
context->Args.AddArg(Execution::Args::Type::Force);
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.Management.Deployment/PackageManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,9 @@ namespace Microsoft.Management.Deployment

/// Accept the package agreements required for installation.
Boolean AcceptPackageAgreements;

/// Bypasses the Disabled Store Policy
Boolean BypassStorePolicy;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public string Location
/// Gets or sets a value indicating whether to skip the installer hash validation check.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter AllowHashMismatch { get; set; }
public SwitchParameter AllowHashMismatch { get; set; }

/// <summary>
PaulJYim marked this conversation as resolved.
Show resolved Hide resolved
/// Gets or sets a value indicating whether to skip the installer hash validation check.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter BypassStorePolicy { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to continue upon non security related failures.
Expand All @@ -80,6 +86,7 @@ protected virtual InstallOptions GetInstallOptions(PackageVersionId version)
{
InstallOptions options = ComObjectFactory.Value.CreateInstallOptions();
options.AllowHashMismatch = this.AllowHashMismatch.ToBool();
options.BypassStorePolicy = this.BypassStorePolicy.ToBool();
options.Force = this.Force.ToBool();
options.PackageInstallMode = this.Mode;
if (version != null)
Expand Down