From 8929554278be056a73160ec5f06ab6cc6b8c4fb4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 1 Mar 2021 18:11:41 -0600 Subject: Add conversion for renaming RemotePayload, and warn about changed hash. #3992, #4183 --- src/WixToolset.Converters/WixConverter.cs | 65 +++++++++++++ .../WixToolsetTest.Converters/ConverterFixture.cs | 33 ------- .../RemotePayloadFixture.cs | 104 +++++++++++++++++++++ 3 files changed, 169 insertions(+), 33 deletions(-) create mode 100644 src/test/WixToolsetTest.Converters/RemotePayloadFixture.cs (limited to 'src') diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index 83a333f0..83053725 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -66,10 +66,12 @@ namespace WixToolset.Converters private static readonly XName LaunchElementName = WixNamespace + "Launch"; private static readonly XName LevelElementName = WixNamespace + "Level"; private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; + private static readonly XName ExePackagePayloadElementName = WixNamespace + "ExePackagePayload"; private static readonly XName ModuleElementName = WixNamespace + "Module"; private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; private static readonly XName MspPackageElementName = WixNamespace + "MspPackage"; private static readonly XName MsuPackageElementName = WixNamespace + "MsuPackage"; + private static readonly XName MsuPackagePayloadElementName = WixNamespace + "MsuPackagePayload"; private static readonly XName PackageElementName = WixNamespace + "Package"; private static readonly XName PayloadElementName = WixNamespace + "Payload"; private static readonly XName PermissionExElementName = WixNamespace + "PermissionEx"; @@ -1099,6 +1101,44 @@ namespace WixToolset.Converters private void ConvertRemotePayloadElement(XElement element) { + var xParent = element.Parent; + + if (xParent.Name == ExePackageElementName && + this.OnError(ConverterTestType.RemotePayloadRenamed, element, "The RemotePayload element has been renamed. Use the 'ExePackagePayload' instead.")) + { + element.Name = ExePackagePayloadElementName; + } + else if (xParent.Name == MsuPackageElementName && + this.OnError(ConverterTestType.RemotePayloadRenamed, element, "The RemotePayload element has been renamed. Use the 'MsuPackagePayload' instead.")) + { + element.Name = MsuPackagePayloadElementName; + } + + var xName = xParent.Attribute("Name"); + if (xName != null && + this.OnError(ConverterTestType.NameAttributeMovedToRemotePayload, xParent, "The Name attribute must be specified on the child XxxPackagePayload element when using a remote payload.")) + { + element.SetAttributeValue("Name", xName.Value); + xName.Remove(); + } + + var xDownloadUrl = xParent.Attribute("DownloadUrl"); + if (xDownloadUrl != null && + this.OnError(ConverterTestType.DownloadUrlAttributeMovedToRemotePayload, xParent, "The DownloadUrl attribute must be specified on the child XxxPackagePayload element when using a remote payload.")) + { + element.SetAttributeValue("DownloadUrl", xDownloadUrl.Value); + xDownloadUrl.Remove(); + } + + var xCompressed = xParent.Attribute("Compressed"); + if (xCompressed != null && + this.OnError(ConverterTestType.CompressedAttributeUnnecessaryForRemotePayload, xParent, "The Compressed attribute should not be specified when using a remote payload.")) + { + xCompressed.Remove(); + } + + this.OnError(ConverterTestType.BurnHashAlgorithmChanged, element, "The hash algorithm for bundles changed from SHA1 to SHA512."); + RemoveIfPresent(element.Attribute("CertificatePublicKey")); RemoveIfPresent(element.Attribute("CertificateThumbprint")); @@ -1957,6 +1997,31 @@ namespace WixToolset.Converters /// Remove unused namespaces. /// RemoveUnusedNamespaces, + + /// + /// The Remote element has been renamed. Use the "XxxPackagePayload" element instead. + /// + RemotePayloadRenamed, + + /// + /// The XxxPackage/@Name attribute must be specified on the child XxxPackagePayload element when using a remote payload. + /// + NameAttributeMovedToRemotePayload, + + /// + /// The XxxPackage/@Compressed attribute should not be specified when using a remote payload. + /// + CompressedAttributeUnnecessaryForRemotePayload, + + /// + /// The XxxPackage/@DownloadUrl attribute must be specified on the child XxxPackagePayload element when using a remote payload. + /// + DownloadUrlAttributeMovedToRemotePayload, + + /// + /// The hash algorithm used for bundles changed from SHA1 to SHA512. + /// + BurnHashAlgorithmChanged, } } } diff --git a/src/test/WixToolsetTest.Converters/ConverterFixture.cs b/src/test/WixToolsetTest.Converters/ConverterFixture.cs index 207d5c8f..4d815247 100644 --- a/src/test/WixToolsetTest.Converters/ConverterFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConverterFixture.cs @@ -330,39 +330,6 @@ namespace WixToolsetTest.Converters Assert.Equal(expected, actual); } - [Fact] - public void CanConvertRemotePayloadElement() - { - var parse = String.Join(Environment.NewLine, - "", - " ", - ""); - - var expected = String.Join(Environment.NewLine, - "", - " ", - ""); - - var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); - - var messaging = new MockMessaging(); - var converter = new WixConverter(messaging, 2, null, null); - - var errors = converter.ConvertDocument(document); - - var actual = UnformattedDocumentString(document); - - Assert.Equal(2, errors); - Assert.Equal(expected, actual); - } - [Fact] public void CanConvertSuppressSignatureValidationNo() { diff --git a/src/test/WixToolsetTest.Converters/RemotePayloadFixture.cs b/src/test/WixToolsetTest.Converters/RemotePayloadFixture.cs new file mode 100644 index 00000000..b2640e13 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/RemotePayloadFixture.cs @@ -0,0 +1,104 @@ +// 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. + +namespace WixToolsetTest.Converters +{ + using System; + using System.Xml.Linq; + using WixBuildTools.TestSupport; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class RemotePayloadFixture : BaseConverterFixture + { + [Fact] + public void CanConvertExePackageRemotePayload() + { + var parse = String.Join(Environment.NewLine, + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(6, errors); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + } + + [Fact] + public void CanConvertMsuPackageRemotePayload() + { + var parse = String.Join(Environment.NewLine, + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(5, errors); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + } + } +} -- cgit v1.2.3-55-g6feb