| 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.Firewall |
| 4 | { |
| 5 | using System.Data; |
| 6 | using System.IO; |
| 7 | using System.Linq; |
| 8 | using System.Xml.Linq; |
| 9 | using WixInternal.Core.TestPackage; |
| 10 | using WixInternal.TestSupport; |
| 11 | using WixToolset.Firewall; |
| 12 | using Xunit; |
| 13 | |
| 14 | public class FirewallExtensionFixture |
| 15 | { |
| 16 | [Fact] |
| 17 | public void CanBuildUsingFirewall() |
| 18 | { |
| 19 | var folder = TestData.Get(@"TestData\UsingFirewall"); |
| 20 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 21 | |
| 22 | var results = build.BuildAndQuery(Build, "Wix5FirewallException", "CustomAction"); |
| 23 | WixAssert.CompareLineByLine(new[] |
| 24 | { |
| 25 | "CustomAction:Wix5ExecFirewallExceptionsInstall_X86\t3073\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 26 | "CustomAction:Wix5ExecFirewallExceptionsUninstall_X86\t3073\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 27 | "CustomAction:Wix5RollbackFirewallExceptionsInstall_X86\t3329\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 28 | "CustomAction:Wix5RollbackFirewallExceptionsUninstall_X86\t3329\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 29 | "CustomAction:Wix5SchedFirewallExceptionsInstall_X86\t1\tWix5FWCA_X86\tSchedFirewallExceptionsInstall\t", |
| 30 | "CustomAction:Wix5SchedFirewallExceptionsUninstall_X86\t1\tWix5FWCA_X86\tSchedFirewallExceptionsUninstall\t", |
| 31 | "Wix5FirewallException:ExampleFirewall\tExampleApp\t*\t42\t6\t[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]\t2\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tAn app-based firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 32 | "Wix5FirewallException:fex.BGtyMRGAhxb2hG.49JvWYz7fM0\tLocalScopeExample2\t*\t\t-2147483648\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with local scope property\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t[LOCALSCOPE_PROP]\t\t\t\t\t\t\t\t-2147483648", |
| 33 | "Wix5FirewallException:fex0HTxATWjpC2PCoY6DB7f2D1WaKU\tLocalScopeExample1\t*\t\t-2147483648\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple rule with local scope\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\tLocalSubnet\t\t\t\t\t\t\t\t-2147483648", |
| 34 | "Wix5FirewallException:fex4FeP470wYcFpw.g7fbIKiLnZPzg\tExampleDNSScope\tdns\t356\t17\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDNS scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 35 | "Wix5FirewallException:fex4zTcT0Iwu3dUtHIHXD5qfymvpcM\tdefertouser\t\t\t-2147483648\tfw.exe\t8\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDefer to user edge traversal\t1\t-2147483648\t3\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 36 | "Wix5FirewallException:fex8vMfBplrod4daEz3PqDTeX6olGE\tExampleDefaultGatewayScope\tDefaultGateway\t4432\t6\t\t0\t2\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tdefaultGateway scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 37 | "Wix5FirewallException:fexAMmHzFDyQmubTOnKS1Cn0Y3q_Ug\tINetFwRule3 properties\t*\t\t-2147483648\t\t16\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tINetFwRule3 passed via properties\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t[PROP1]\t[PROP2]\t[PROP3]\t[PROP4]\t[PROP5]\t[PROP6]", |
| 38 | "Wix5FirewallException:fexArlOkFR7CAwVZ2wk8yNdiREydu0\tRemotePortExample2\t\t\t6\tfw.exe\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with remote port property\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t[REMOTEPORT_PROP]\t\t\t\t\t\t\t-2147483648", |
| 39 | "Wix5FirewallException:fexaUTe2tRRcSYrPUTn44DAZhE.40Q\tExamplePort\tLocalSubnet\t42\t6\t\t4\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception\t2\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 40 | "Wix5FirewallException:fexD6w20c5HfNi4l1vHFj_eet4cC8I\tExampleWINSScope\twins\t6573\t6\t\t0\t1\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tWINS scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 41 | "Wix5FirewallException:fexeD3yox6fMflfRy7sDwSN2CMCS2s\tExampleService\t\t12000\t6\t%windir%\\system32\\svchost.exe\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based service exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\tDHCP,WINS\t\tftpsrv\t\t\t\t\t\t-2147483648", |
| 42 | "Wix5FirewallException:fexeok6aI2_AlclZggec4d8PBLFXLw\tinterface property\t\t54671\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tInterfaces with property\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t[INTERFACE_PROPERTY]\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 43 | "Wix5FirewallException:fexEPvcf4iexD1mVQdvxm7tD02nZEc\tICMPExample1\t\t\t2\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple ICMP rule\t1\t-2147483648\t-2147483648\t-2147483648\t\t4:*,9:*,12:*\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 44 | "Wix5FirewallException:fexfzjTQsWwZkHQpObtl0XaUosfcRk\tGroupingExample1\t\t\t-2147483648\tfw.exe\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple rule with grouping\t1\t-2147483648\t-2147483648\t-2147483648\t@yourresources.dll,-1005\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 45 | "Wix5FirewallException:fexHx2xbwZYzAi0oYp4YGWevJQs5eM\tRemotePortExample1\t*\t\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple rule with remote port\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t34560\t\t\t\t\t\t\t-2147483648", |
| 46 | "Wix5FirewallException:fexpWUzK53RVnaluW36gSmphPRY8VY\tExampleDHCPScope\tdhcp\t\t211\ttest.exe\t0\t4\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDHCP scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 47 | "Wix5FirewallException:fexuanTga5xaaFzr9JsAnUmpCNediw\tICMPExample2\t\t\t2\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with ICMP property\t1\t-2147483648\t-2147483648\t-2147483648\t\t[ICMP_PROP]\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 48 | "Wix5FirewallException:fexv60s7u2Dmd1imH5vEFYKPgEWhG4\tinterface nested\t127.0.0.1\t54671\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tInterfaces with nested elements\t1\t-2147483648\t-2147483648\t-2147483648\t\t\tWi-Fi|Local Area Connection\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 49 | "Wix5FirewallException:fexVr6uHcOCak5MHuTLwujjh_oKtbI\tGroupingExample2\t\t8732\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with grouping property\t1\t-2147483648\t-2147483648\t-2147483648\t[GROUPING_PROP]\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 50 | "Wix5FirewallException:fexwjf4OTFVE9SNiC4goVxBA6ENJBE\tINetFwRule3 values\t*\t\t-2147483648\t\t16\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple INetFwRule3 values\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\tS-1-15-2-1239072475-3687740317-1842961305-3395936705-4023953123-1525404051-2779347315\tO:LSD:(A;;CC;;;S-1-5-84-0-0-0-0-0)\tS-1-5-21-1898747406-2352535518-1247798438-1914\t127.0.0.1\tO:LSD:(A;;CC;;;S-1-5-84-0-0-0-0-0)\t3", |
| 51 | "Wix5FirewallException:ServiceInstall.nested\tExampleNestedService\tLocalSubnet\t3546-7890\t6\t\t1\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception for a Windows service\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\tLan,Wireless\t\t\tsvc1\t\t\t\t\t\t-2147483648", |
| 52 | }, results); |
| 53 | } |
| 54 | |
| 55 | [Fact] |
| 56 | public void CanBuildUsingFirewallARM64() |
| 57 | { |
| 58 | var folder = TestData.Get(@"TestData\UsingFirewall"); |
| 59 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 60 | |
| 61 | var results = build.BuildAndQuery(BuildARM64, "Wix5FirewallException", "CustomAction"); |
| 62 | WixAssert.CompareLineByLine(new[] |
| 63 | { |
| 64 | "CustomAction:Wix5ExecFirewallExceptionsInstall_A64\t3073\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 65 | "CustomAction:Wix5ExecFirewallExceptionsUninstall_A64\t3073\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 66 | "CustomAction:Wix5RollbackFirewallExceptionsInstall_A64\t3329\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 67 | "CustomAction:Wix5RollbackFirewallExceptionsUninstall_A64\t3329\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 68 | "CustomAction:Wix5SchedFirewallExceptionsInstall_A64\t1\tWix5FWCA_A64\tSchedFirewallExceptionsInstall\t", |
| 69 | "CustomAction:Wix5SchedFirewallExceptionsUninstall_A64\t1\tWix5FWCA_A64\tSchedFirewallExceptionsUninstall\t", |
| 70 | "Wix5FirewallException:ExampleFirewall\tExampleApp\t*\t42\t6\t[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]\t2\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tAn app-based firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 71 | "Wix5FirewallException:fex.BGtyMRGAhxb2hG.49JvWYz7fM0\tLocalScopeExample2\t*\t\t-2147483648\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with local scope property\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t[LOCALSCOPE_PROP]\t\t\t\t\t\t\t\t-2147483648", |
| 72 | "Wix5FirewallException:fex0HTxATWjpC2PCoY6DB7f2D1WaKU\tLocalScopeExample1\t*\t\t-2147483648\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple rule with local scope\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\tLocalSubnet\t\t\t\t\t\t\t\t-2147483648", |
| 73 | "Wix5FirewallException:fex4FeP470wYcFpw.g7fbIKiLnZPzg\tExampleDNSScope\tdns\t356\t17\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDNS scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 74 | "Wix5FirewallException:fex4zTcT0Iwu3dUtHIHXD5qfymvpcM\tdefertouser\t\t\t-2147483648\tfw.exe\t8\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDefer to user edge traversal\t1\t-2147483648\t3\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 75 | "Wix5FirewallException:fex8vMfBplrod4daEz3PqDTeX6olGE\tExampleDefaultGatewayScope\tDefaultGateway\t4432\t6\t\t0\t2\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tdefaultGateway scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 76 | "Wix5FirewallException:fexAMmHzFDyQmubTOnKS1Cn0Y3q_Ug\tINetFwRule3 properties\t*\t\t-2147483648\t\t16\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tINetFwRule3 passed via properties\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t[PROP1]\t[PROP2]\t[PROP3]\t[PROP4]\t[PROP5]\t[PROP6]", |
| 77 | "Wix5FirewallException:fexArlOkFR7CAwVZ2wk8yNdiREydu0\tRemotePortExample2\t\t\t6\tfw.exe\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with remote port property\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t[REMOTEPORT_PROP]\t\t\t\t\t\t\t-2147483648", |
| 78 | "Wix5FirewallException:fexaUTe2tRRcSYrPUTn44DAZhE.40Q\tExamplePort\tLocalSubnet\t42\t6\t\t4\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception\t2\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 79 | "Wix5FirewallException:fexD6w20c5HfNi4l1vHFj_eet4cC8I\tExampleWINSScope\twins\t6573\t6\t\t0\t1\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tWINS scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 80 | "Wix5FirewallException:fexeD3yox6fMflfRy7sDwSN2CMCS2s\tExampleService\t\t12000\t6\t%windir%\\system32\\svchost.exe\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based service exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\tDHCP,WINS\t\tftpsrv\t\t\t\t\t\t-2147483648", |
| 81 | "Wix5FirewallException:fexeok6aI2_AlclZggec4d8PBLFXLw\tinterface property\t\t54671\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tInterfaces with property\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t[INTERFACE_PROPERTY]\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 82 | "Wix5FirewallException:fexEPvcf4iexD1mVQdvxm7tD02nZEc\tICMPExample1\t\t\t2\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple ICMP rule\t1\t-2147483648\t-2147483648\t-2147483648\t\t4:*,9:*,12:*\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 83 | "Wix5FirewallException:fexfzjTQsWwZkHQpObtl0XaUosfcRk\tGroupingExample1\t\t\t-2147483648\tfw.exe\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple rule with grouping\t1\t-2147483648\t-2147483648\t-2147483648\t@yourresources.dll,-1005\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 84 | "Wix5FirewallException:fexHx2xbwZYzAi0oYp4YGWevJQs5eM\tRemotePortExample1\t*\t\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple rule with remote port\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t34560\t\t\t\t\t\t\t-2147483648", |
| 85 | "Wix5FirewallException:fexpWUzK53RVnaluW36gSmphPRY8VY\tExampleDHCPScope\tdhcp\t\t211\ttest.exe\t0\t4\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDHCP scope firewall exception\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 86 | "Wix5FirewallException:fexuanTga5xaaFzr9JsAnUmpCNediw\tICMPExample2\t\t\t2\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with ICMP property\t1\t-2147483648\t-2147483648\t-2147483648\t\t[ICMP_PROP]\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 87 | "Wix5FirewallException:fexv60s7u2Dmd1imH5vEFYKPgEWhG4\tinterface nested\t127.0.0.1\t54671\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tInterfaces with nested elements\t1\t-2147483648\t-2147483648\t-2147483648\t\t\tWi-Fi|Local Area Connection\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 88 | "Wix5FirewallException:fexVr6uHcOCak5MHuTLwujjh_oKtbI\tGroupingExample2\t\t8732\t6\t\t0\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tRule with grouping property\t1\t-2147483648\t-2147483648\t-2147483648\t[GROUPING_PROP]\t\t\t\t\t\t\t\t\t\t\t\t-2147483648", |
| 89 | "Wix5FirewallException:fexwjf4OTFVE9SNiC4goVxBA6ENJBE\tINetFwRule3 values\t*\t\t-2147483648\t\t16\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tSimple INetFwRule3 values\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\t\t\t\t\tS-1-15-2-1239072475-3687740317-1842961305-3395936705-4023953123-1525404051-2779347315\tO:LSD:(A;;CC;;;S-1-5-84-0-0-0-0-0)\tS-1-5-21-1898747406-2352535518-1247798438-1914\t127.0.0.1\tO:LSD:(A;;CC;;;S-1-5-84-0-0-0-0-0)\t3", |
| 90 | "Wix5FirewallException:ServiceInstall.nested\tExampleNestedService\tLocalSubnet\t3546-7890\t6\t\t1\t-2147483648\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception for a Windows service\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t\tLan,Wireless\t\t\tsvc1\t\t\t\t\t\t-2147483648", |
| 91 | }, results); |
| 92 | } |
| 93 | |
| 94 | [Fact] |
| 95 | public void CanBuildWithProperties() |
| 96 | { |
| 97 | var folder = TestData.Get(@"TestData\UsingProperties"); |
| 98 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 99 | |
| 100 | var results = build.BuildAndQuery(Build, "Wix5FirewallException", "CustomAction"); |
| 101 | WixAssert.CompareLineByLine(new[] |
| 102 | { |
| 103 | "CustomAction:Wix5ExecFirewallExceptionsInstall_X86\t3073\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 104 | "CustomAction:Wix5ExecFirewallExceptionsUninstall_X86\t3073\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 105 | "CustomAction:Wix5RollbackFirewallExceptionsInstall_X86\t3329\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 106 | "CustomAction:Wix5RollbackFirewallExceptionsUninstall_X86\t3329\tWix5FWCA_X86\tExecFirewallExceptions\t", |
| 107 | "CustomAction:Wix5SchedFirewallExceptionsInstall_X86\t1\tWix5FWCA_X86\tSchedFirewallExceptionsInstall\t", |
| 108 | "CustomAction:Wix5SchedFirewallExceptionsUninstall_X86\t1\tWix5FWCA_X86\tSchedFirewallExceptionsUninstall\t", |
| 109 | "Wix5FirewallException:fexRrE4bS.DwUJQMvzX0ALEsx7jrZs\tSingle Nested properties\t[REMOTEADDRESS]\t\t-2147483648\t\t0\t-2147483648\tFirewallComponent\t\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t[INTERFACE]\t[INTERFACETYPE]\t[LOCALADDRESS]\t\t\t\t\t\t\t\t-2147483648", |
| 110 | "Wix5FirewallException:fexvEy1GfdOjHlKcvsguyqK6mvYKyk\t[NAME]\t[REMOTESCOPE]\t[LOCALPORT]\t[PROTOCOL]\t[PROGRAM]\t16\t[PROFILE]\tFirewallComponent\t[DESCRIPTION]\t1\t[ACTION]\t[EDGETRAVERSAL]\t[ENABLED]\t[GROUPING]\t[ICMPTYPES]\t[INTERFACE]\t[INTERFACETYPE]\t[LOCALSCOPE]\t[REMOTEPORT]\t[SERVICE]\t[PACKAGEID]\t[LOCALUSERS]\t[LOCALOWNER]\t[REMOTEMACHINES]\t[REMOTEUSERS]\t[SECUREFLAGS]", |
| 111 | "Wix5FirewallException:fexWywW3VGiEuG23FOv1YM6h7R6F5Q\tMultiple Nested properties\t[REMOTEADDRESS1],[REMOTEADDRESS2]\t\t-2147483648\t\t0\t-2147483648\tFirewallComponent\t\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t[INTERFACE1]|[INTERFACE2]\t[INTERFACETYPE1],[INTERFACETYPE2]\t[LOCALADDRESS1],[LOCALADDRESS2]\t\t\t\t\t\t\t\t-2147483648", |
| 112 | }, results); |
| 113 | } |
| 114 | |
| 115 | [Fact] |
| 116 | public void CanBuildWithPropertiesUsingFirewallARM64() |
| 117 | { |
| 118 | var folder = TestData.Get(@"TestData\UsingProperties"); |
| 119 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 120 | |
| 121 | var results = build.BuildAndQuery(BuildARM64, "Wix5FirewallException", "CustomAction"); |
| 122 | WixAssert.CompareLineByLine(new[] |
| 123 | { |
| 124 | "CustomAction:Wix5ExecFirewallExceptionsInstall_A64\t3073\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 125 | "CustomAction:Wix5ExecFirewallExceptionsUninstall_A64\t3073\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 126 | "CustomAction:Wix5RollbackFirewallExceptionsInstall_A64\t3329\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 127 | "CustomAction:Wix5RollbackFirewallExceptionsUninstall_A64\t3329\tWix5FWCA_A64\tExecFirewallExceptions\t", |
| 128 | "CustomAction:Wix5SchedFirewallExceptionsInstall_A64\t1\tWix5FWCA_A64\tSchedFirewallExceptionsInstall\t", |
| 129 | "CustomAction:Wix5SchedFirewallExceptionsUninstall_A64\t1\tWix5FWCA_A64\tSchedFirewallExceptionsUninstall\t", |
| 130 | "Wix5FirewallException:fexRrE4bS.DwUJQMvzX0ALEsx7jrZs\tSingle Nested properties\t[REMOTEADDRESS]\t\t-2147483648\t\t0\t-2147483648\tFirewallComponent\t\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t[INTERFACE]\t[INTERFACETYPE]\t[LOCALADDRESS]\t\t\t\t\t\t\t\t-2147483648", |
| 131 | "Wix5FirewallException:fexvEy1GfdOjHlKcvsguyqK6mvYKyk\t[NAME]\t[REMOTESCOPE]\t[LOCALPORT]\t[PROTOCOL]\t[PROGRAM]\t16\t[PROFILE]\tFirewallComponent\t[DESCRIPTION]\t1\t[ACTION]\t[EDGETRAVERSAL]\t[ENABLED]\t[GROUPING]\t[ICMPTYPES]\t[INTERFACE]\t[INTERFACETYPE]\t[LOCALSCOPE]\t[REMOTEPORT]\t[SERVICE]\t[PACKAGEID]\t[LOCALUSERS]\t[LOCALOWNER]\t[REMOTEMACHINES]\t[REMOTEUSERS]\t[SECUREFLAGS]", |
| 132 | "Wix5FirewallException:fexWywW3VGiEuG23FOv1YM6h7R6F5Q\tMultiple Nested properties\t[REMOTEADDRESS1],[REMOTEADDRESS2]\t\t-2147483648\t\t0\t-2147483648\tFirewallComponent\t\t1\t-2147483648\t-2147483648\t-2147483648\t\t\t[INTERFACE1]|[INTERFACE2]\t[INTERFACETYPE1],[INTERFACETYPE2]\t[LOCALADDRESS1],[LOCALADDRESS2]\t\t\t\t\t\t\t\t-2147483648", |
| 133 | }, results); |
| 134 | } |
| 135 | |
| 136 | [Fact] |
| 137 | public void CanRoundtripFirewallExceptions() |
| 138 | { |
| 139 | var folder = TestData.Get(@"TestData", "UsingFirewall"); |
| 140 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 141 | var output = Path.Combine(folder, "FirewallExceptionDecompile.xml"); |
| 142 | |
| 143 | build.BuildAndDecompileAndBuild(Build, Decompile, output); |
| 144 | |
| 145 | var doc = XDocument.Load(output); |
| 146 | var actual = doc.Descendants() |
| 147 | .Where(e => e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/firewall") |
| 148 | .Select(fe => new { Name = fe.Name.LocalName, Attributes = fe.Attributes().Select(a => $"{a.Name.LocalName}={a.Value}").ToArray() }) |
| 149 | .ToArray(); |
| 150 | |
| 151 | WixAssert.CompareLineByLine(new[] |
| 152 | { |
| 153 | "FirewallException", |
| 154 | "FirewallException", |
| 155 | "FirewallException", |
| 156 | "FirewallException", |
| 157 | "FirewallException", |
| 158 | "FirewallException", |
| 159 | "FirewallException", |
| 160 | "FirewallException", |
| 161 | "LocalAddress", |
| 162 | "LocalAddress", |
| 163 | "FirewallException", |
| 164 | "RemoteAddress", |
| 165 | "Interface", |
| 166 | "Interface", |
| 167 | "FirewallException", |
| 168 | "FirewallException", |
| 169 | "InterfaceType", |
| 170 | "InterfaceType", |
| 171 | "FirewallException", |
| 172 | "FirewallException", |
| 173 | "FirewallException", |
| 174 | "FirewallException", |
| 175 | "FirewallException", |
| 176 | "FirewallException", |
| 177 | "FirewallException", |
| 178 | "FirewallException", |
| 179 | "FirewallException", |
| 180 | "FirewallException", |
| 181 | }, actual.Select(a => a.Name).ToArray()); |
| 182 | } |
| 183 | |
| 184 | [Fact] |
| 185 | public void CanRoundtripFirewallExceptionsWithProperties() |
| 186 | { |
| 187 | var folder = TestData.Get(@"TestData", "UsingProperties"); |
| 188 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 189 | var output = Path.Combine(folder, "FirewallPropertiesDecompile.xml"); |
| 190 | |
| 191 | build.BuildAndDecompileAndBuild(Build, Decompile, output); |
| 192 | |
| 193 | var doc = XDocument.Load(output); |
| 194 | var actual = doc.Descendants() |
| 195 | .Where(e => e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/firewall") |
| 196 | .Select(fe => new { Name = fe.Name.LocalName, Attributes = fe.Attributes().Select(a => $"{a.Name.LocalName}={a.Value}").ToArray() }) |
| 197 | .ToArray(); |
| 198 | |
| 199 | WixAssert.CompareLineByLine(new[] |
| 200 | { |
| 201 | "FirewallException", |
| 202 | "FirewallException", |
| 203 | "FirewallException", |
| 204 | "RemoteAddress", |
| 205 | "RemoteAddress", |
| 206 | "Interface", |
| 207 | "Interface", |
| 208 | "InterfaceType", |
| 209 | "InterfaceType", |
| 210 | "LocalAddress", |
| 211 | "LocalAddress", |
| 212 | }, actual.Select(a => a.Name).ToArray()); |
| 213 | } |
| 214 | |
| 215 | [Fact] |
| 216 | public void RoundtripAttributesAreCorrectForApp() |
| 217 | { |
| 218 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ExampleApp"); |
| 219 | WixAssert.CompareLineByLine(new[] |
| 220 | { |
| 221 | "Id=ExampleFirewall", |
| 222 | "Name=ExampleApp", |
| 223 | "Scope=any", |
| 224 | "Port=42", |
| 225 | "Protocol=tcp", |
| 226 | "Program=[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]", |
| 227 | "OnUpdate=doNothing", |
| 228 | "Description=An app-based firewall exception", |
| 229 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 230 | }, actual.Attributes); |
| 231 | } |
| 232 | |
| 233 | [Fact] |
| 234 | public void RoundtripAttributesAreCorrectForPort() |
| 235 | { |
| 236 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ExamplePort"); |
| 237 | WixAssert.CompareLineByLine(new[] |
| 238 | { |
| 239 | "Id=fexaUTe2tRRcSYrPUTn44DAZhE.40Q", |
| 240 | "Name=ExamplePort", |
| 241 | "Scope=localSubnet", |
| 242 | "Port=42", |
| 243 | "Protocol=tcp", |
| 244 | "OnUpdate=enableOnly", |
| 245 | "Description=A port-based firewall exception", |
| 246 | "Outbound=yes", |
| 247 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 248 | }, actual.Attributes); |
| 249 | } |
| 250 | |
| 251 | [Fact] |
| 252 | public void RoundtripAttributesAreCorrectForDNSScope() |
| 253 | { |
| 254 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ExampleDNSScope"); |
| 255 | WixAssert.CompareLineByLine(new[] |
| 256 | { |
| 257 | "Id=fex4FeP470wYcFpw.g7fbIKiLnZPzg", |
| 258 | "Name=ExampleDNSScope", |
| 259 | "Scope=DNS", |
| 260 | "Port=356", |
| 261 | "Protocol=udp", |
| 262 | "Description=DNS scope firewall exception", |
| 263 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 264 | }, actual.Attributes); |
| 265 | } |
| 266 | |
| 267 | [Fact] |
| 268 | public void RoundtripAttributesAreCorrectForDHCPScope() |
| 269 | { |
| 270 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ExampleDHCPScope"); |
| 271 | WixAssert.CompareLineByLine(new[] |
| 272 | { |
| 273 | "Id=fexpWUzK53RVnaluW36gSmphPRY8VY", |
| 274 | "Name=ExampleDHCPScope", |
| 275 | "Scope=DHCP", |
| 276 | "Protocol=211", |
| 277 | "Program=test.exe", |
| 278 | "Profile=public", |
| 279 | "Description=DHCP scope firewall exception", |
| 280 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall" |
| 281 | }, actual.Attributes); |
| 282 | } |
| 283 | |
| 284 | [Fact] |
| 285 | public void RoundtripAttributesAreCorrectForWINSScope() |
| 286 | { |
| 287 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ExampleWINSScope"); |
| 288 | WixAssert.CompareLineByLine(new[] |
| 289 | { |
| 290 | "Id=fexD6w20c5HfNi4l1vHFj_eet4cC8I", |
| 291 | "Name=ExampleWINSScope", |
| 292 | "Scope=WINS", |
| 293 | "Port=6573", |
| 294 | "Protocol=tcp", |
| 295 | "Profile=domain", |
| 296 | "Description=WINS scope firewall exception", |
| 297 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 298 | }, actual.Attributes); |
| 299 | } |
| 300 | |
| 301 | [Fact] |
| 302 | public void RoundtripAttributesAreCorrectForDefaultGatewayScope() |
| 303 | { |
| 304 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ExampleDefaultGatewayScope"); |
| 305 | WixAssert.CompareLineByLine(new[] |
| 306 | { |
| 307 | "Id=fex8vMfBplrod4daEz3PqDTeX6olGE", |
| 308 | "Name=ExampleDefaultGatewayScope", |
| 309 | "Scope=defaultGateway", |
| 310 | "Port=4432", |
| 311 | "Protocol=tcp", |
| 312 | "Profile=private", |
| 313 | "Description=defaultGateway scope firewall exception", |
| 314 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 315 | }, actual.Attributes); |
| 316 | } |
| 317 | |
| 318 | [Fact] |
| 319 | public void RoundtripAttributesAreCorrectForINetFwRule3Values() |
| 320 | { |
| 321 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "INetFwRule3 values"); |
| 322 | WixAssert.CompareLineByLine(new[] |
| 323 | { |
| 324 | "Id=fexwjf4OTFVE9SNiC4goVxBA6ENJBE", |
| 325 | "Name=INetFwRule3 values", |
| 326 | "Scope=any", |
| 327 | "Description=Simple INetFwRule3 values", |
| 328 | "LocalAppPackageId=S-1-15-2-1239072475-3687740317-1842961305-3395936705-4023953123-1525404051-2779347315", |
| 329 | "LocalUserAuthorizedList=O:LSD:(A;;CC;;;S-1-5-84-0-0-0-0-0)", |
| 330 | "LocalUserOwner=S-1-5-21-1898747406-2352535518-1247798438-1914", |
| 331 | "RemoteMachineAuthorizedList=127.0.0.1", |
| 332 | "RemoteUserAuthorizedList=O:LSD:(A;;CC;;;S-1-5-84-0-0-0-0-0)", |
| 333 | "IPSecSecureFlags=negotiateEncryption", |
| 334 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 335 | }, actual.Attributes); |
| 336 | } |
| 337 | |
| 338 | [Fact] |
| 339 | public void RoundtripAttributesAreCorrectForINetFwRule3Properties() |
| 340 | { |
| 341 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "INetFwRule3 properties"); |
| 342 | WixAssert.CompareLineByLine(new[] |
| 343 | { |
| 344 | "Id=fexAMmHzFDyQmubTOnKS1Cn0Y3q_Ug", |
| 345 | "Name=INetFwRule3 properties", |
| 346 | "Scope=any", |
| 347 | "Description=INetFwRule3 passed via properties", |
| 348 | "LocalAppPackageId=[PROP1]", |
| 349 | "LocalUserAuthorizedList=[PROP2]", |
| 350 | "LocalUserOwner=[PROP3]", |
| 351 | "RemoteMachineAuthorizedList=[PROP4]", |
| 352 | "RemoteUserAuthorizedList=[PROP5]", |
| 353 | "IPSecSecureFlags=[PROP6]", |
| 354 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 355 | }, actual.Attributes); |
| 356 | } |
| 357 | |
| 358 | [Fact] |
| 359 | public void RoundtripAttributesAreCorrectForGroupingValue() |
| 360 | { |
| 361 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "GroupingExample1"); |
| 362 | WixAssert.CompareLineByLine(new[] |
| 363 | { |
| 364 | "Id=fexfzjTQsWwZkHQpObtl0XaUosfcRk", |
| 365 | "Name=GroupingExample1", |
| 366 | "Program=fw.exe", |
| 367 | "Description=Simple rule with grouping", |
| 368 | "Grouping=@yourresources.dll,-1005", |
| 369 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 370 | }, actual.Attributes); |
| 371 | } |
| 372 | |
| 373 | [Fact] |
| 374 | public void RoundtripAttributesAreCorrectForGroupingProperty() |
| 375 | { |
| 376 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "GroupingExample2"); |
| 377 | WixAssert.CompareLineByLine(new[] |
| 378 | { |
| 379 | "Id=fexVr6uHcOCak5MHuTLwujjh_oKtbI", |
| 380 | "Name=GroupingExample2", |
| 381 | "Port=8732", |
| 382 | "Protocol=tcp", |
| 383 | "Description=Rule with grouping property", |
| 384 | "Grouping=[GROUPING_PROP]", |
| 385 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 386 | }, actual.Attributes); |
| 387 | } |
| 388 | |
| 389 | [Fact] |
| 390 | public void RoundtripAttributesAreCorrectForIcmpValue() |
| 391 | { |
| 392 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ICMPExample1"); |
| 393 | WixAssert.CompareLineByLine(new[] |
| 394 | { |
| 395 | "Id=fexEPvcf4iexD1mVQdvxm7tD02nZEc", |
| 396 | "Name=ICMPExample1", |
| 397 | "Protocol=2", |
| 398 | "Description=Simple ICMP rule", |
| 399 | "IcmpTypesAndCodes=4:*,9:*,12:*", |
| 400 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 401 | }, actual.Attributes); |
| 402 | } |
| 403 | |
| 404 | [Fact] |
| 405 | public void RoundtripAttributesAreCorrectForIcmpProperty() |
| 406 | { |
| 407 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "ICMPExample2"); |
| 408 | WixAssert.CompareLineByLine(new[] |
| 409 | { |
| 410 | "Id=fexuanTga5xaaFzr9JsAnUmpCNediw", |
| 411 | "Name=ICMPExample2", |
| 412 | "Protocol=2", |
| 413 | "Description=Rule with ICMP property", |
| 414 | "IcmpTypesAndCodes=[ICMP_PROP]", |
| 415 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 416 | }, actual.Attributes); |
| 417 | } |
| 418 | |
| 419 | [Fact] |
| 420 | public void RoundtripAttributesAreCorrectForLocalScopeValue() |
| 421 | { |
| 422 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "LocalScopeExample1"); |
| 423 | WixAssert.CompareLineByLine(new[] |
| 424 | { |
| 425 | "Id=fex0HTxATWjpC2PCoY6DB7f2D1WaKU", |
| 426 | "Name=LocalScopeExample1", |
| 427 | "Scope=any", |
| 428 | "Description=Simple rule with local scope", |
| 429 | "LocalScope=localSubnet", |
| 430 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 431 | }, actual.Attributes); |
| 432 | } |
| 433 | |
| 434 | [Fact] |
| 435 | public void RoundtripAttributesAreCorrectForLocalScopeProperty() |
| 436 | { |
| 437 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "LocalScopeExample2"); |
| 438 | WixAssert.CompareLineByLine(new[] |
| 439 | { |
| 440 | "Id=fex.BGtyMRGAhxb2hG.49JvWYz7fM0", |
| 441 | "Name=LocalScopeExample2", |
| 442 | "Scope=any", |
| 443 | "Description=Rule with local scope property", |
| 444 | "LocalScope=[LOCALSCOPE_PROP]", |
| 445 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 446 | }, actual.Attributes); |
| 447 | } |
| 448 | |
| 449 | [Fact] |
| 450 | public void RoundtripAttributesAreCorrectForRemotePorts() |
| 451 | { |
| 452 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "RemotePortExample1"); |
| 453 | WixAssert.CompareLineByLine(new[] |
| 454 | { |
| 455 | "Id=fexHx2xbwZYzAi0oYp4YGWevJQs5eM", |
| 456 | "Name=RemotePortExample1", |
| 457 | "Scope=any", |
| 458 | "Protocol=tcp", |
| 459 | "Description=Simple rule with remote port", |
| 460 | "RemotePort=34560", |
| 461 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 462 | }, actual.Attributes); |
| 463 | } |
| 464 | |
| 465 | [Fact] |
| 466 | public void RoundtripAttributesAreCorrectForRemotePortsProperty() |
| 467 | { |
| 468 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "RemotePortExample2"); |
| 469 | WixAssert.CompareLineByLine(new[] |
| 470 | { |
| 471 | "Id=fexArlOkFR7CAwVZ2wk8yNdiREydu0", |
| 472 | "Name=RemotePortExample2", |
| 473 | "Protocol=tcp", |
| 474 | "Program=fw.exe", |
| 475 | "Description=Rule with remote port property", |
| 476 | "RemotePort=[REMOTEPORT_PROP]", |
| 477 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall", |
| 478 | }, actual.Attributes); |
| 479 | } |
| 480 | |
| 481 | [Fact] |
| 482 | public void RoundtripAttributesAreCorrectWhenPropertiesAreUsed() |
| 483 | { |
| 484 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "[NAME]", "UsingProperties"); |
| 485 | WixAssert.CompareLineByLine(new[] |
| 486 | { |
| 487 | "Id=fexvEy1GfdOjHlKcvsguyqK6mvYKyk", |
| 488 | "Name=[NAME]", |
| 489 | "Scope=[REMOTESCOPE]", |
| 490 | "Port=[LOCALPORT]", |
| 491 | "Protocol=[PROTOCOL]", |
| 492 | "Program=[PROGRAM]", |
| 493 | "Profile=[PROFILE]", |
| 494 | "Description=[DESCRIPTION]", |
| 495 | "Action=[ACTION]", |
| 496 | "EdgeTraversal=[EDGETRAVERSAL]", |
| 497 | "Enabled=[ENABLED]", |
| 498 | "Grouping=[GROUPING]", |
| 499 | "IcmpTypesAndCodes=[ICMPTYPES]", |
| 500 | "Interface=[INTERFACE]", |
| 501 | "InterfaceType=[INTERFACETYPE]", |
| 502 | "LocalScope=[LOCALSCOPE]", |
| 503 | "RemotePort=[REMOTEPORT]", |
| 504 | "Service=[SERVICE]", |
| 505 | "LocalAppPackageId=[PACKAGEID]", |
| 506 | "LocalUserAuthorizedList=[LOCALUSERS]", |
| 507 | "LocalUserOwner=[LOCALOWNER]", |
| 508 | "RemoteMachineAuthorizedList=[REMOTEMACHINES]", |
| 509 | "RemoteUserAuthorizedList=[REMOTEUSERS]", |
| 510 | "IPSecSecureFlags=[SECUREFLAGS]", |
| 511 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall" |
| 512 | }, actual.Attributes); |
| 513 | |
| 514 | var folder = TestData.Get(@"TestData", "UsingProperties"); |
| 515 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 516 | var output = Path.Combine(folder, $"FirewallNothingNested.xml"); |
| 517 | |
| 518 | build.BuildAndDecompileAndBuild(Build, Decompile, output); |
| 519 | |
| 520 | var doc = XDocument.Load(output); |
| 521 | var related = doc.Descendants() |
| 522 | .Where(e => |
| 523 | { |
| 524 | return e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/firewall" && |
| 525 | e.Parent.Attributes().Any(a => a.Name.LocalName == "Name" && a.Value == "[NAME]"); |
| 526 | }); |
| 527 | |
| 528 | var nested = related.Select(e => e.Attributes().Single(a => a.Name.LocalName == "Name").Value); |
| 529 | Assert.False(nested.Any()); |
| 530 | } |
| 531 | |
| 532 | [Fact] |
| 533 | public void RoundtripAttributesAreCorrectWhenNestedPropertiesAreUsed() |
| 534 | { |
| 535 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "Single Nested properties", "UsingProperties"); |
| 536 | WixAssert.CompareLineByLine(new[] |
| 537 | { |
| 538 | "Id=fexRrE4bS.DwUJQMvzX0ALEsx7jrZs", |
| 539 | "Name=Single Nested properties", |
| 540 | "Scope=[REMOTEADDRESS]", |
| 541 | "Interface=[INTERFACE]", |
| 542 | "InterfaceType=[INTERFACETYPE]", |
| 543 | "LocalScope=[LOCALADDRESS]", |
| 544 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall" |
| 545 | }, actual.Attributes); |
| 546 | |
| 547 | var folder = TestData.Get(@"TestData", "UsingProperties"); |
| 548 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 549 | var output = Path.Combine(folder, $"FirewallSingleNested.xml"); |
| 550 | |
| 551 | build.BuildAndDecompileAndBuild(Build, Decompile, output); |
| 552 | |
| 553 | var doc = XDocument.Load(output); |
| 554 | var related = doc.Descendants() |
| 555 | .Where(e => |
| 556 | { |
| 557 | return e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/firewall" && |
| 558 | e.Parent.Attributes().Any(a => a.Name.LocalName == "Name" && a.Value == "Single Nested properties"); |
| 559 | }); |
| 560 | |
| 561 | var nested = related.Select(e => e.Attributes().Single(a => a.Name.LocalName == "Name").Value); |
| 562 | Assert.False(nested.Any()); |
| 563 | } |
| 564 | |
| 565 | [Fact] |
| 566 | public void RoundtripAttributesAreCorrectWhenMultipleNestedPropertiesAreUsed() |
| 567 | { |
| 568 | var actual = BuildAndDecompileAndBuild("http://wixtoolset.org/schemas/v4/wxs/firewall", "Multiple Nested properties", "UsingProperties"); |
| 569 | WixAssert.CompareLineByLine(new[] |
| 570 | { |
| 571 | "Id=fexWywW3VGiEuG23FOv1YM6h7R6F5Q", |
| 572 | "Name=Multiple Nested properties", |
| 573 | "xmlns=http://wixtoolset.org/schemas/v4/wxs/firewall" |
| 574 | }, actual.Attributes); |
| 575 | |
| 576 | var folder = TestData.Get(@"TestData", "UsingProperties"); |
| 577 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 578 | var output = Path.Combine(folder, $"FirewallMultipleNested.xml"); |
| 579 | |
| 580 | build.BuildAndDecompileAndBuild(Build, Decompile, output); |
| 581 | |
| 582 | var doc = XDocument.Load(output); |
| 583 | var related = doc.Descendants() |
| 584 | .Where(e => |
| 585 | { |
| 586 | return e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/firewall" && |
| 587 | e.Parent.Attributes().Any(a => a.Name.LocalName == "Name" && a.Value == "Multiple Nested properties"); |
| 588 | }); |
| 589 | |
| 590 | var interfaces = related.Where(e => e.Name.LocalName == "Interface") |
| 591 | .Select(e => e.Attributes().Single(a => a.Name.LocalName == "Name").Value); |
| 592 | WixAssert.CompareLineByLine(new[] |
| 593 | { |
| 594 | "[INTERFACE1]", |
| 595 | "[INTERFACE2]", |
| 596 | }, interfaces.ToArray()); |
| 597 | |
| 598 | var interfaceTypes = related.Where(e => e.Name.LocalName == "InterfaceType") |
| 599 | .Select(e => e.Attributes().Single(a => a.Name.LocalName == "Value").Value); |
| 600 | WixAssert.CompareLineByLine(new[] |
| 601 | { |
| 602 | "[INTERFACETYPE1]", |
| 603 | "[INTERFACETYPE2]", |
| 604 | }, interfaceTypes.ToArray()); |
| 605 | |
| 606 | var remotes = related.Where(e => e.Name.LocalName == "RemoteAddress") |
| 607 | .Select(e => e.Attributes().Single(a => a.Name.LocalName == "Value").Value); |
| 608 | WixAssert.CompareLineByLine(new[] |
| 609 | { |
| 610 | "[REMOTEADDRESS1]", |
| 611 | "[REMOTEADDRESS2]", |
| 612 | }, remotes.ToArray()); |
| 613 | |
| 614 | var locals = related.Where(e => e.Name.LocalName == "LocalAddress") |
| 615 | .Select(e => e.Attributes().Single(a => a.Name.LocalName == "Value").Value); |
| 616 | WixAssert.CompareLineByLine(new[] |
| 617 | { |
| 618 | "[LOCALADDRESS1]", |
| 619 | "[LOCALADDRESS2]", |
| 620 | }, locals.ToArray()); |
| 621 | } |
| 622 | |
| 623 | private static void Build(string[] args) |
| 624 | { |
| 625 | var result = WixRunner.Execute(args); |
| 626 | result.AssertSuccess(); |
| 627 | } |
| 628 | |
| 629 | private static void BuildARM64(string[] args) |
| 630 | { |
| 631 | var newArgs = args.ToList(); |
| 632 | newArgs.Add("-platform"); |
| 633 | newArgs.Add("arm64"); |
| 634 | |
| 635 | var result = WixRunner.Execute(newArgs.ToArray()); |
| 636 | result.AssertSuccess(); |
| 637 | } |
| 638 | |
| 639 | private static void Decompile(string[] args) |
| 640 | { |
| 641 | var result = WixRunner.Execute(args); |
| 642 | result.AssertSuccess(); |
| 643 | } |
| 644 | |
| 645 | class AttributeVerifier |
| 646 | { |
| 647 | public string Name { get; set; } |
| 648 | public string[] Attributes { get; set; } |
| 649 | } |
| 650 | |
| 651 | private static AttributeVerifier BuildAndDecompileAndBuild(string nameSpace, string ruleName, string path = "UsingFirewall") |
| 652 | { |
| 653 | var folder = TestData.Get(@"TestData", path); |
| 654 | var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder }); |
| 655 | var output = Path.Combine(folder, $"Firewall{ruleName}.xml"); |
| 656 | |
| 657 | build.BuildAndDecompileAndBuild(Build, Decompile, output, validate: true); |
| 658 | |
| 659 | var doc = XDocument.Load(output); |
| 660 | var actual = doc.Descendants() |
| 661 | .Where(e => |
| 662 | { |
| 663 | return e.Name.Namespace == nameSpace && e.Name.LocalName == "FirewallException"; |
| 664 | }) |
| 665 | .Select(fe => new AttributeVerifier |
| 666 | { |
| 667 | Name = fe.Attributes().Single(a => a.Name.LocalName == "Name").Value, |
| 668 | Attributes = fe.Attributes().Select(a => $"{a.Name.LocalName}={a.Value}").ToArray() |
| 669 | }) |
| 670 | .Single(av => av.Name == ruleName); |
| 671 | |
| 672 | return actual; |
| 673 | } |
| 674 | } |
| 675 | } |