Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Util:user - Add domain runtime test skipping, and integration test including Domain="[valid domain]" #547

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions src/test/burn/WixTestTools/UserVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public static void VerifyUserInformation(string domainName, string userName, boo

Assert.False(null == user, String.Format("User '{0}' was not found under domain '{1}'.", userName, domainName));

Assert.True(passwordNeverExpires == user.PasswordNeverExpires, String.Format("Password Never Expires for user '{0}/{1}' is: '{2}', expected: '{3}'.", domainName, userName, user.PasswordNeverExpires, passwordNeverExpires));
Assert.True(disabled != user.Enabled, String.Format("Disappled for user '{0}/{1}' is: '{2}', expected: '{3}'.", domainName, userName, !user.Enabled, disabled));
Assert.True(passwordNeverExpires == user.PasswordNeverExpires, String.Format("Password Never Expires for user '{0}\\{1}' is: '{2}', expected: '{3}'.", domainName, userName, user.PasswordNeverExpires, passwordNeverExpires));
Assert.True(disabled != user.Enabled, String.Format("Account disabled for user '{0}\\{1}' is: '{2}', expected: '{3}'.", domainName, userName, !user.Enabled, disabled));

DateTime expirationDate = user.AccountExpirationDate.GetValueOrDefault();
bool accountExpired = expirationDate.ToLocalTime().CompareTo(DateTime.Now) <= 0;
Assert.True(passwordExpired == accountExpired, String.Format("Password Expired for user '{0}/{1}' is: '{2}', expected: '{3}'.", domainName, userName, accountExpired, passwordExpired));
Assert.True(passwordExpired == accountExpired, String.Format("Password Expired for user '{0}\\{1}' is: '{2}', expected: '{3}'.", domainName, userName, accountExpired, passwordExpired));
}

/// <summary>
Expand Down Expand Up @@ -349,7 +349,7 @@ private static void IsUserMemberOf(string domainName, string userName, bool shou
if (found != shouldBeMember)
{
missedAGroup = true;
message += String.Format("User '{0}/{1}' is {2} a member of local group '{3}'. \r\n", domainName, userName, found ? String.Empty : "NOT", groupName);
message += String.Format("User '{0}\\{1}' is {2} a member of local group '{3}'. \r\n", domainName, userName, found ? String.Empty : "NOT", groupName);
}
}
catch (System.DirectoryServices.AccountManagement.PrincipalOperationException)
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>
23 changes: 21 additions & 2 deletions src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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!@#");
Expand Down Expand Up @@ -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"));
}
}
}
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
Loading