diff options
Diffstat (limited to '')
| -rw-r--r-- | src/test/burn/WixTestTools/BundleVerifier.cs | 119 |
1 files changed, 80 insertions, 39 deletions
diff --git a/src/test/burn/WixTestTools/BundleVerifier.cs b/src/test/burn/WixTestTools/BundleVerifier.cs index b6181047..7bfba687 100644 --- a/src/test/burn/WixTestTools/BundleVerifier.cs +++ b/src/test/burn/WixTestTools/BundleVerifier.cs | |||
| @@ -5,8 +5,6 @@ namespace WixTestTools | |||
| 5 | using System; | 5 | using System; |
| 6 | using System.IO; | 6 | using System.IO; |
| 7 | using System.Linq; | 7 | using System.Linq; |
| 8 | using System.Text; | ||
| 9 | using System.Xml.Linq; | ||
| 10 | using Microsoft.Win32; | 8 | using Microsoft.Win32; |
| 11 | using WixInternal.TestSupport; | 9 | using WixInternal.TestSupport; |
| 12 | using WixToolset.Data; | 10 | using WixToolset.Data; |
| @@ -56,43 +54,64 @@ namespace WixTestTools | |||
| 56 | { | 54 | { |
| 57 | var bundleSymbol = this.GetBundleSymbol(); | 55 | var bundleSymbol = this.GetBundleSymbol(); |
| 58 | var x64 = bundleSymbol.Platform != Platform.X86; | 56 | var x64 = bundleSymbol.Platform != Platform.X86; |
| 57 | |||
| 59 | return x64 ? FULL_BURN_POLICY_REGISTRY_PATH : FULL_BURN_POLICY_REGISTRY_PATH_WOW6432NODE; | 58 | return x64 ? FULL_BURN_POLICY_REGISTRY_PATH : FULL_BURN_POLICY_REGISTRY_PATH_WOW6432NODE; |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | public string GetPackageCachePathForCacheId(string cacheId, bool perMachine) | 61 | public string GetPackageCachePathForCacheId(string cacheId, WixBundleScopeType? scope, bool? plannedPerMachine = null) |
| 63 | { | 62 | { |
| 64 | string cachePath; | 63 | string cachePath; |
| 65 | if (perMachine) | 64 | |
| 65 | if (scope == WixBundleScopeType.PerMachine) | ||
| 66 | { | 66 | { |
| 67 | using var policyKey = Registry.LocalMachine.OpenSubKey(this.GetFullBurnPolicyRegistryPath()); | 67 | cachePath = GetPerMachineCacheRoot(); |
| 68 | var redirectedCachePath = policyKey?.GetValue("PackageCache") as string; | 68 | } |
| 69 | cachePath = redirectedCachePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), PACKAGE_CACHE_FOLDER_NAME); | 69 | else if (scope == WixBundleScopeType.PerUser) |
| 70 | { | ||
| 71 | cachePath = GetPerUserCacheRoot(); | ||
| 70 | } | 72 | } |
| 71 | else | 73 | else |
| 72 | { | 74 | { |
| 73 | cachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PACKAGE_CACHE_FOLDER_NAME); | 75 | cachePath = plannedPerMachine.Value ? GetPerMachineCacheRoot() : GetPerUserCacheRoot(); |
| 74 | } | 76 | } |
| 77 | |||
| 75 | return Path.Combine(cachePath, cacheId); | 78 | return Path.Combine(cachePath, cacheId); |
| 79 | |||
| 80 | string GetPerMachineCacheRoot() | ||
| 81 | { | ||
| 82 | using var policyKey = Registry.LocalMachine.OpenSubKey(this.GetFullBurnPolicyRegistryPath()); | ||
| 83 | var redirectedCachePath = policyKey?.GetValue("PackageCache") as string; | ||
| 84 | return redirectedCachePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), PACKAGE_CACHE_FOLDER_NAME); | ||
| 85 | } | ||
| 86 | |||
| 87 | string GetPerUserCacheRoot() | ||
| 88 | { | ||
| 89 | return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PACKAGE_CACHE_FOLDER_NAME); | ||
| 90 | } | ||
| 76 | } | 91 | } |
| 77 | 92 | ||
| 78 | public string GetExpectedCachedBundlePath() | 93 | public string GetExpectedCachedBundlePath(bool? plannedPerMachine = null) |
| 79 | { | 94 | { |
| 80 | var bundleSymbol = this.GetBundleSymbol(); | 95 | var bundleSymbol = this.GetBundleSymbol(); |
| 81 | var cachePath = this.GetPackageCachePathForCacheId(bundleSymbol.BundleCode, bundleSymbol.PerMachine); | 96 | var cachePath = this.GetPackageCachePathForCacheId(bundleSymbol.BundleCode, bundleSymbol.Scope, plannedPerMachine); |
| 97 | |||
| 82 | return Path.Combine(cachePath, Path.GetFileName(this.Bundle)); | 98 | return Path.Combine(cachePath, Path.GetFileName(this.Bundle)); |
| 83 | } | 99 | } |
| 84 | 100 | ||
| 85 | public string ManuallyCache() | 101 | public string ManuallyCache(bool? plannedPerMachine = null) |
| 86 | { | 102 | { |
| 87 | var expectedCachePath = this.GetExpectedCachedBundlePath(); | 103 | var expectedCachePath = this.GetExpectedCachedBundlePath(plannedPerMachine); |
| 104 | |||
| 88 | Directory.CreateDirectory(Path.GetDirectoryName(expectedCachePath)); | 105 | Directory.CreateDirectory(Path.GetDirectoryName(expectedCachePath)); |
| 89 | File.Copy(this.Bundle, expectedCachePath); | 106 | File.Copy(this.Bundle, expectedCachePath); |
| 107 | |||
| 90 | return expectedCachePath; | 108 | return expectedCachePath; |
| 91 | } | 109 | } |
| 92 | 110 | ||
| 93 | public void ManuallyUncache() | 111 | public void ManuallyUncache(bool? plannedPerMachine = null) |
| 94 | { | 112 | { |
| 95 | var expectedCachePath = this.GetExpectedCachedBundlePath(); | 113 | var expectedCachePath = this.GetExpectedCachedBundlePath(plannedPerMachine); |
| 114 | |||
| 96 | File.Delete(expectedCachePath); | 115 | File.Delete(expectedCachePath); |
| 97 | } | 116 | } |
| 98 | 117 | ||
| @@ -103,38 +122,51 @@ namespace WixTestTools | |||
| 103 | var section = intermediate.Sections.Single(); | 122 | var section = intermediate.Sections.Single(); |
| 104 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().SingleOrDefault(p => p.Id.Id == packageId); | 123 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().SingleOrDefault(p => p.Id.Id == packageId); |
| 105 | var exePackageSymbol = section.Symbols.OfType<WixBundleExePackageSymbol>().SingleOrDefault(p => p.Id.Id == packageId); | 124 | var exePackageSymbol = section.Symbols.OfType<WixBundleExePackageSymbol>().SingleOrDefault(p => p.Id.Id == packageId); |
| 125 | |||
| 106 | if (packageSymbol == null || exePackageSymbol == null || exePackageSymbol.DetectionType != WixBundleExePackageDetectionType.Arp) | 126 | if (packageSymbol == null || exePackageSymbol == null || exePackageSymbol.DetectionType != WixBundleExePackageDetectionType.Arp) |
| 107 | { | 127 | { |
| 128 | this.TestContext.TestOutputHelper.WriteLine($"Missing config for ExePackage {packageId}"); | ||
| 129 | |||
| 108 | arpId = null; | 130 | arpId = null; |
| 109 | arpVersion = null; | 131 | arpVersion = null; |
| 110 | arpWin64 = false; | 132 | arpWin64 = false; |
| 111 | perMachine = false; | 133 | perMachine = false; |
| 134 | |||
| 112 | return false; | 135 | return false; |
| 113 | } | 136 | } |
| 114 | 137 | ||
| 115 | arpId = exePackageSymbol.ArpId; | 138 | arpId = exePackageSymbol.ArpId; |
| 116 | arpVersion = exePackageSymbol.ArpDisplayVersion; | 139 | arpVersion = exePackageSymbol.ArpDisplayVersion; |
| 117 | arpWin64 = exePackageSymbol.ArpWin64; | 140 | arpWin64 = exePackageSymbol.ArpWin64; |
| 118 | perMachine = packageSymbol.PerMachine == true; | 141 | perMachine = packageSymbol.Scope == WixBundleScopeType.PerMachine; |
| 142 | |||
| 143 | this.TestContext.TestOutputHelper.WriteLine($"Config for ExePackage {packageId}: arpId={arpId}, arpVersion={arpVersion}, arpWin64={arpWin64}, perMachine={perMachine}"); | ||
| 144 | |||
| 119 | return true; | 145 | return true; |
| 120 | } | 146 | } |
| 121 | 147 | ||
| 122 | public bool TryGetRegistration(out BundleRegistration registration) | 148 | public bool TryGetRegistration(bool? plannedPerMachine, out BundleRegistration registration) |
| 123 | { | 149 | { |
| 124 | var bundleSymbol = this.GetBundleSymbol(); | 150 | var bundleSymbol = this.GetBundleSymbol(); |
| 125 | var x64 = bundleSymbol.Platform != Platform.X86; | 151 | var x64 = bundleSymbol.Platform != Platform.X86; |
| 126 | var bundleCode = bundleSymbol.BundleCode; | 152 | var bundleCode = bundleSymbol.BundleCode; |
| 127 | if (bundleSymbol.PerMachine) | 153 | |
| 154 | if (bundleSymbol.Scope == WixBundleScopeType.PerMachine) | ||
| 155 | { | ||
| 156 | return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleCode, x64, this.TestContext.TestOutputHelper, out registration); | ||
| 157 | } | ||
| 158 | else if (bundleSymbol.Scope == WixBundleScopeType.PerUser) | ||
| 128 | { | 159 | { |
| 129 | return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleCode, x64, out registration); | 160 | return BundleRegistration.TryGetPerUserBundleRegistrationById(bundleCode, this.TestContext.TestOutputHelper, out registration); |
| 130 | } | 161 | } |
| 131 | else | 162 | else |
| 132 | { | 163 | { |
| 133 | return BundleRegistration.TryGetPerUserBundleRegistrationById(bundleCode, out registration); | 164 | return plannedPerMachine.Value ? BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleCode, x64, this.TestContext.TestOutputHelper, out registration) |
| 165 | : BundleRegistration.TryGetPerUserBundleRegistrationById(bundleCode, this.TestContext.TestOutputHelper, out registration); | ||
| 134 | } | 166 | } |
| 135 | } | 167 | } |
| 136 | 168 | ||
| 137 | public bool TryGetUpdateRegistration(out BundleUpdateRegistration registration) | 169 | public bool TryGetUpdateRegistration(bool? plannedPerMachine, out BundleUpdateRegistration registration) |
| 138 | { | 170 | { |
| 139 | var bundleSymbol = this.GetBundleSymbol(); | 171 | var bundleSymbol = this.GetBundleSymbol(); |
| 140 | var x64 = bundleSymbol.Platform != Platform.X86; | 172 | var x64 = bundleSymbol.Platform != Platform.X86; |
| @@ -144,84 +176,93 @@ namespace WixTestTools | |||
| 144 | var productFamily = updateRegistrationSymbol.ProductFamily; | 176 | var productFamily = updateRegistrationSymbol.ProductFamily; |
| 145 | var name = updateRegistrationSymbol.Name; | 177 | var name = updateRegistrationSymbol.Name; |
| 146 | 178 | ||
| 147 | 179 | if (bundleSymbol.Scope == WixBundleScopeType.PerMachine) | |
| 148 | if (bundleSymbol.PerMachine) | ||
| 149 | { | 180 | { |
| 150 | return BundleUpdateRegistration.TryGetPerMachineBundleUpdateRegistration(manufacturer, productFamily, name, x64, out registration); | 181 | return BundleUpdateRegistration.TryGetPerMachineBundleUpdateRegistration(manufacturer, productFamily, name, x64, out registration); |
| 151 | } | 182 | } |
| 152 | else | 183 | else if (bundleSymbol.Scope == WixBundleScopeType.PerUser) |
| 153 | { | 184 | { |
| 154 | return BundleUpdateRegistration.TryGetPerUserBundleUpdateRegistration(manufacturer, productFamily, name, out registration); | 185 | return BundleUpdateRegistration.TryGetPerUserBundleUpdateRegistration(manufacturer, productFamily, name, out registration); |
| 155 | } | 186 | } |
| 187 | else | ||
| 188 | { | ||
| 189 | return plannedPerMachine.Value ? BundleUpdateRegistration.TryGetPerMachineBundleUpdateRegistration(manufacturer, productFamily, name, x64, out registration) | ||
| 190 | : BundleUpdateRegistration.TryGetPerUserBundleUpdateRegistration(manufacturer, productFamily, name, out registration); | ||
| 191 | } | ||
| 156 | } | 192 | } |
| 157 | 193 | ||
| 158 | public BundleRegistration VerifyRegisteredAndInPackageCache(int? expectedSystemComponent = null) | 194 | public BundleRegistration VerifyRegisteredAndInPackageCache(int? expectedSystemComponent = null, bool? plannedPerMachine = null) |
| 159 | { | 195 | { |
| 160 | Assert.True(this.TryGetRegistration(out var registration)); | 196 | Assert.True(this.TryGetRegistration(plannedPerMachine, out var registration)); |
| 161 | 197 | ||
| 162 | Assert.Equal(expectedSystemComponent, registration.SystemComponent); | 198 | Assert.Equal(expectedSystemComponent, registration.SystemComponent); |
| 163 | 199 | ||
| 164 | Assert.NotNull(registration.CachePath); | 200 | Assert.NotNull(registration.CachePath); |
| 165 | Assert.True(File.Exists(registration.CachePath)); | 201 | Assert.True(File.Exists(registration.CachePath)); |
| 166 | 202 | ||
| 167 | var expectedCachePath = this.GetExpectedCachedBundlePath(); | 203 | var expectedCachePath = this.GetExpectedCachedBundlePath(plannedPerMachine); |
| 168 | WixAssert.StringEqual(expectedCachePath, registration.CachePath, true); | 204 | WixAssert.StringEqual(expectedCachePath, registration.CachePath, true); |
| 169 | 205 | ||
| 170 | return registration; | 206 | return registration; |
| 171 | } | 207 | } |
| 172 | 208 | ||
| 173 | public void VerifyUnregisteredAndRemovedFromPackageCache() | 209 | public void VerifyUnregisteredAndRemovedFromPackageCache(bool? plannedPerMachine = null) |
| 174 | { | 210 | { |
| 175 | var cachedBundlePath = this.GetExpectedCachedBundlePath(); | 211 | var cachedBundlePath = this.GetExpectedCachedBundlePath(plannedPerMachine); |
| 176 | this.VerifyUnregisteredAndRemovedFromPackageCache(cachedBundlePath); | 212 | |
| 213 | this.VerifyUnregisteredAndRemovedFromPackageCache(cachedBundlePath, plannedPerMachine); | ||
| 177 | } | 214 | } |
| 178 | 215 | ||
| 179 | public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath) | 216 | public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath, bool? plannedPerMachine = null) |
| 180 | { | 217 | { |
| 181 | Assert.False(this.TryGetRegistration(out _), $"Bundle cached at '{cachedBundlePath}' should not still be registered."); | 218 | Assert.False(this.TryGetRegistration(plannedPerMachine, out _), $"Bundle cached at '{cachedBundlePath}' should not still be registered."); |
| 182 | Assert.False(File.Exists(cachedBundlePath), $"Cached bundle should have been removed from package cache at '{cachedBundlePath}'."); | 219 | Assert.False(File.Exists(cachedBundlePath), $"Cached bundle should have been removed from package cache at '{cachedBundlePath}'."); |
| 183 | } | 220 | } |
| 184 | 221 | ||
| 185 | public void RemovePackageFromCache(string packageId) | 222 | public void RemovePackageFromCache(string packageId, bool? plannedPerMachine = null) |
| 186 | { | 223 | { |
| 187 | using var wixOutput = WixOutput.Read(this.BundlePdb); | 224 | using var wixOutput = WixOutput.Read(this.BundlePdb); |
| 188 | var intermediate = Intermediate.Load(wixOutput); | 225 | var intermediate = Intermediate.Load(wixOutput); |
| 189 | var section = intermediate.Sections.Single(); | 226 | var section = intermediate.Sections.Single(); |
| 190 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); | 227 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); |
| 191 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId, packageSymbol.PerMachine == true); | 228 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId, packageSymbol.Scope, plannedPerMachine); |
| 229 | |||
| 192 | if (Directory.Exists(cachePath)) | 230 | if (Directory.Exists(cachePath)) |
| 193 | { | 231 | { |
| 194 | Directory.Delete(cachePath, true); | 232 | Directory.Delete(cachePath, true); |
| 195 | } | 233 | } |
| 196 | } | 234 | } |
| 197 | 235 | ||
| 198 | public string GetPackageEntryPointCachePath(string packageId) | 236 | public string GetPackageEntryPointCachePath(string packageId, bool? plannedPerMachine = null) |
| 199 | { | 237 | { |
| 200 | using var wixOutput = WixOutput.Read(this.BundlePdb); | 238 | using var wixOutput = WixOutput.Read(this.BundlePdb); |
| 201 | var intermediate = Intermediate.Load(wixOutput); | 239 | var intermediate = Intermediate.Load(wixOutput); |
| 202 | var section = intermediate.Sections.Single(); | 240 | var section = intermediate.Sections.Single(); |
| 203 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); | 241 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); |
| 204 | var packagePayloadSymbol = section.Symbols.OfType<WixBundlePayloadSymbol>().Single(p => p.Id.Id == packageSymbol.PayloadRef); | 242 | var packagePayloadSymbol = section.Symbols.OfType<WixBundlePayloadSymbol>().Single(p => p.Id.Id == packageSymbol.PayloadRef); |
| 205 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId, packageSymbol.PerMachine == true); | 243 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId, packageSymbol.Scope, plannedPerMachine); |
| 244 | |||
| 206 | return Path.Combine(cachePath, packagePayloadSymbol.Name); | 245 | return Path.Combine(cachePath, packagePayloadSymbol.Name); |
| 207 | } | 246 | } |
| 208 | 247 | ||
| 209 | public void VerifyPackageIsCached(string packageId, bool cached = true) | 248 | public void VerifyPackageIsCached(string packageId, bool cached = true, bool? plannedPerMachine = null) |
| 210 | { | 249 | { |
| 211 | var entryPointCachePath = this.GetPackageEntryPointCachePath(packageId); | 250 | var entryPointCachePath = this.GetPackageEntryPointCachePath(packageId, plannedPerMachine); |
| 251 | |||
| 212 | Assert.Equal(cached, File.Exists(entryPointCachePath)); | 252 | Assert.Equal(cached, File.Exists(entryPointCachePath)); |
| 213 | } | 253 | } |
| 214 | 254 | ||
| 215 | public void VerifyPackageProviderRemoved(string packageId) | 255 | public void VerifyPackageProviderRemoved(string packageId, bool? plannedPerMachine = null) |
| 216 | { | 256 | { |
| 217 | using var wixOutput = WixOutput.Read(this.BundlePdb); | 257 | using var wixOutput = WixOutput.Read(this.BundlePdb); |
| 218 | var intermediate = Intermediate.Load(wixOutput); | 258 | var intermediate = Intermediate.Load(wixOutput); |
| 219 | var section = intermediate.Sections.Single(); | 259 | var section = intermediate.Sections.Single(); |
| 220 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); | 260 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); |
| 221 | var providerSymbol = section.Symbols.OfType<WixDependencyProviderSymbol>().Single(p => p.ParentRef == packageId); | 261 | var providerSymbol = section.Symbols.OfType<WixDependencyProviderSymbol>().Single(p => p.ParentRef == packageId); |
| 222 | var registryRoot = packageSymbol.PerMachine == true ? Registry.LocalMachine : Registry.CurrentUser; | 262 | var registryRoot = plannedPerMachine.HasValue ? (plannedPerMachine.Value ? Registry.LocalMachine : Registry.CurrentUser) : packageSymbol.Scope == WixBundleScopeType.PerMachine ? Registry.LocalMachine : Registry.CurrentUser; |
| 223 | var subkeyPath = Path.Combine(DependencyRegistryRoot, providerSymbol.ProviderKey); | 263 | var subkeyPath = Path.Combine(DependencyRegistryRoot, providerSymbol.ProviderKey); |
| 224 | using var registryKey = registryRoot.OpenSubKey(subkeyPath); | 264 | using var registryKey = registryRoot.OpenSubKey(subkeyPath); |
| 265 | |||
| 225 | if (registryKey != null) | 266 | if (registryKey != null) |
| 226 | { | 267 | { |
| 227 | WixAssert.StringEqual(null, subkeyPath); | 268 | WixAssert.StringEqual(null, subkeyPath); |
