From 54715f1cecf12276445ddc8bdb41ac631927456a Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Sat, 13 Jul 2024 15:52:51 +1000 Subject: [PATCH] Add conditional MsiE2E Tests for Domain functionality. This test currently fails under a Domain workstation. Signed-off-by: Bevan Weiss --- .../burn/WixTestTools/RuntimeFactAttribute.cs | 32 ++++++++++++++++++ .../ProductDomain/ProductDomain.wixproj | 13 ++++++++ .../ProductDomain/product.wxs | 33 +++++++++++++++++++ .../UtilExtensionUserTests.cs | 23 +++++++++++-- .../msi/WixToolsetTest.MsiE2E/runtests.cmd | 1 + 5 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/ProductDomain.wixproj create mode 100644 src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/product.wxs diff --git a/src/test/burn/WixTestTools/RuntimeFactAttribute.cs b/src/test/burn/WixTestTools/RuntimeFactAttribute.cs index f73c87a29..02cec9e44 100644 --- a/src/test/burn/WixTestTools/RuntimeFactAttribute.cs +++ b/src/test/burn/WixTestTools/RuntimeFactAttribute.cs @@ -3,16 +3,21 @@ namespace WixTestTools { using System; + using System.DirectoryServices.ActiveDirectory; using System.Security.Principal; using WixInternal.TestSupport.XunitExtensions; public class RuntimeFactAttribute : SkippableFactAttribute { const string RequiredEnvironmentVariableName = "RuntimeTestsEnabled"; + const string RequiredDomainEnvironmentVariableName = "RuntimeDomainTestsEnabled"; public static bool RuntimeTestsEnabled { get; } public static bool RunningAsAdministrator { get; } + public static bool RuntimeDomainTestsEnabled { get; } + public static bool RunningInDomain { get; } + static RuntimeFactAttribute() { using var identity = WindowsIdentity.GetCurrent(); @@ -21,6 +26,33 @@ static RuntimeFactAttribute() 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")})."; + } + } } public RuntimeFactAttribute() diff --git a/src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/ProductDomain.wixproj b/src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/ProductDomain.wixproj new file mode 100644 index 000000000..1477407a6 --- /dev/null +++ b/src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/ProductDomain.wixproj @@ -0,0 +1,13 @@ + + + + {08806ED8-3CE7-4BC3-A319-3ACCE3AAE7DC} + true + + + + + + + + diff --git a/src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/product.wxs b/src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/product.wxs new file mode 100644 index 000000000..93df23518 --- /dev/null +++ b/src/test/msi/TestData/UtilExtensionUserTests/ProductDomain/product.wxs @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs b/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs index 08b7cee18..41ea2f4c8 100644 --- a/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs +++ b/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs @@ -79,7 +79,7 @@ public void CanRollbackUsers() // Verify that command-line parameters are not blocked by repair switches. // Original code signalled repair mode by using "-f ", which silently // terminated the command-line parsing, ignoring any parameters that followed. - [RuntimeFact()] + [RuntimeFact] public void CanRepairUsersWithCommandLineParameters() { var arguments = new string[] @@ -103,7 +103,7 @@ public void CanRepairUsersWithCommandLineParameters() // Verify that the users specified in the authoring are created as expected on repair. - [RuntimeFact()] + [RuntimeFact] public void CanRepairUsers() { UserVerifier.CreateLocalUser("testName3", "test123!@#"); @@ -279,5 +279,24 @@ public void CanDeleteCommentOfExistingUser() // clean up UserVerifier.DeleteLocalUser("testName1"); } + + // Verify that the users specified in the authoring are created as expected. + [RuntimeFact(DomainRequired = true)] + public void CanInstallAndUninstallDomainUsers() + { + var productDomain = this.CreatePackageInstaller("ProductDomain"); + + productDomain.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + + // Validate New User Information. + UserVerifier.VerifyUserInformation("TESTDOMAIN", "testName1", true, false, true); + UserVerifier.VerifyUserIsMemberOf("TESTDOMAIN", "testName1", "Administrators", "TESTDOMAIN\\Domain Guests"); + UserVerifier.VerifyUserComment("TESTDOMAIN", "testName1", "testComment1"); + + productDomain.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + + // Verify Users marked as RemoveOnUninstall were removed. + Assert.False(UserVerifier.UserExists("TESTDOMAIN", "testName1"), String.Format("User '{0}\\{1}' was not removed on Uninstall", "TESTDOMAIN", "testName1")); + } } } diff --git a/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd b/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd index a2e67c891..ed1d50b68 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