main
cs 401 lines 19.5 KB
Raw
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.Collections.Generic;
6 using System.IO;
7 using System.Linq;
8 using System.Xml;
9 using WixInternal.TestSupport;
10 using WixInternal.Core.TestPackage;
11 using Xunit;
12
13 public class PackagePayloadFixture
14 {
15 [Fact]
16 public void CanSpecifyMsiPackagePayloadInPayloadGroup()
17 {
18 var folder = TestData.Get(@"TestData");
19
20 using (var fs = new DisposableFileSystem())
21 {
22 var baseFolder = fs.GetFolder();
23 var intermediateFolder = Path.Combine(baseFolder, "obj");
24 var bundlePath = Path.Combine(baseFolder, @"bin\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, "PackagePayload", "MsiPackagePayloadInPayloadGroup.wxs"),
32 Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"),
33 "-bindpath", Path.Combine(folder, "SimpleBundle", "data"),
34 "-bindpath", Path.Combine(folder, ".Data"),
35 "-intermediateFolder", intermediateFolder,
36 "-o", bundlePath,
37 });
38
39 result.AssertSuccess();
40
41 Assert.True(File.Exists(bundlePath));
42
43 var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath);
44 extractResult.AssertSuccess();
45
46 var ignoreAttributesByElementName = new Dictionary<string, List<string>>
47 {
48 { "ExePackage", new List<string> { "CacheId", "InstallSize", "Size" } },
49 };
50 var msiPackageElements = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/burn:MsiPackage", ignoreAttributesByElementName);
51 WixAssert.CompareLineByLine(new[]
52 {
53 "<MsiPackage Id='MsiWithFeatures' Cache='keep' CacheId='{040011E1-F84C-4927-AD62-50A5EC19CA32}v1.0.0.0_1' InstallSize='34' Size='32803' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryForward='WixDefaultBoundary' LogPathVariable='WixBundleLog_MsiWithFeatures' RollbackLogPathVariable='WixBundleRollbackLog_MsiWithFeatures' ProductCode='{040011E1-F84C-4927-AD62-50A5EC19CA32}' Language='1033' Version='1.0.0.0' UpgradeCode='{047730A5-30FE-4A62-A520-DA9381B8226A}'>" +
54 "<MsiFeature Id='ProductFeature' /><MsiProperty Id='ARPSYSTEMCOMPONENT' Value='1' /><MsiProperty Id='MSIFASTINSTALL' Value='7' /><Provides Key='{040011E1-F84C-4927-AD62-50A5EC19CA32}_v1.0.0.0' Version='1.0.0.0' DisplayName='MsiPackage' />" +
55 "<RelatedPackage Id='{047730A5-30FE-4A62-A520-DA9381B8226A}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
56 "<RelatedPackage Id='{047730A5-30FE-4A62-A520-DA9381B8226A}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
57 "<PayloadRef Id='test.msi' /><PayloadRef Id='fhuZsOcBDTuIX8rF96kswqI6SnuI' /><PayloadRef Id='faf_OZ741BG7SJ6ZkcIvivZ2Yzo8' />" +
58 "</MsiPackage>",
59
60 "<MsiPackage Id='MsiWithoutFeatures' Cache='keep' CacheId='{040011E1-F84C-4927-AD62-50A5EC19CA32}v1.0.0.0_2' InstallSize='34' Size='32803' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryBackward='WixDefaultBoundary' LogPathVariable='WixBundleLog_MsiWithoutFeatures' RollbackLogPathVariable='WixBundleRollbackLog_MsiWithoutFeatures' ProductCode='{040011E1-F84C-4927-AD62-50A5EC19CA32}' Language='1033' Version='1.0.0.0' UpgradeCode='{047730A5-30FE-4A62-A520-DA9381B8226A}'>" +
61 "<MsiProperty Id='ARPSYSTEMCOMPONENT' Value='1' /><MsiProperty Id='MSIFASTINSTALL' Value='7' /><Provides Key='{040011E1-F84C-4927-AD62-50A5EC19CA32}_v1.0.0.0' Version='1.0.0.0' DisplayName='MsiPackage' />" +
62 "<RelatedPackage Id='{047730A5-30FE-4A62-A520-DA9381B8226A}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
63 "<RelatedPackage Id='{047730A5-30FE-4A62-A520-DA9381B8226A}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" +
64 "<PayloadRef Id='test.msi' /><PayloadRef Id='fhuZsOcBDTuIX8rF96kswqI6SnuI' /><PayloadRef Id='faf_OZ741BG7SJ6ZkcIvivZ2Yzo8' />" +
65 "</MsiPackage>",
66 }, msiPackageElements);
67
68 var packageElements = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixPackageProperties");
69 WixAssert.CompareLineByLine(new[]
70 {
71 "<WixPackageProperties Package='MsiWithFeatures' Vital='yes' DisplayName='MsiPackage' DownloadSize='32803' PackageSize='32803' InstalledSize='34' PackageType='Msi' Permanent='no' LogPathVariable='WixBundleLog_MsiWithFeatures' RollbackLogPathVariable='WixBundleRollbackLog_MsiWithFeatures' Compressed='yes' ProductCode='{040011E1-F84C-4927-AD62-50A5EC19CA32}' UpgradeCode='{047730A5-30FE-4A62-A520-DA9381B8226A}' Version='1.0.0.0' Cache='keep' />",
72 "<WixPackageProperties Package='MsiWithoutFeatures' Vital='yes' DisplayName='MsiPackage' DownloadSize='32803' PackageSize='32803' InstalledSize='34' PackageType='Msi' Permanent='no' LogPathVariable='WixBundleLog_MsiWithoutFeatures' RollbackLogPathVariable='WixBundleRollbackLog_MsiWithoutFeatures' Compressed='yes' ProductCode='{040011E1-F84C-4927-AD62-50A5EC19CA32}' UpgradeCode='{047730A5-30FE-4A62-A520-DA9381B8226A}' Version='1.0.0.0' Cache='keep' />",
73 }, packageElements);
74
75 var featureElements = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixPackageFeatureInfo");
76 WixAssert.CompareLineByLine(new[]
77 {
78 "<WixPackageFeatureInfo Package='MsiWithFeatures' Feature='ProductFeature' Size='34' Display='2' Level='1' Directory='' Attributes='0' />",
79 }, featureElements);
80 }
81 }
82
83 [Fact]
84 public void CanSpecifyExePackagePayloadInPayloadGroup()
85 {
86 var folder = TestData.Get(@"TestData");
87
88 using (var fs = new DisposableFileSystem())
89 {
90 var baseFolder = fs.GetFolder();
91 var intermediateFolder = Path.Combine(baseFolder, "obj");
92 var bundlePath = Path.Combine(baseFolder, @"bin\test.exe");
93 var baFolderPath = Path.Combine(baseFolder, "ba");
94 var extractFolderPath = Path.Combine(baseFolder, "extract");
95
96 var result = WixRunner.Execute(new[]
97 {
98 "build",
99 Path.Combine(folder, "PackagePayload", "PackagePayloadInPayloadGroup.wxs"),
100 Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"),
101 "-bindpath", Path.Combine(folder, "SimpleBundle", "data"),
102 "-bindpath", Path.Combine(folder, ".Data"),
103 "-intermediateFolder", intermediateFolder,
104 "-o", bundlePath,
105 });
106
107 result.AssertSuccess();
108
109 Assert.True(File.Exists(bundlePath));
110
111 var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath);
112 extractResult.AssertSuccess();
113
114 var ignoreAttributesByElementName = new Dictionary<string, List<string>>
115 {
116 { "ExePackage", new List<string> { "CacheId", "InstallSize", "Size" } },
117 };
118 var exePackageElements = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/burn:ExePackage", ignoreAttributesByElementName);
119 WixAssert.CompareLineByLine(new[]
120 {
121 "<ExePackage Id='PackagePayloadInPayloadGroup' Cache='keep' CacheId='*' InstallSize='*' Size='*' PerMachine='yes' Permanent='yes' Vital='yes' RollbackBoundaryForward='WixDefaultBoundary' RollbackBoundaryBackward='WixDefaultBoundary' LogPathVariable='WixBundleLog_PackagePayloadInPayloadGroup' RollbackLogPathVariable='WixBundleRollbackLog_PackagePayloadInPayloadGroup' InstallArguments='' RepairArguments='' Repairable='no' DetectionType='condition' DetectCondition='none'><PayloadRef Id='burn.exe' /></ExePackage>",
122 }, exePackageElements);
123
124 var payloadElements = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Payload[@Id='burn.exe']");
125 WixAssert.CompareLineByLine(new[]
126 {
127 "<Payload Id='burn.exe' FilePath='burn.exe' FileSize='463360' Hash='F6E722518AC3AB7E31C70099368D5770788C179AA23226110DCF07319B1E1964E246A1E8AE72E2CF23E0138AFC281BAFDE45969204405E114EB20C8195DA7E5E' Packaging='embedded' SourcePath='a0' Container='WixAttachedContainer' />",
128 }, payloadElements);
129 }
130 }
131
132 [Fact]
133 public void CanSpecifyExePackagePayloadWithCertificate()
134 {
135 var folder = TestData.Get(@"TestData", "PackagePayload");
136
137 using (var fs = new DisposableFileSystem())
138 {
139 var baseFolder = fs.GetFolder();
140
141 var result = WixRunner.Execute(new[]
142 {
143 "build",
144 Path.Combine(folder, "SpecifiedCertificate.wxs"),
145 "-o", Path.Combine(baseFolder, "test.wixlib")
146 });
147
148 result.AssertSuccess();
149 }
150 }
151
152 [Fact]
153 public void ErrorWhenMissingSourceFileAndHash()
154 {
155 var folder = TestData.Get(@"TestData", "PackagePayload");
156
157 using (var fs = new DisposableFileSystem())
158 {
159 var baseFolder = fs.GetFolder();
160
161 var result = WixRunner.Execute(false, new[]
162 {
163 "build",
164 Path.Combine(folder, "MissingSourceFileAndHash.wxs"),
165 "-o", Path.Combine(baseFolder, "test.wixlib")
166 });
167
168 Assert.Equal(44, result.ExitCode);
169 WixAssert.CompareLineByLine(new[]
170 {
171 "The MsuPackagePayload element's SourceFile, CertificatePublicKey, or Hash attribute was not found; one of these is required.",
172 }, result.Messages.Select(m => m.ToString()).ToArray());
173 }
174 }
175
176 [Fact]
177 public void ErrorWhenMissingSourceFileAndName()
178 {
179 var folder = TestData.Get(@"TestData", "PackagePayload");
180
181 using (var fs = new DisposableFileSystem())
182 {
183 var baseFolder = fs.GetFolder();
184
185 var result = WixRunner.Execute(false, new[]
186 {
187 "build",
188 Path.Combine(folder, "MissingSourceFileAndName.wxs"),
189 "-o", Path.Combine(baseFolder, "test.wixlib")
190 });
191
192 Assert.Equal(44, result.ExitCode);
193 WixAssert.CompareLineByLine(new[]
194 {
195 "The MsiPackagePayload element's Name or SourceFile attribute was not found; one of these is required.",
196 }, result.Messages.Select(m => m.ToString()).ToArray());
197 }
198 }
199
200 [Fact]
201 public void ErrorWhenSpecifiedHash()
202 {
203 var folder = TestData.Get(@"TestData", "PackagePayload");
204
205 using (var fs = new DisposableFileSystem())
206 {
207 var baseFolder = fs.GetFolder();
208
209 var result = WixRunner.Execute(new[]
210 {
211 "build",
212 Path.Combine(folder, "SpecifiedHash.wxs"),
213 "-o", Path.Combine(baseFolder, "test.wixlib")
214 });
215
216 Assert.Equal(4, result.ExitCode);
217 WixAssert.CompareLineByLine(new[]
218 {
219 "The MspPackagePayload element contains an unexpected attribute 'Hash'.",
220 }, result.Messages.Select(m => m.ToString()).ToArray());
221 }
222 }
223
224 [Fact]
225 public void ErrorWhenSpecifiedHashAndMissingDownloadUrl()
226 {
227 var folder = TestData.Get(@"TestData", "PackagePayload");
228
229 using (var fs = new DisposableFileSystem())
230 {
231 var baseFolder = fs.GetFolder();
232
233 var result = WixRunner.Execute(new[]
234 {
235 "build",
236 Path.Combine(folder, "SpecifiedHashAndMissingDownloadUrl.wxs"),
237 "-o", Path.Combine(baseFolder, "test.wixlib")
238 });
239
240 Assert.Equal(408, result.ExitCode);
241 WixAssert.CompareLineByLine(new[]
242 {
243 "The MsuPackagePayload element's DownloadUrl attribute was not found; it is required without attribute SourceFile present.",
244 }, result.Messages.Select(m => m.ToString()).ToArray());
245 }
246 }
247
248 [Fact]
249 public void ErrorWhenSpecifiedSourceFileAndHash()
250 {
251 var folder = TestData.Get(@"TestData", "PackagePayload");
252
253 using (var fs = new DisposableFileSystem())
254 {
255 var baseFolder = fs.GetFolder();
256
257 var result = WixRunner.Execute(new[]
258 {
259 "build",
260 Path.Combine(folder, "SpecifiedSourceFileAndHash.wxs"),
261 "-o", Path.Combine(baseFolder, "test.wixlib")
262 });
263
264 Assert.Equal(35, result.ExitCode);
265 WixAssert.CompareLineByLine(new[]
266 {
267 "The ExePackagePayload/@Hash attribute cannot be specified when attribute SourceFile is present.",
268 }, result.Messages.Select(m => m.ToString()).ToArray());
269 }
270 }
271
272 [Fact]
273 public void ErrorWhenSpecifiedSourceFileAndCertificatePublicKey()
274 {
275 var folder = TestData.Get(@"TestData", "PackagePayload");
276
277 using (var fs = new DisposableFileSystem())
278 {
279 var baseFolder = fs.GetFolder();
280
281 var result = WixRunner.Execute(new[]
282 {
283 "build",
284 Path.Combine(folder, "SpecifiedSourceFileAndCertificatePublicKey.wxs"),
285 "-o", Path.Combine(baseFolder, "test.wixlib")
286 });
287
288 WixAssert.CompareLineByLine(new[]
289 {
290 "The ExePackagePayload/@CertificatePublicKey attribute cannot be specified when attribute SourceFile is present.",
291 }, result.Messages.Select(m => m.ToString()).ToArray());
292 Assert.Equal(35, result.ExitCode);
293 }
294 }
295
296 [Fact]
297 public void ErrorWhenSpecifiedSourceFileAndCertificateThumprint()
298 {
299 var folder = TestData.Get(@"TestData", "PackagePayload");
300
301 using (var fs = new DisposableFileSystem())
302 {
303 var baseFolder = fs.GetFolder();
304
305 var result = WixRunner.Execute(new[]
306 {
307 "build",
308 Path.Combine(folder, "SpecifiedSourceFileAndCertificateThumbprint.wxs"),
309 "-o", Path.Combine(baseFolder, "test.wixlib")
310 });
311
312 WixAssert.CompareLineByLine(new[]
313 {
314 "The ExePackagePayload/@CertificateThumbprint attribute cannot be specified when attribute SourceFile is present.",
315 }, result.Messages.Select(m => m.ToString()).ToArray());
316 Assert.Equal(35, result.ExitCode);
317 }
318 }
319
320 [Fact]
321 public void ErrorWhenSpecifiedCertificateThumbprintWithoutPublicKey()
322 {
323 var folder = TestData.Get(@"TestData", "PackagePayload");
324
325 using (var fs = new DisposableFileSystem())
326 {
327 var baseFolder = fs.GetFolder();
328
329 var result = WixRunner.Execute(new[]
330 {
331 "build",
332 Path.Combine(folder, "SpecifiedHashAndCertificatePublicKey.wxs"),
333 "-o", Path.Combine(baseFolder, "test.wixlib")
334 });
335
336 WixAssert.CompareLineByLine(new[]
337 {
338 "The ExePackagePayload/@CertificatePublicKey attribute was not found; it is required when attribute CertificateThumbprint is specified.",
339 "The ExePackagePayload/@Hash attribute cannot be specified when attribute CertificateThumbprint is present."
340 }, result.Messages.Select(m => m.ToString()).ToArray());
341 Assert.Equal(35, result.ExitCode);
342 }
343 }
344
345 [Fact]
346 public void ErrorWhenSpecifiedCertificatePublicKeyWithoutThumbprint()
347 {
348 var folder = TestData.Get(@"TestData", "PackagePayload");
349
350 using (var fs = new DisposableFileSystem())
351 {
352 var baseFolder = fs.GetFolder();
353
354 var result = WixRunner.Execute(new[]
355 {
356 "build",
357 Path.Combine(folder, "SpecifiedCertificatePublicKeyWithoutThumbprint.wxs"),
358 "-o", Path.Combine(baseFolder, "test.wixlib")
359 });
360
361 WixAssert.CompareLineByLine(new[]
362 {
363 "The ExePackagePayload/@CertificateThumbprint attribute was not found; it is required when attribute CertificatePublicKey is specified.",
364 }, result.Messages.Select(m => m.ToString()).ToArray());
365 Assert.Equal(10, result.ExitCode);
366 }
367 }
368
369 [Fact]
370 public void ErrorWhenWrongPackagePayloadInPayloadGroup()
371 {
372 var folder = TestData.Get(@"TestData");
373
374 using (var fs = new DisposableFileSystem())
375 {
376 var baseFolder = fs.GetFolder();
377 var intermediateFolder = Path.Combine(baseFolder, "obj");
378 var bundlePath = Path.Combine(baseFolder, @"bin\test.exe");
379
380 var result = WixRunner.Execute(new[]
381 {
382 "build",
383 Path.Combine(folder, "PackagePayload", "WrongPackagePayloadInPayloadGroup.wxs"),
384 Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"),
385 "-bindpath", Path.Combine(folder, "SimpleBundle", "data"),
386 "-bindpath", Path.Combine(folder, ".Data"),
387 "-intermediateFolder", intermediateFolder,
388 "-o", bundlePath,
389 });
390
391 Assert.Equal(407, result.ExitCode);
392 WixAssert.CompareLineByLine(new[]
393 {
394 "The ExePackagePayload element can only be used for ExePackages.",
395 "The location of the package related to previous error.",
396 "There is no payload defined for package 'WrongPackagePayloadInPayloadGroup'. This is specified on the MsiPackage element or a child MsiPackagePayload element.",
397 }, result.Messages.Select(m => m.ToString()).ToArray());
398 }
399 }
400 }
401 }