Skip to content

Commit

Permalink
Add conditional MsiE2E Tests for Domain functionality.
Browse files Browse the repository at this point in the history
This test currently fails under a Domain workstation.

Signed-off-by: Bevan Weiss <[email protected]>
  • Loading branch information
bevanweiss committed Jul 18, 2024
1 parent ce613e2 commit bb4549d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/test/burn/WixTestTools/RuntimeFactAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<UpgradeCode>{08806ED8-3CE7-4BC3-A319-3ACCE3AAE7DC}</UpgradeCode>
<ProductComponentsRef>true</ProductComponentsRef>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Templates\Product.wxs" Link="Product.wxs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Util.wixext" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- 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. -->


<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Fragment>
<ComponentGroup Id="ProductComponents">
<ComponentRef Id="Component1" />
</ComponentGroup>

<Property Id="TEMPDOMAIN" Secure="yes" />
<Property Id="TEMPUSERNAME" Secure="yes" />
</Fragment>

<Fragment>
<util:Group Id="ADMIN" Name="Administrators" />
<util:Group Id="DOMAIN_GUESTS" Name="Domain Guests" Domain="TESTDOMAIN" />

<Component Id="Component1" Guid="09624A9A-4BBC-4126-BBF9-0713C5217DB1" Directory="INSTALLFOLDER">
<File Source="$(sys.SOURCEFILEPATH)" KeyPath="yes" />

<util:User Id="TEST_USER1" Name="testName1" Domain="TESTDOMAIN" Comment="testComment1"
Password="test123!@#"
PasswordNeverExpires="no"
PasswordExpired="yes"
Disabled="yes"
CreateUser="yes"
RemoveOnUninstall="yes">
<util:GroupRef Id="ADMIN" />
<util:GroupRef Id="DOMAIN_GUESTS" />
</util:User>
</Component>
</Fragment>
</Wix>
24 changes: 22 additions & 2 deletions src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void CanRollbackUsers()
// Verify that command-line parameters aer 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[]
Expand All @@ -98,7 +98,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!@#");
Expand Down Expand Up @@ -274,5 +274,25 @@ 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"));
}
}
}
1 change: 1 addition & 0 deletions src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
SET RuntimeTestsEnabled=true
SET RuntimeDomainTestsEnabled=true
dotnet test WixToolsetTest.MsiE2E.dll -v normal --logger trx

0 comments on commit bb4549d

Please sign in to comment.