From 36eb3fabd3082912d79dbeafc8c406ac6755e1b9 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Tue, 1 Apr 2025 16:48:38 -0400 Subject: Sync IEngine.SetDownloadSource with native side. Fixes https://github.com/wixtoolset/issues/issues/9018 --- .../Engine.cs | 4 +-- .../IBootstrapperEngine.cs | 5 ++-- .../IDefaultBootstrapperApplication.cs | 4 +-- .../IEngine.cs | 3 ++- src/test/burn/TestBA/TestBA.cs | 30 ++++++++++++++++++++++ .../burn/WixToolsetTest.BurnE2E/FailureTests.cs | 19 +++++++++++++- .../Utilities/TestBAController.cs | 10 ++++++++ 7 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/Engine.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/Engine.cs index 44d77359..52ac90c5 100644 --- a/src/api/burn/WixToolset.BootstrapperApplicationApi/Engine.cs +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/Engine.cs @@ -271,9 +271,9 @@ namespace WixToolset.BootstrapperApplicationApi } /// - public void SetDownloadSource(string packageOrContainerId, string payloadId, string url, string user, string password) + public void SetDownloadSource(string packageOrContainerId, string payloadId, string url, string user, string password, string authorizationHeader) { - this.engine.SetDownloadSource(packageOrContainerId, payloadId, url, user, password); + this.engine.SetDownloadSource(packageOrContainerId, payloadId, url, user, password, authorizationHeader); } /// diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/IBootstrapperEngine.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/IBootstrapperEngine.cs index c7b0c003..172bafe8 100644 --- a/src/api/burn/WixToolset.BootstrapperApplicationApi/IBootstrapperEngine.cs +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/IBootstrapperEngine.cs @@ -129,14 +129,15 @@ namespace WixToolset.BootstrapperApplicationApi ); /// - /// See . + /// See . /// void SetDownloadSource( [MarshalAs(UnmanagedType.LPWStr)] string wzPackageOrContainerId, [MarshalAs(UnmanagedType.LPWStr)] string wzPayloadId, [MarshalAs(UnmanagedType.LPWStr)] string wzUrl, [MarshalAs(UnmanagedType.LPWStr)] string wzUser, - [MarshalAs(UnmanagedType.LPWStr)] string wzPassword + [MarshalAs(UnmanagedType.LPWStr)] string wzPassword, + [MarshalAs(UnmanagedType.LPWStr)] string wzAuthorizationHeader ); /// diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/IDefaultBootstrapperApplication.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/IDefaultBootstrapperApplication.cs index ad51b2be..1ff12c28 100644 --- a/src/api/burn/WixToolset.BootstrapperApplicationApi/IDefaultBootstrapperApplication.cs +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/IDefaultBootstrapperApplication.cs @@ -37,14 +37,14 @@ namespace WixToolset.BootstrapperApplicationApi /// /// Fired when the engine has begun acquiring the payload or container. /// The BA can change the source using - /// or . + /// or . /// event EventHandler CacheAcquireBegin; /// /// Fired when the engine has completed the acquisition of the payload or container. /// The BA can change the source using - /// or . + /// or . /// event EventHandler CacheAcquireComplete; diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/IEngine.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/IEngine.cs index bd78409b..ca423309 100644 --- a/src/api/burn/WixToolset.BootstrapperApplicationApi/IEngine.cs +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/IEngine.cs @@ -174,7 +174,8 @@ namespace WixToolset.BootstrapperApplicationApi /// The new url. /// The user name for proxy authentication. /// The password for proxy authentication. - void SetDownloadSource(string packageOrContainerId, string payloadId, string url, string user, string password); + /// Additional proxy authentication header. Not currently used. + void SetDownloadSource(string packageOrContainerId, string payloadId, string url, string user, string password, string authorizationHeader); /// /// Sets numeric variables for the engine. diff --git a/src/test/burn/TestBA/TestBA.cs b/src/test/burn/TestBA/TestBA.cs index 1556acd0..4f75a055 100644 --- a/src/test/burn/TestBA/TestBA.cs +++ b/src/test/burn/TestBA/TestBA.cs @@ -41,6 +41,7 @@ namespace WixToolset.Test.BA private int cancelOnProgressAtProgress; private int retryExecuteFilesInUse; private bool rollingBack; + private string forceDownloadSource; private IBootstrapperCommand Command { get; set; } @@ -375,6 +376,12 @@ namespace WixToolset.Test.BA { this.Log(" CancelCacheAtProgress: {0}", this.cancelCacheAtProgress); } + + this.forceDownloadSource = this.ReadPackageAction(args.PackageId, "ForceDownloadSource"); + if (!String.IsNullOrEmpty(this.forceDownloadSource)) + { + this.Log(" ForceDownloadSource: {0}", this.forceDownloadSource); + } } protected override void OnCachePackageNonVitalValidationFailure(CachePackageNonVitalValidationFailureEventArgs args) @@ -387,6 +394,29 @@ namespace WixToolset.Test.BA this.Log("OnCachePackageNonVitalValidationFailure() - id: {0}, default: {1}, requested: {2}", args.PackageId, args.Recommendation, args.Action); } + protected override void OnCacheAcquireResolving(CacheAcquireResolvingEventArgs args) + { + if (!String.IsNullOrEmpty(this.forceDownloadSource)) + { + args.Action = CacheResolveOperation.Download; + var url = String.Format(this.forceDownloadSource, args.PayloadId); + + this.Log("OnCacheAcquireResolving: {0} => {1}", this.forceDownloadSource, url); + + this.engine.SetDownloadSource( + String.Empty, + args.PayloadId, + url, + String.Empty, + String.Empty, + String.Empty); + } + else + { + this.Log("OnCacheAcquireResolving not forcing download"); + } + } + protected override void OnCacheAcquireProgress(CacheAcquireProgressEventArgs args) { this.Log("OnCacheAcquireProgress() - container/package: {0}, payload: {1}, progress: {2}, total: {3}, overall progress: {4}%", args.PackageOrContainerId, args.PayloadId, args.Progress, args.Total, args.OverallPercentage); diff --git a/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs index bd3762ed..4bbfc7e9 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs @@ -2,7 +2,6 @@ namespace WixToolsetTest.BurnE2E { - using System.Threading; using WixTestTools; using WixToolset.BootstrapperApplicationApi; using Xunit; @@ -12,6 +11,24 @@ namespace WixToolsetTest.BurnE2E { public FailureTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } + [RuntimeFact] + public void CanSetDownloadSourceAndForceDownload() + { + var packageA = this.CreatePackageInstaller("PackageA"); + var bundleA = this.CreateBundleInstaller("BundleA"); + var testBAController = this.CreateTestBAController(); + + testBAController.SetPackageForceDownloadSource("PackageA", "https://1e1bf2be1c384fd1a0c4c0500eef971b/downloads/payloads/{0}"); + + packageA.VerifyInstalled(false); + + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); + + bundleA.Install(0x2ee7/*ERROR_INTERNET_NAME_NOT_RESOLVED*/); + + packageA.VerifyInstalled(false); + } + [RuntimeFact] public void CanCancelExePackageAndAbandonIt() { diff --git a/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs b/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs index a378545e..ca395f56 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs @@ -107,6 +107,16 @@ namespace WixToolsetTest.BurnE2E this.SetPackageState(packageId, "CancelExecuteAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null); } + /// + /// Forces a download action and sets the download source. + /// + /// Package identity. + /// The URL format string. + public void SetPackageForceDownloadSource(string packageId, string url) + { + this.SetPackageState(packageId, "ForceDownloadSource", url); + } + /// /// Cancels the execute of a package at the next progess after the specified MSI action start. /// -- cgit v1.2.3-55-g6feb