| 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 WixInternal.TestSupport; |
| 7 | using WixInternal.Core.TestPackage; |
| 8 | using Xunit; |
| 9 | |
| 10 | public class SigningFixture |
| 11 | { |
| 12 | [Fact] |
| 13 | public void CanInscribeMsiWithSignedCabinet() |
| 14 | { |
| 15 | var folder = TestData.Get(@"TestData\SingleFileCompressed"); |
| 16 | var signedFolder = TestData.Get(@"TestData\.Data"); |
| 17 | |
| 18 | using (var fs = new DisposableFileSystem()) |
| 19 | { |
| 20 | var baseFolder = fs.GetFolder(); |
| 21 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 22 | var outputMsi = Path.Combine(intermediateFolder, @"bin\test.msi"); |
| 23 | var signedMsi = Path.Combine(baseFolder, @"signed.msi"); |
| 24 | |
| 25 | var result = WixRunner.Execute(new[] |
| 26 | { |
| 27 | "build", |
| 28 | Path.Combine(folder, "Package.wxs"), |
| 29 | Path.Combine(folder, "PackageComponents.wxs"), |
| 30 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), |
| 31 | "-bindpath", Path.Combine(folder, "data"), |
| 32 | "-intermediateFolder", intermediateFolder, |
| 33 | "-o", outputMsi |
| 34 | }); |
| 35 | |
| 36 | result.AssertSuccess(); |
| 37 | |
| 38 | var beforeRows = Query.QueryDatabase(outputMsi, new[] { "MsiDigitalSignature", "MsiDigitalCertificate" }); |
| 39 | Assert.Empty(beforeRows); |
| 40 | |
| 41 | // Swap in a pre-signed cabinet since signing during the unit test |
| 42 | // is a challenge. The cabinet contents almost definitely don't |
| 43 | // match but that's okay for these testing purposes. |
| 44 | File.Copy(Path.Combine(signedFolder, "signed_cab1.cab"), Path.Combine(Path.GetDirectoryName(outputMsi), "example.cab"), true); |
| 45 | |
| 46 | result = WixRunner.Execute(new[] |
| 47 | { |
| 48 | "msi", |
| 49 | "inscribe", |
| 50 | outputMsi, |
| 51 | "-o", signedMsi, |
| 52 | "-intermediateFolder", intermediateFolder, |
| 53 | }); |
| 54 | |
| 55 | result.AssertSuccess(); |
| 56 | |
| 57 | var rows = Query.QueryDatabase(signedMsi, new[] { "MsiDigitalSignature", "MsiDigitalCertificate" }); |
| 58 | WixAssert.CompareLineByLine(new[] |
| 59 | { |
| 60 | "MsiDigitalCertificate:cer8xpsawK5TG4sIx4em8F.i7ocIKU\t[Binary data]", |
| 61 | "MsiDigitalSignature:Media\t1\tcer8xpsawK5TG4sIx4em8F.i7ocIKU\t" |
| 62 | }, rows); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | [Fact] |
| 67 | public void CanInscribeBundle() |
| 68 | { |
| 69 | var folder = TestData.Get(@"TestData", "SimpleBundle"); |
| 70 | var signedFolder = TestData.Get(@"TestData", ".Data"); |
| 71 | |
| 72 | using (var fs = new DisposableFileSystem()) |
| 73 | { |
| 74 | var baseFolder = fs.GetFolder(); |
| 75 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 76 | var exePath = Path.Combine(baseFolder, @"bin\test.exe"); |
| 77 | var signedExe = Path.Combine(intermediateFolder, @"signed.exe"); |
| 78 | var reattachedExe = Path.Combine(baseFolder, @"bin\final.exe"); |
| 79 | |
| 80 | var result = WixRunner.Execute(new[] |
| 81 | { |
| 82 | "build", |
| 83 | Path.Combine(folder, "Bundle.wxs"), |
| 84 | "-loc", Path.Combine(folder, "Bundle.en-us.wxl"), |
| 85 | "-bindpath", Path.Combine(folder, "data"), |
| 86 | "-bindpath", signedFolder, |
| 87 | "-intermediateFolder", intermediateFolder, |
| 88 | "-o", exePath, |
| 89 | }); |
| 90 | |
| 91 | result.AssertSuccess(); |
| 92 | |
| 93 | result = WixRunner.Execute(new[] |
| 94 | { |
| 95 | "burn", |
| 96 | "detach", |
| 97 | exePath, |
| 98 | "-engine", signedExe |
| 99 | }); |
| 100 | |
| 101 | result.AssertSuccess(); |
| 102 | |
| 103 | // Swap in a pre-signed executable since signing during the unit test |
| 104 | // is a challenge. The exe isn't an exact match but that's okay for |
| 105 | // these testing purposes. |
| 106 | File.Copy(Path.Combine(signedFolder, "signed_bundle_engine.exe"), signedExe, true); |
| 107 | |
| 108 | result = WixRunner.Execute(new[] |
| 109 | { |
| 110 | "burn", |
| 111 | "reattach", |
| 112 | exePath, |
| 113 | "-engine", signedExe, |
| 114 | "-o", reattachedExe |
| 115 | }); |
| 116 | |
| 117 | result.AssertSuccess(); |
| 118 | Assert.True(File.Exists(reattachedExe)); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | [Fact] |
| 123 | public void CanInscribe64BitBundle() |
| 124 | { |
| 125 | var folder = TestData.Get(@"TestData", "SimpleBundle"); |
| 126 | var signedFolder = TestData.Get(@"TestData", ".Data"); |
| 127 | |
| 128 | using (var fs = new DisposableFileSystem()) |
| 129 | { |
| 130 | var baseFolder = fs.GetFolder(); |
| 131 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 132 | var exePath = Path.Combine(baseFolder, @"bin\test.exe"); |
| 133 | var signedExe = Path.Combine(intermediateFolder, @"signed.exe"); |
| 134 | var reattachedExe = Path.Combine(baseFolder, @"bin\final.exe"); |
| 135 | |
| 136 | var result = WixRunner.Execute(new[] |
| 137 | { |
| 138 | "build", |
| 139 | Path.Combine(folder, "Bundle.wxs"), |
| 140 | "-platform", "x64", |
| 141 | "-loc", Path.Combine(folder, "Bundle.en-us.wxl"), |
| 142 | "-bindpath", Path.Combine(folder, "data"), |
| 143 | "-bindpath", signedFolder, |
| 144 | "-intermediateFolder", intermediateFolder, |
| 145 | "-o", exePath, |
| 146 | }); |
| 147 | |
| 148 | result.AssertSuccess(); |
| 149 | |
| 150 | result = WixRunner.Execute(new[] |
| 151 | { |
| 152 | "burn", |
| 153 | "detach", |
| 154 | exePath, |
| 155 | "-engine", signedExe |
| 156 | }); |
| 157 | |
| 158 | result.AssertSuccess(); |
| 159 | Assert.True(File.Exists(signedExe)); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | [Fact] |
| 164 | public void CanInscribeUncompressedBundle() |
| 165 | { |
| 166 | var folder = TestData.Get(@"TestData", "BundleUncompressed"); |
| 167 | var bindPath = TestData.Get(@"TestData", "SimpleBundle", "data"); |
| 168 | var signedFolder = TestData.Get(@"TestData", ".Data"); |
| 169 | |
| 170 | using (var fs = new DisposableFileSystem()) |
| 171 | { |
| 172 | var baseFolder = fs.GetFolder(); |
| 173 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 174 | var exePath = Path.Combine(baseFolder, @"bin\test.exe"); |
| 175 | var signedExe = Path.Combine(intermediateFolder, @"signed.exe"); |
| 176 | var reattachedExe = Path.Combine(baseFolder, @"bin\final.exe"); |
| 177 | |
| 178 | var result = WixRunner.Execute(new[] |
| 179 | { |
| 180 | "build", |
| 181 | Path.Combine(folder, "UncompressedBundle.wxs"), |
| 182 | "-bindpath", bindPath, |
| 183 | "-bindpath", signedFolder, |
| 184 | "-intermediateFolder", intermediateFolder, |
| 185 | "-o", exePath, |
| 186 | }); |
| 187 | |
| 188 | result.AssertSuccess(); |
| 189 | |
| 190 | result = WixRunner.Execute(new[] |
| 191 | { |
| 192 | "burn", |
| 193 | "detach", |
| 194 | exePath, |
| 195 | "-engine", signedExe |
| 196 | }); |
| 197 | |
| 198 | result.AssertSuccess(); |
| 199 | |
| 200 | // Swap in a pre-signed executable since signing during the unit test |
| 201 | // is a challenge. The exe isn't an exact match but that's okay for |
| 202 | // these testing purposes. |
| 203 | File.Copy(Path.Combine(signedFolder, "signed_bundle_engine.exe"), signedExe, true); |
| 204 | |
| 205 | result = WixRunner.Execute(new[] |
| 206 | { |
| 207 | "burn", |
| 208 | "reattach", |
| 209 | exePath, |
| 210 | "-engine", signedExe, |
| 211 | "-o", reattachedExe |
| 212 | }); |
| 213 | |
| 214 | Assert.True(File.Exists(reattachedExe)); |
| 215 | Assert.Equal(-1000, result.ExitCode); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |