| 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.CoreIntegration |
| 4 | { |
| 5 | using System.IO; |
| 6 | using System.Linq; |
| 7 | using WixInternal.TestSupport; |
| 8 | using WixInternal.Core.TestPackage; |
| 9 | using Xunit; |
| 10 | |
| 11 | public class MsuPackageFixture |
| 12 | { |
| 13 | [Fact] |
| 14 | public void CanBuildBundleWithMsuPackage() |
| 15 | { |
| 16 | var dotDatafolder = TestData.Get(@"TestData", ".Data"); |
| 17 | var folder = TestData.Get(@"TestData", "MsuPackage"); |
| 18 | |
| 19 | using (var fs = new DisposableFileSystem()) |
| 20 | { |
| 21 | var baseFolder = fs.GetFolder(); |
| 22 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 23 | var binFolder = Path.Combine(baseFolder, "bin"); |
| 24 | var bundlePath = Path.Combine(binFolder, "test.exe"); |
| 25 | var baFolderPath = Path.Combine(baseFolder, "ba"); |
| 26 | var extractFolderPath = Path.Combine(baseFolder, "extract"); |
| 27 | |
| 28 | var result = WixRunner.Execute(new[] |
| 29 | { |
| 30 | "build", |
| 31 | Path.Combine(folder, "Bundle.wxs"), |
| 32 | "-bindpath", Path.Combine(folder, "data"), |
| 33 | "-bindpath", dotDatafolder, |
| 34 | "-intermediateFolder", intermediateFolder, |
| 35 | "-o", bundlePath, |
| 36 | }); |
| 37 | |
| 38 | result.AssertSuccess(); |
| 39 | Assert.True(File.Exists(bundlePath)); |
| 40 | |
| 41 | var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath); |
| 42 | extractResult.AssertSuccess(); |
| 43 | |
| 44 | var msuPackages = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/burn:MsuPackage"); |
| 45 | WixAssert.CompareLineByLine(new string[] |
| 46 | { |
| 47 | "<MsuPackage Id='test.msu' Cache='keep' CacheId='B040F02D2F90E04E9AFBDC91C00CEB5DF97D48E205D96DC0A44E10AF8870794D' InstallSize='28' Size='28' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryForward='WixDefaultBoundary' RollbackBoundaryBackward='WixDefaultBoundary' DetectCondition='DetectedTheMsu'>" + |
| 48 | "<PayloadRef Id='test.msu' />" + |
| 49 | "</MsuPackage>", |
| 50 | }, msuPackages); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | [Fact] |
| 55 | public void CanBuildBundleWithMsuPackageUsingCertificateVerification() |
| 56 | { |
| 57 | var dotDatafolder = TestData.Get(@"TestData", ".Data"); |
| 58 | var folder = TestData.Get(@"TestData", "MsuPackage"); |
| 59 | |
| 60 | using (var fs = new DisposableFileSystem()) |
| 61 | { |
| 62 | var baseFolder = fs.GetFolder(); |
| 63 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 64 | var binFolder = Path.Combine(baseFolder, "bin"); |
| 65 | var bundlePath = Path.Combine(binFolder, "test.exe"); |
| 66 | var baFolderPath = Path.Combine(baseFolder, "ba"); |
| 67 | var extractFolderPath = Path.Combine(baseFolder, "extract"); |
| 68 | |
| 69 | var result = WixRunner.Execute(new[] |
| 70 | { |
| 71 | "build", |
| 72 | Path.Combine(folder, "BundleUsingCertificateVerification.wxs"), |
| 73 | "-bindpath", Path.Combine(folder, "data"), |
| 74 | "-bindpath", dotDatafolder, |
| 75 | "-intermediateFolder", intermediateFolder, |
| 76 | "-o", bundlePath, |
| 77 | }); |
| 78 | |
| 79 | result.AssertSuccess(); |
| 80 | Assert.True(File.Exists(bundlePath)); |
| 81 | |
| 82 | var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath); |
| 83 | extractResult.AssertSuccess(); |
| 84 | |
| 85 | var msuPackages = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/burn:MsuPackage"); |
| 86 | WixAssert.CompareLineByLine(new string[] |
| 87 | { |
| 88 | "<MsuPackage Id='Windows8.1_KB2937592_x86.msu' Cache='keep' CacheId='8cf75b99-13c0-4184-82ce-dbde45dcd55a' InstallSize='309544' Size='309544' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryForward='WixDefaultBoundary' RollbackBoundaryBackward='WixDefaultBoundary' DetectCondition='DetectedTheMsu'>" + |
| 89 | "<PayloadRef Id='Windows8.1_KB2937592_x86.msu' />" + |
| 90 | "</MsuPackage>", |
| 91 | }, msuPackages); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | [Fact] |
| 96 | public void CannotBuildBundleWithMsuPackageUsingCertificateVerificationWithoutCacheId() |
| 97 | { |
| 98 | var dotDatafolder = TestData.Get(@"TestData", ".Data"); |
| 99 | var folder = TestData.Get(@"TestData", "MsuPackage"); |
| 100 | |
| 101 | using (var fs = new DisposableFileSystem()) |
| 102 | { |
| 103 | var baseFolder = fs.GetFolder(); |
| 104 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 105 | |
| 106 | var result = WixRunner.Execute(new[] |
| 107 | { |
| 108 | "build", |
| 109 | Path.Combine(folder, "BundleUsingCertificateVerificationWithoutCacheId.wxs"), |
| 110 | "-bindpath", Path.Combine(folder, "data"), |
| 111 | "-bindpath", dotDatafolder, |
| 112 | "-intermediateFolder", intermediateFolder, |
| 113 | "-o", Path.Combine(baseFolder, "bin", "test.exe") |
| 114 | }); |
| 115 | |
| 116 | WixAssert.CompareLineByLine(new[] |
| 117 | { |
| 118 | "The MsuPackage/@CacheId attribute was not found; it is required when attribute CertificatePublicKey is specified.", |
| 119 | }, result.Messages.Select(m => m.ToString()).ToArray()); |
| 120 | |
| 121 | Assert.Equal(10, result.ExitCode); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | [Fact] |
| 126 | public void ErrorWhenSpecifyingPermanent() |
| 127 | { |
| 128 | var folder = TestData.Get(@"TestData", "MsuPackage"); |
| 129 | |
| 130 | using (var fs = new DisposableFileSystem()) |
| 131 | { |
| 132 | var baseFolder = fs.GetFolder(); |
| 133 | |
| 134 | var result = WixRunner.Execute(false, new[] |
| 135 | { |
| 136 | "build", |
| 137 | Path.Combine(folder, "PermanentMsuPackage.wxs"), |
| 138 | "-o", Path.Combine(baseFolder, "test.wixlib") |
| 139 | }); |
| 140 | |
| 141 | WixAssert.CompareLineByLine(new[] |
| 142 | { |
| 143 | "The MsuPackage element contains an unexpected attribute 'Permanent'.", |
| 144 | }, result.Messages.Select(m => m.ToString()).ToArray()); |
| 145 | Assert.Equal(4, result.ExitCode); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |