From 5b4a6538ee06988c75b717bd905197fb670e6142 Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Sun, 4 Aug 2024 21:13:44 +1000 Subject: Add/Remove Group Membership rollback handled. Fixups to a few test cases. Signed-off-by: Bevan Weiss --- src/test/burn/WixTestTools/RuntimeFactAttribute.cs | 32 +++++++- .../UtilExtensionGroupTests/ProductA/product.wxs | 9 +- .../ProductAddCommentToExistingGroup/product.wxs | 9 +- .../ProductCommentDelete/product.wxs | 4 +- .../ProductCommentFail/product_fail.wxs | 4 +- .../ProductFail/product_fail.wxs | 2 + .../ProductFailIfExists/FailIfExists.wxs | 2 + .../ProductNestedGroups/product.wxs | 7 +- .../ProductNewGroupWithComment/product.wxs | 9 +- .../ProductNonVitalGroup/NonVitalUserGroup.wxs | 2 + .../ProductRestrictedDomain/RestrictedDomain.wxs | 4 +- .../ProductWithCommandLineParameters.wxs | 11 +-- .../UtilExtensionGroupTests.cs | 95 ++++++++++++++++------ src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd | 1 + 14 files changed, 135 insertions(+), 56 deletions(-) (limited to 'src/test') diff --git a/src/test/burn/WixTestTools/RuntimeFactAttribute.cs b/src/test/burn/WixTestTools/RuntimeFactAttribute.cs index 573a9de2..76004f26 100644 --- a/src/test/burn/WixTestTools/RuntimeFactAttribute.cs +++ b/src/test/burn/WixTestTools/RuntimeFactAttribute.cs @@ -3,6 +3,7 @@ namespace WixTestTools { using System; + using System.DirectoryServices.ActiveDirectory; using System.Security.Principal; using WixInternal.TestSupport.XunitExtensions; using System.Runtime.InteropServices; @@ -10,10 +11,13 @@ namespace WixTestTools public class RuntimeFactAttribute : SkippableFactAttribute { const string RequiredEnvironmentVariableName = "RuntimeTestsEnabled"; + const string RequiredDomainEnvironmentVariableName = "RuntimeDomainTestsEnabled"; public static bool RuntimeTestsEnabled { get; } + public static bool RuntimeDomainTestsEnabled { get; } public static bool RunningAsAdministrator { get; } public static bool RunningOnWindowsServer { get; } + public static bool RunningInDomain { get; } [DllImport("shlwapi.dll", SetLastError = true, EntryPoint = "#437")] private static extern bool IsOS(int os); @@ -23,7 +27,6 @@ namespace WixTestTools return IsOS(OS_ANYSERVER); } - static RuntimeFactAttribute() { using var identity = WindowsIdentity.GetCurrent(); @@ -33,6 +36,33 @@ namespace WixTestTools var testsEnabledString = Environment.GetEnvironmentVariable(RequiredEnvironmentVariableName); RuntimeTestsEnabled = Boolean.TryParse(testsEnabledString, out var testsEnabled) && testsEnabled; + RunningInDomain = false; + try + { + RunningInDomain = !String.IsNullOrEmpty(System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name); + } + catch (ActiveDirectoryObjectNotFoundException) { } + + var domainTestsEnabledString = Environment.GetEnvironmentVariable(RequiredDomainEnvironmentVariableName); + RuntimeDomainTestsEnabled = Boolean.TryParse(domainTestsEnabledString, out var domainTestsEnabled) && domainTestsEnabled; + } + + private bool _domainRequired; + public bool DomainRequired + { + get + { + return _domainRequired; + } + set + { + _domainRequired = value; + if (_domainRequired && String.IsNullOrEmpty(this.Skip) && (!RunningInDomain || !RuntimeDomainTestsEnabled)) + { + this.Skip = $"These tests require the test host to be running as a domain member ({(RunningInDomain ? "passed" : "failed")}). These tests affect both MACHINE AND DOMAIN state. To accept the consequences, set the {RequiredDomainEnvironmentVariableName} environment variable to true ({(RuntimeDomainTestsEnabled ? "passed" : "failed")})."; + } + } + RunningOnWindowsServer = IsWindowsServer(); } diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductA/product.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductA/product.wxs index e3c143e6..f7f60fdb 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductA/product.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductA/product.wxs @@ -7,19 +7,18 @@ - - + - + - + - + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductAddCommentToExistingGroup/product.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductAddCommentToExistingGroup/product.wxs index e0170746..6c9d3be3 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductAddCommentToExistingGroup/product.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductAddCommentToExistingGroup/product.wxs @@ -6,18 +6,15 @@ + + - + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentDelete/product.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentDelete/product.wxs index d1824890..a34a276b 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentDelete/product.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentDelete/product.wxs @@ -6,13 +6,15 @@ + + - + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentFail/product_fail.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentFail/product_fail.wxs index 4e70717f..79396882 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentFail/product_fail.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductCommentFail/product_fail.wxs @@ -10,13 +10,15 @@ + + - + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductFail/product_fail.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductFail/product_fail.wxs index 3013e5a0..148f26ca 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductFail/product_fail.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductFail/product_fail.wxs @@ -13,6 +13,8 @@ + + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductFailIfExists/FailIfExists.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductFailIfExists/FailIfExists.wxs index 00f8e12d..e7acb5e0 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductFailIfExists/FailIfExists.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductFailIfExists/FailIfExists.wxs @@ -6,6 +6,8 @@ + + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductNestedGroups/product.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductNestedGroups/product.wxs index c27eb27a..f513e7c6 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductNestedGroups/product.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductNestedGroups/product.wxs @@ -7,13 +7,14 @@ - + - + + @@ -25,6 +26,8 @@ + + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductNewGroupWithComment/product.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductNewGroupWithComment/product.wxs index 2d012b23..2305a80b 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductNewGroupWithComment/product.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductNewGroupWithComment/product.wxs @@ -6,18 +6,15 @@ + + + Id="TEST_GROUP1" Name="testName1" CreateGroup="yes" UpdateIfExists="yes" RemoveOnUninstall="yes" Comment="testComment1" /> diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductNonVitalGroup/NonVitalUserGroup.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductNonVitalGroup/NonVitalUserGroup.wxs index a834c76b..4922fcef 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductNonVitalGroup/NonVitalUserGroup.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductNonVitalGroup/NonVitalUserGroup.wxs @@ -6,6 +6,8 @@ + + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductRestrictedDomain/RestrictedDomain.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductRestrictedDomain/RestrictedDomain.wxs index edb3387c..04a1ac4e 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductRestrictedDomain/RestrictedDomain.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductRestrictedDomain/RestrictedDomain.wxs @@ -7,14 +7,14 @@ - + - + diff --git a/src/test/msi/TestData/UtilExtensionGroupTests/ProductWithCommandLineParameters/ProductWithCommandLineParameters.wxs b/src/test/msi/TestData/UtilExtensionGroupTests/ProductWithCommandLineParameters/ProductWithCommandLineParameters.wxs index 059ecee8..36d10aa3 100644 --- a/src/test/msi/TestData/UtilExtensionGroupTests/ProductWithCommandLineParameters/ProductWithCommandLineParameters.wxs +++ b/src/test/msi/TestData/UtilExtensionGroupTests/ProductWithCommandLineParameters/ProductWithCommandLineParameters.wxs @@ -4,16 +4,13 @@ + + - - + + diff --git a/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionGroupTests.cs b/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionGroupTests.cs index d7cf3168..cee357a6 100644 --- a/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionGroupTests.cs +++ b/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionGroupTests.cs @@ -11,9 +11,10 @@ namespace WixToolsetTest.MsiE2E { public UtilExtensionGroupTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } + #region Non Domain // Verify that the users specified in the authoring are created as expected. [RuntimeFact] - public void CanInstallAndUninstallGroups() + public void CanInstallAndUninstallNonDomainGroups() { UserGroupVerifier.CreateLocalGroup("testName3"); var productA = this.CreatePackageInstaller("ProductA"); @@ -39,7 +40,7 @@ namespace WixToolsetTest.MsiE2E // Verify the rollback action reverts all Users changes. [RuntimeFact] - public void CanRollbackGroups() + public void CanRollbackNonDomainGroups() { UserGroupVerifier.CreateLocalGroup("testName3"); var productFail = this.CreatePackageInstaller("ProductFail"); @@ -65,7 +66,7 @@ namespace WixToolsetTest.MsiE2E // Original code signalled repair mode by using "-f ", which silently // terminated the command-line parsing, ignoring any parameters that followed. [RuntimeFact()] - public void CanRepairGroupsWithCommandLineParameters() + public void CanRepairNonDomainGroupsWithCommandLineParameters() { var arguments = new string[] { @@ -82,6 +83,10 @@ namespace WixToolsetTest.MsiE2E // Repair productWithCommandLineParameters.RepairProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments); + + // Install + productWithCommandLineParameters.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments); + // Clean up UserGroupVerifier.DeleteLocalGroup("testName1"); } @@ -89,7 +94,7 @@ namespace WixToolsetTest.MsiE2E // Verify that the groups specified in the authoring are created as expected on repair. [RuntimeFact()] - public void CanRepairGroups() + public void CanRepairNonDomainGroups() { UserGroupVerifier.CreateLocalGroup("testName3"); var productA = this.CreatePackageInstaller("ProductA"); @@ -119,7 +124,7 @@ namespace WixToolsetTest.MsiE2E // Verify that Installation fails if FailIfExists is set. [RuntimeFact] - public void FailsIfGroupExists() + public void FailsIfNonDomainGroupExists() { var productFailIfExists = this.CreatePackageInstaller("ProductFailIfExists"); @@ -148,7 +153,7 @@ namespace WixToolsetTest.MsiE2E { var productRestrictedDomain = this.CreatePackageInstaller("ProductRestrictedDomain"); - string logFile = productRestrictedDomain.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "TEMPDOMAIN=DOESNOTEXIST"); + string logFile = productRestrictedDomain.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "TESTDOMAIN=DOESNOTEXIST"); // Verify expected error message in the log file Assert.True(LogVerifier.MessageInLogFile(logFile, "CreateGroup: Error 0x8007054b: failed to find Domain DOESNOTEXIST.")); @@ -156,12 +161,13 @@ namespace WixToolsetTest.MsiE2E // Verify that a group can be created with a group comment [RuntimeFact] - public void CanCreateNewGroupWithComment() + public void CanCreateNewNonDomainGroupWithComment() { var productNewUserWithComment = this.CreatePackageInstaller("ProductNewGroupWithComment"); - productNewUserWithComment.InstallProduct(); + productNewUserWithComment.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1"); + productNewUserWithComment.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); // clean up UserGroupVerifier.DeleteLocalGroup("testName1"); @@ -169,30 +175,33 @@ namespace WixToolsetTest.MsiE2E // Verify that a comment can be added to an existing group [RuntimeFact] - public void CanAddCommentToExistingGroup() + public void CanAddCommentToExistingNonDomainGroup() { UserGroupVerifier.CreateLocalGroup("testName1"); var productAddCommentToExistingUser = this.CreatePackageInstaller("ProductAddCommentToExistingGroup"); - productAddCommentToExistingUser.InstallProduct(); + productAddCommentToExistingUser.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1"); + productAddCommentToExistingUser.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + // clean up UserGroupVerifier.DeleteLocalGroup("testName1"); } // Verify that a comment can be repaired for a new group [RuntimeFact] - public void CanRepairCommentOfNewGroup() + public void CanRepairCommentOfNewNonDomainGroup() { var productNewUserWithComment = this.CreatePackageInstaller("ProductNewGroupWithComment"); - productNewUserWithComment.InstallProduct(); + productNewUserWithComment.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); UserGroupVerifier.SetGroupComment(String.Empty, "testName1", ""); - productNewUserWithComment.RepairProduct(); + productNewUserWithComment.RepairProduct(MSIExec.MSIExecReturnCode.SUCCESS); UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1"); + productNewUserWithComment.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); // clean up UserGroupVerifier.DeleteLocalGroup("testName1"); @@ -200,14 +209,15 @@ namespace WixToolsetTest.MsiE2E // Verify that a comment can be changed for an existing group [RuntimeFact] - public void CanChangeCommentOfExistingGroup() + public void CanChangeCommentOfExistingNonDomainGroup() { UserGroupVerifier.CreateLocalGroup("testName1"); UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "initialTestComment1"); var productNewUserWithComment = this.CreatePackageInstaller("ProductNewGroupWithComment"); - productNewUserWithComment.InstallProduct(); + productNewUserWithComment.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1"); + productNewUserWithComment.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); // clean up UserGroupVerifier.DeleteLocalGroup("testName1"); @@ -215,7 +225,7 @@ namespace WixToolsetTest.MsiE2E // Verify that a comment can be rolled back for an existing group [RuntimeFact] - public void CanRollbackCommentOfExistingGroup() + public void CanRollbackCommentOfExistingNonDomainGroup() { UserGroupVerifier.CreateLocalGroup("testName1"); UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "initialTestComment1"); @@ -232,7 +242,7 @@ namespace WixToolsetTest.MsiE2E // Verify that a comment can be deleted for an existing group [RuntimeFact] - public void CanDeleteCommentOfExistingGroup() + public void CanDeleteCommentOfExistingNonDomainGroup() { UserGroupVerifier.CreateLocalGroup("testName1"); UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "testComment1"); @@ -243,29 +253,64 @@ namespace WixToolsetTest.MsiE2E // Verify that comment was removed. UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", ""); + + productCommentDelete.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + // clean up UserGroupVerifier.DeleteLocalGroup("testName1"); } - // Verify that a comment can be deleted for an existing group - [RuntimeFact] - public void CanNestGroups() + #endregion + + #region Domain + // Verify that a domain group can be nested within a local group + [RuntimeFact(DomainRequired = true)] + public void CanNestDomainGroups() { + var testDomain = System.Environment.UserDomainName; var productNestedGroups = this.CreatePackageInstaller("ProductNestedGroups"); - productNestedGroups.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + productNestedGroups.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, $"TESTDOMAIN={testDomain}"); // Verify group nested membership - UserGroupVerifier.VerifyIsMemberOf(String.Empty, "Authenticated Users", new string[] { "testName1", "testName2" }); - UserGroupVerifier.VerifyIsMemberOf(String.Empty, "Everyone", new string[] { "testName1" }); + UserGroupVerifier.VerifyIsMemberOf(testDomain, "Domain Users", new string[] { "testName1", "testName2" }); + //UserGroupVerifier.VerifyIsMemberOf(String.Empty, "Everyone", new string[] { "testName1" }); + + UserGroupVerifier.VerifyIsNotMemberOf(testDomain, "Domain Users", new string[] { "testName3" }); + //UserGroupVerifier.VerifyIsNotMemberOf(String.Empty, "Everyone", new string[] { "testName2", "testName3" }); - UserGroupVerifier.VerifyIsNotMemberOf(String.Empty, "Authenticated Users", new string[] { "testName3" }); - UserGroupVerifier.VerifyIsNotMemberOf(String.Empty, "Everyone", new string[] { "testName2", "testName3" }); + productNestedGroups.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, $"TESTDOMAIN={testDomain}"); // clean up UserGroupVerifier.DeleteLocalGroup("testName1"); UserGroupVerifier.DeleteLocalGroup("testName2"); UserGroupVerifier.DeleteLocalGroup("testName3"); } + + // Verify the rollback action reverts all Users changes. + [RuntimeFact(DomainRequired = true)] + public void CanRollbackDomainGroups() + { + var testDomain = System.Environment.UserDomainName; + UserGroupVerifier.CreateLocalGroup("testName3"); + var productFail = this.CreatePackageInstaller("ProductFail"); + + // make sure the user accounts are deleted before we start + UserGroupVerifier.DeleteLocalGroup("testName1"); + UserGroupVerifier.DeleteLocalGroup("testName2"); + + productFail.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, $"TESTDOMAIN={testDomain}"); + + // Verify added Users were removed on rollback. + Assert.False(UserGroupVerifier.GroupExists(String.Empty, "testName1"), String.Format("Group '{0}' was not removed on Rollback", "testName1")); + Assert.False(UserGroupVerifier.GroupExists(String.Empty, "testName2"), String.Format("Group '{0}' was not removed on Rollback", "testName2")); + + // clean up + UserGroupVerifier.DeleteLocalGroup("testName1"); + UserGroupVerifier.DeleteLocalGroup("testName2"); + UserGroupVerifier.DeleteLocalGroup("testName3"); + } + + #endregion } } diff --git a/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd b/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd index a2e67c89..ed1d50b6 100644 --- a/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd +++ b/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd @@ -1,2 +1,3 @@ SET RuntimeTestsEnabled=true +SET RuntimeDomainTestsEnabled=true dotnet test WixToolsetTest.MsiE2E.dll -v normal --logger trx -- cgit v1.2.3-55-g6feb