| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolsetTest.BurnE2E |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Diagnostics; |
| 8 | using System.IO; |
| 9 | using WixTestTools; |
| 10 | using Xunit; |
| 11 | using Xunit.Abstractions; |
| 12 | |
| 13 | public class UpdateBundleTests : BurnE2ETests |
| 14 | { |
| 15 | public UpdateBundleTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } |
| 16 | |
| 17 | [RuntimeFact] |
| 18 | public void CanLaunchUpdateBundleFromLocalSourceInsteadOfInstall() |
| 19 | { |
| 20 | var packageAv1 = this.CreatePackageInstaller("PackageAv1"); |
| 21 | var packageAv2 = this.CreatePackageInstaller("PackageAv2"); |
| 22 | var bundleAv1 = this.CreateBundleInstaller("BundleAv1"); |
| 23 | var bundleAv2 = this.CreateBundleInstaller("BundleAv2"); |
| 24 | |
| 25 | var updateBundleSwitch = String.Concat("\"", "-updatebundle:", bundleAv2.Bundle, "\""); |
| 26 | |
| 27 | packageAv1.VerifyInstalled(false); |
| 28 | packageAv2.VerifyInstalled(false); |
| 29 | |
| 30 | // Install the v2 bundle by getting v1 to launch it as an update bundle. |
| 31 | bundleAv1.Install(arguments: updateBundleSwitch); |
| 32 | bundleAv1.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 33 | bundleAv2.VerifyRegisteredAndInPackageCache(); |
| 34 | |
| 35 | packageAv1.VerifyInstalled(false); |
| 36 | packageAv2.VerifyInstalled(true); |
| 37 | |
| 38 | bundleAv2.Uninstall(); |
| 39 | bundleAv2.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 40 | packageAv2.VerifyInstalled(false); |
| 41 | } |
| 42 | |
| 43 | [RuntimeFact] |
| 44 | public void CanLaunchUpdateBundleFromLocalSourceInsteadOfModify() |
| 45 | { |
| 46 | var packageAv1 = this.CreatePackageInstaller("PackageAv1"); |
| 47 | var packageAv2 = this.CreatePackageInstaller("PackageAv2"); |
| 48 | var bundleAv1 = this.CreateBundleInstaller("BundleAv1"); |
| 49 | var bundleAv2 = this.CreateBundleInstaller("BundleAv2"); |
| 50 | |
| 51 | var updateBundleSwitch = String.Concat("\"", "-updatebundle:", bundleAv2.Bundle, "\""); |
| 52 | |
| 53 | packageAv1.VerifyInstalled(false); |
| 54 | packageAv2.VerifyInstalled(false); |
| 55 | |
| 56 | bundleAv1.Install(); |
| 57 | bundleAv1.VerifyRegisteredAndInPackageCache(); |
| 58 | |
| 59 | packageAv1.VerifyInstalled(true); |
| 60 | packageAv2.VerifyInstalled(false); |
| 61 | |
| 62 | // Install the v2 bundle by getting v1 to launch it as an update bundle. |
| 63 | bundleAv1.Modify(arguments: updateBundleSwitch); |
| 64 | bundleAv1.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 65 | bundleAv2.VerifyRegisteredAndInPackageCache(); |
| 66 | |
| 67 | packageAv1.VerifyInstalled(false); |
| 68 | packageAv2.VerifyInstalled(true); |
| 69 | |
| 70 | bundleAv2.Uninstall(); |
| 71 | bundleAv2.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 72 | packageAv2.VerifyInstalled(false); |
| 73 | } |
| 74 | |
| 75 | [RuntimeFact] |
| 76 | public void ForwardsArgumentsToUpdateBundle() |
| 77 | { |
| 78 | var packageAv1 = this.CreatePackageInstaller("PackageAv1"); |
| 79 | var packageAv2 = this.CreatePackageInstaller("PackageAv2"); |
| 80 | var bundleAv1 = this.CreateBundleInstaller("BundleAv1"); |
| 81 | var bundleAv2 = this.CreateBundleInstaller("BundleAv2"); |
| 82 | var testBAController = this.CreateTestBAController(); |
| 83 | |
| 84 | const string verifyArguments = "these arguments should exist"; |
| 85 | var updateBundleSwitch = String.Concat("\"", "-updatebundle:", bundleAv2.Bundle, "\" ", verifyArguments); |
| 86 | |
| 87 | testBAController.SetVerifyArguments(verifyArguments); |
| 88 | |
| 89 | packageAv1.VerifyInstalled(false); |
| 90 | packageAv2.VerifyInstalled(false); |
| 91 | |
| 92 | // Install the v2 bundle by getting v1 to launch it as an update bundle. |
| 93 | bundleAv1.Install(arguments: updateBundleSwitch); |
| 94 | bundleAv1.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 95 | bundleAv2.VerifyRegisteredAndInPackageCache(); |
| 96 | |
| 97 | packageAv1.VerifyInstalled(false); |
| 98 | packageAv2.VerifyInstalled(true); |
| 99 | |
| 100 | // Attempt to uninstall bundleA2 without the verify arguments passed and expect failure code. |
| 101 | bundleAv2.Uninstall(expectedExitCode: -1); |
| 102 | |
| 103 | // Remove the required arguments and uninstall again. |
| 104 | testBAController.SetVerifyArguments(null); |
| 105 | bundleAv2.Uninstall(); |
| 106 | bundleAv2.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 107 | packageAv2.VerifyInstalled(false); |
| 108 | } |
| 109 | |
| 110 | // Installs bundle Bv1.0 then tries to update to latest version during modify (but no server exists). |
| 111 | [RuntimeFact] |
| 112 | public void CanCheckUpdateServerDuringModifyAndDoNothingWhenServerIsntResponsive() |
| 113 | { |
| 114 | var packageB = this.CreatePackageInstaller("PackageBv1"); |
| 115 | var bundleB = this.CreateBundleInstaller("BundleBv1"); |
| 116 | |
| 117 | packageB.VerifyInstalled(false); |
| 118 | |
| 119 | bundleB.Install(); |
| 120 | bundleB.VerifyRegisteredAndInPackageCache(); |
| 121 | |
| 122 | packageB.VerifyInstalled(true); |
| 123 | |
| 124 | // Run the v1 bundle requesting an update bundle. |
| 125 | bundleB.Modify(arguments: "-checkupdate"); |
| 126 | bundleB.VerifyRegisteredAndInPackageCache(); |
| 127 | |
| 128 | // Verify nothing changed. |
| 129 | packageB.VerifyInstalled(true); |
| 130 | |
| 131 | bundleB.Uninstall(); |
| 132 | bundleB.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 133 | packageB.VerifyInstalled(false); |
| 134 | } |
| 135 | |
| 136 | // Installs bundle Bv1.0 then tries to update to latest version during modify (server exists, no feed). |
| 137 | [RuntimeFact] |
| 138 | public void CanCheckUpdateServerDuringModifyAndDoNothingWhenFeedIsMissing() |
| 139 | { |
| 140 | var packageB = this.CreatePackageInstaller("PackageBv1"); |
| 141 | var bundleB = this.CreateBundleInstaller("BundleBv1"); |
| 142 | var webServer = this.CreateWebServer(); |
| 143 | |
| 144 | webServer.Start(); |
| 145 | |
| 146 | packageB.VerifyInstalled(false); |
| 147 | |
| 148 | bundleB.Install(); |
| 149 | bundleB.VerifyRegisteredAndInPackageCache(); |
| 150 | |
| 151 | packageB.VerifyInstalled(true); |
| 152 | |
| 153 | // Run the v1 bundle requesting an update bundle. |
| 154 | bundleB.Modify(arguments: "-checkupdate"); |
| 155 | bundleB.VerifyRegisteredAndInPackageCache(); |
| 156 | |
| 157 | // Verify nothing changed. |
| 158 | packageB.VerifyInstalled(true); |
| 159 | |
| 160 | bundleB.Uninstall(); |
| 161 | bundleB.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 162 | packageB.VerifyInstalled(false); |
| 163 | } |
| 164 | |
| 165 | // Installs bundle Bv1.0 then tries to update to latest version during modify (server exists, v1.0 feed). |
| 166 | [RuntimeFact] |
| 167 | public void CanCheckUpdateServerDuringModifyAndDoNothingWhenAlreadyLatestVersion() |
| 168 | { |
| 169 | var packageB = this.CreatePackageInstaller("PackageBv1"); |
| 170 | var bundleB = this.CreateBundleInstaller("BundleBv1"); |
| 171 | var webServer = this.CreateWebServer(); |
| 172 | |
| 173 | webServer.AddFiles(new Dictionary<string, string> |
| 174 | { |
| 175 | { "/BundleB/feed", Path.Combine(this.TestContext.TestDataFolder, "FeedBv1.0.xml") }, |
| 176 | }); |
| 177 | webServer.Start(); |
| 178 | |
| 179 | packageB.VerifyInstalled(false); |
| 180 | |
| 181 | bundleB.Install(); |
| 182 | bundleB.VerifyRegisteredAndInPackageCache(); |
| 183 | |
| 184 | packageB.VerifyInstalled(true); |
| 185 | |
| 186 | // Run the v1 bundle requesting an update bundle. |
| 187 | bundleB.Modify(arguments: "-checkupdate"); |
| 188 | bundleB.VerifyRegisteredAndInPackageCache(); |
| 189 | |
| 190 | // Verify nothing changed. |
| 191 | packageB.VerifyInstalled(true); |
| 192 | |
| 193 | bundleB.Uninstall(); |
| 194 | bundleB.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 195 | packageB.VerifyInstalled(false); |
| 196 | } |
| 197 | |
| 198 | // Installs bundle Bv1.0 then does an update to bundle Bv2.0 during modify (server exists, v2.0 feed). |
| 199 | [RuntimeFact] |
| 200 | public void CanLaunchUpdateBundleFromDownloadInsteadOfModify() |
| 201 | { |
| 202 | var packageBv1 = this.CreatePackageInstaller("PackageBv1"); |
| 203 | var packageBv2 = this.CreatePackageInstaller("PackageBv2"); |
| 204 | var bundleBv1 = this.CreateBundleInstaller("BundleBv1"); |
| 205 | var bundleBv2 = this.CreateBundleInstaller("BundleBv2"); |
| 206 | var webServer = this.CreateWebServer(); |
| 207 | |
| 208 | webServer.AddFiles(new Dictionary<string, string> |
| 209 | { |
| 210 | { "/BundleB/feed", Path.Combine(this.TestContext.TestDataFolder, "FeedBv2.0.xml") }, |
| 211 | { "/BundleB/2.0/BundleB.exe", bundleBv2.Bundle }, |
| 212 | }); |
| 213 | webServer.Start(); |
| 214 | |
| 215 | packageBv1.VerifyInstalled(false); |
| 216 | packageBv2.VerifyInstalled(false); |
| 217 | |
| 218 | bundleBv1.Install(); |
| 219 | bundleBv1.VerifyRegisteredAndInPackageCache(); |
| 220 | |
| 221 | packageBv1.VerifyInstalled(true); |
| 222 | packageBv2.VerifyInstalled(false); |
| 223 | |
| 224 | // Run the v1 bundle requesting an update bundle. |
| 225 | bundleBv1.Modify(arguments: "-checkupdate"); |
| 226 | |
| 227 | // The modify -> update is asynchronous, so we need to wait until all the bundles are done. |
| 228 | var childBundles = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(bundleBv1.Bundle)); |
| 229 | foreach (var childBundle in childBundles) |
| 230 | { |
| 231 | childBundle.WaitForExit(); |
| 232 | } |
| 233 | |
| 234 | childBundles = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(bundleBv2.Bundle)); |
| 235 | foreach (var childBundle in childBundles) |
| 236 | { |
| 237 | childBundle.WaitForExit(); |
| 238 | } |
| 239 | |
| 240 | bundleBv1.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 241 | bundleBv2.VerifyRegisteredAndInPackageCache(); |
| 242 | |
| 243 | packageBv1.VerifyInstalled(false); |
| 244 | packageBv2.VerifyInstalled(true); |
| 245 | |
| 246 | bundleBv2.Uninstall(); |
| 247 | bundleBv2.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 248 | packageBv1.VerifyInstalled(false); |
| 249 | packageBv2.VerifyInstalled(false); |
| 250 | } |
| 251 | |
| 252 | // Installs bundle Bv1.0 then attempts an update to bundle Bv2.0 during modify (server exists, v2.0 feed with wrong hash). |
| 253 | [RuntimeFact] |
| 254 | public void CanBlockWrongUpdateBundleFromDownloadInsteadOfModify() |
| 255 | { |
| 256 | var packageBv1 = this.CreatePackageInstaller("PackageBv1"); |
| 257 | var packageBv2 = this.CreatePackageInstaller("PackageBv2"); |
| 258 | var bundleBv1 = this.CreateBundleInstaller("BundleBv1"); |
| 259 | var bundleBv2 = this.CreateBundleInstaller("BundleBv2"); |
| 260 | var webServer = this.CreateWebServer(); |
| 261 | |
| 262 | webServer.AddFiles(new Dictionary<string, string> |
| 263 | { |
| 264 | { "/BundleB/feed", Path.Combine(this.TestContext.TestDataFolder, "FeedBv2.0_wronghash.xml") }, |
| 265 | { "/BundleB/2.0/BundleB.exe", bundleBv2.Bundle }, |
| 266 | }); |
| 267 | webServer.Start(); |
| 268 | |
| 269 | packageBv1.VerifyInstalled(false); |
| 270 | packageBv2.VerifyInstalled(false); |
| 271 | |
| 272 | bundleBv1.Install(); |
| 273 | bundleBv1.VerifyRegisteredAndInPackageCache(); |
| 274 | |
| 275 | packageBv1.VerifyInstalled(true); |
| 276 | packageBv2.VerifyInstalled(false); |
| 277 | |
| 278 | // Run the v1 bundle requesting an update bundle. |
| 279 | bundleBv1.Modify(unchecked((int)0x80091007), arguments: "-checkupdate"); |
| 280 | |
| 281 | bundleBv1.VerifyRegisteredAndInPackageCache(); |
| 282 | bundleBv2.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 283 | |
| 284 | packageBv1.VerifyInstalled(true); |
| 285 | packageBv2.VerifyInstalled(false); |
| 286 | } |
| 287 | } |
| 288 | } |