MSBuild tests enhanced to test signing
Rob Mensching committed
Jan 10, 2022 at 14:23 UTC
c0e933d1cec2515e1c43aa1f3b3c4bde9a17e449
5 files changed
+89
-9
src/wix/test/WixToolsetTest.CoreIntegration/TestData/.Data/signed_cab1.cab
Binary files /dev/null and b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/.Data/signed_cab1.cab differ
src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs
+51
-6
@@ -26,12 +26,19 @@ namespace WixToolsetTest.Sdk
26
var binFolder = Path.Combine(baseFolder, @"bin\");
27
var projectPath = Path.Combine(baseFolder, "SimpleBundle.wixproj");
28
29
- var result = MsbuildUtilities.BuildProject(buildSystem, projectPath);
29
+ var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { "-p:SignOutput=true" });
30
result.AssertSuccess();
31
32
var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray();
33
WixAssert.StringCollectionEmpty(warnings);
34
35
+ var testMessages = result.Output.Where(line => line.Contains("TEST:")).Select(line => line.Trim()).ToArray();
36
+ WixAssert.CompareLineByLine(new[]
37
+ {
38
+ @"TEST: SignBundleEngine: obj\x86\Release\SimpleBundle.exe",
39
+ @"TEST: SignBundle: obj\x86\Release\SimpleBundle.exe",
40
+ }, testMessages);
41
+
42
var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories)
43
.Select(s => s.Substring(baseFolder.Length + 1))
44
.OrderBy(s => s)
@@ -59,12 +66,18 @@ namespace WixToolsetTest.Sdk
66
var binFolder = Path.Combine(baseFolder, @"bin\");
67
var projectPath = Path.Combine(baseFolder, "UncompressedBundle.wixproj");
68
62
- var result = MsbuildUtilities.BuildProject(buildSystem, projectPath);
69
+ var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { "-p:SignOutput=true" });
70
result.AssertSuccess();
71
72
var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray();
73
WixAssert.StringCollectionEmpty(warnings);
74
75
+ var testMessages = result.Output.Where(line => line.Contains("TEST:")).Select(line => line.Trim()).ToArray();
76
+ WixAssert.CompareLineByLine(new[]
77
+ {
78
+ @"TEST: SignBundleEngine: obj\x86\Release\UncompressedBundle.exe",
79
+ }, testMessages);
80
+
81
var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories)
82
.Select(s => s.Substring(baseFolder.Length + 1))
83
.OrderBy(s => s)
@@ -119,21 +132,39 @@ namespace WixToolsetTest.Sdk
132
{
133
var sourceFolder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage");
134
135
+ var baseFolder = String.Empty;
136
+
137
using (var fs = new TestDataFolderFileSystem())
138
{
139
fs.Initialize(sourceFolder);
125
- var baseFolder = fs.BaseFolder;
140
+ baseFolder = fs.BaseFolder;
141
+
142
var binFolder = Path.Combine(baseFolder, @"bin\");
143
var projectPath = Path.Combine(baseFolder, "MsiPackage.wixproj");
144
129
- var result = MsbuildUtilities.BuildProject(buildSystem, projectPath);
145
+ var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { "-p:SignOutput=true" });
146
result.AssertSuccess();
147
148
var platformSwitches = result.Output.Where(line => line.Contains("-platform x86"));
149
Assert.Single(platformSwitches);
150
135
- var warnings = result.Output.Where(line => line.Contains(": warning"));
136
- Assert.Equal(4, warnings.Count());
151
+ var warnings = result.Output.Where(line => line.Contains(": warning")).Select(ExtractWarningFromMessage).ToArray();
152
+ WixAssert.CompareLineByLine(new[]
153
+ {
154
+ @"WIX1118: The variable 'Variable' with value 'DifferentValue' was previously declared with value 'Value'.",
155
+ @"WIX1102: The DefaultLanguage '1033' was used for file 'filcV1yrx0x8wJWj4qMzcH21jwkPko' which has no language or version. For unversioned files, specifying a value for DefaultLanguage is not neccessary and it will not be used when determining file versions. Remove the DefaultLanguage attribute to eliminate this warning.",
156
+ @"WIX1122: The installer database '<basefolder>\obj\x86\Release\en-US\MsiPackage.msi' has external cabs, but at least one of them is not signed. Please ensure that all external cabs are signed, if you mean to sign them. If you don't mean to sign them, there is no need to inscribe the MSI as part of your build.",
157
+ @"WIX1118: The variable 'Variable' with value 'DifferentValue' was previously declared with value 'Value'.",
158
+ @"WIX1102: The DefaultLanguage '1033' was used for file 'filcV1yrx0x8wJWj4qMzcH21jwkPko' which has no language or version. For unversioned files, specifying a value for DefaultLanguage is not neccessary and it will not be used when determining file versions. Remove the DefaultLanguage attribute to eliminate this warning.",
159
+ @"WIX1122: The installer database '<basefolder>\obj\x86\Release\en-US\MsiPackage.msi' has external cabs, but at least one of them is not signed. Please ensure that all external cabs are signed, if you mean to sign them. If you don't mean to sign them, there is no need to inscribe the MSI as part of your build."
160
+ }, warnings);
161
+
162
+ var testMessages = result.Output.Where(line => line.Contains("TEST:")).Select(ReplacePathsInMessage).ToArray();
163
+ WixAssert.CompareLineByLine(new[]
164
+ {
165
+ @"TEST: SignCabs: <basefolder>\obj\x86\Release\en-US\cab1.cab",
166
+ @"TEST: SignMsi: obj\x86\Release\en-US\MsiPackage.msi",
167
+ }, testMessages);
168
169
var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories)
170
.Select(s => s.Substring(baseFolder.Length + 1))
@@ -146,6 +177,20 @@ namespace WixToolsetTest.Sdk
177
@"bin\x86\Release\en-US\MsiPackage.wixpdb",
178
}, paths);
179
}
180
+
181
+ string ExtractWarningFromMessage(string message)
182
+ {
183
+ const string prefix = ": warning ";
184
+
185
+ var start = message.IndexOf(prefix) + prefix.Length;
186
+ var end = message.LastIndexOf("[");
187
+ return ReplacePathsInMessage(message.Substring(start, end - start));
188
+ }
189
+
190
+ string ReplacePathsInMessage(string message)
191
+ {
192
+ return message.Replace(baseFolder, "<basefolder>").Trim();
193
+ }
194
}
195
196
[Theory]
src/wix/test/WixToolsetTest.Sdk/TestData/SimpleMsiPackage/MsiPackage/MsiPackage.wixproj
+20
-1
@@ -43,4 +43,23 @@
43
</ItemGroup>
44
45
<Import Project="$(WixTargetsPath)" />
46
-</Project>
\ No newline at end of file
46
+
47
+ <Target Name="SignCabs">
48
+ <!-- It would be cool to actually sign, but signtool.exe is not always easy to find, so we'll
49
+ mock it up instead.
50
+ <Error Text="Could not find pfx at: $(TestCertificate)" Condition=" !Exists('$(TestCertificate)') " />
51
+ <Exec Command='signtool.exe sign /v /f $(TestCertificate) /p password %(SignCabs.FullPath)' />
52
+ -->
53
+ <Message Importance="high" Text="TEST: SignCabs: @(SignCabs)" />
54
+ </Target>
55
+
56
+ <Target Name="SignMsi">
57
+ <!-- It would be cool to actually sign, but signtool.exe is not always easy to find, so we'll
58
+ mock it up instead.
59
+ <Error Text="Could not find pfx at: $(TestCertificate)" Condition=" !Exists('$(TestCertificate)') " />
60
+ <Exec Command='signtool.exe sign /v /f $(TestCertificate) /p password "%(SignMsi.FullPath)" ' />
61
+ -->
62
+ <Message Importance="high" Text="TEST: SignMsi: @(SignMsi)" />
63
+ </Target>
64
+
65
+</Project>
src/wix/test/WixToolsetTest.Sdk/TestData/SimpleMsiPackage/SimpleBundle/SimpleBundle.wixproj
+9
-1
@@ -39,4 +39,12 @@
39
</ItemGroup>
40
41
<Import Project="$(WixTargetsPath)" />
42
-</Project>
\ No newline at end of file
42
+
43
+ <Target Name="SignBundleEngine">
44
+ <Message Importance="high" Text="TEST: SignBundleEngine: @(SignBundleEngine)" />
45
+ </Target>
46
+
47
+ <Target Name="SignBundle">
48
+ <Message Importance="high" Text="TEST: SignBundle: @(SignBundle)" />
49
+ </Target>
50
+</Project>
src/wix/test/WixToolsetTest.Sdk/TestData/SimpleMsiPackage/UncompressedBundle/UncompressedBundle.wixproj
+9
-1
@@ -39,4 +39,12 @@
39
</ItemGroup>
40
41
<Import Project="$(WixTargetsPath)" />
42
-</Project>
\ No newline at end of file
42
+
43
+ <Target Name="SignBundleEngine">
44
+ <Message Importance="high" Text="TEST: SignBundleEngine: @(SignBundleEngine)" />
45
+ </Target>
46
+
47
+ <Target Name="SignBundle">
48
+ <Message Importance="high" Text="TEST: SignBundle: @(SignBundle)" />
49
+ </Target>
50
+</Project>