Skip to content

Commit 088a2d3

Browse files
committed
Add conditional MsiE2E Tests for Domain functionality.
This test currently fails under a Domain workstation. Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
1 parent ce613e2 commit 088a2d3

File tree

6 files changed

+102
-3
lines changed

6 files changed

+102
-3
lines changed

src/test/burn/WixTestTools/RuntimeFactAttribute.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
namespace WixTestTools
44
{
55
using System;
6+
using System.DirectoryServices.ActiveDirectory;
67
using System.Security.Principal;
78
using WixInternal.TestSupport.XunitExtensions;
89

910
public class RuntimeFactAttribute : SkippableFactAttribute
1011
{
1112
const string RequiredEnvironmentVariableName = "RuntimeTestsEnabled";
13+
const string RequiredDomainEnvironmentVariableName = "RuntimeDomainTestsEnabled";
1214

1315
public static bool RuntimeTestsEnabled { get; }
1416
public static bool RunningAsAdministrator { get; }
1517

18+
public static bool RuntimeDomainTestsEnabled { get; }
19+
public static bool RunningInDomain { get; }
20+
1621
static RuntimeFactAttribute()
1722
{
1823
using var identity = WindowsIdentity.GetCurrent();
@@ -21,6 +26,33 @@ static RuntimeFactAttribute()
2126

2227
var testsEnabledString = Environment.GetEnvironmentVariable(RequiredEnvironmentVariableName);
2328
RuntimeTestsEnabled = Boolean.TryParse(testsEnabledString, out var testsEnabled) && testsEnabled;
29+
30+
RunningInDomain = false;
31+
try
32+
{
33+
RunningInDomain = !String.IsNullOrEmpty(System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name);
34+
}
35+
catch (ActiveDirectoryObjectNotFoundException) { }
36+
37+
var domainTestsEnabledString = Environment.GetEnvironmentVariable(RequiredDomainEnvironmentVariableName);
38+
RuntimeDomainTestsEnabled = Boolean.TryParse(domainTestsEnabledString, out var domainTestsEnabled) && domainTestsEnabled;
39+
}
40+
41+
private bool _domainRequired;
42+
public bool DomainRequired
43+
{
44+
get
45+
{
46+
return _domainRequired;
47+
}
48+
set
49+
{
50+
_domainRequired = value;
51+
if (_domainRequired && String.IsNullOrEmpty(this.Skip) && (!RunningInDomain || !RuntimeDomainTestsEnabled))
52+
{
53+
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")}).";
54+
}
55+
}
2456
}
2557

2658
public RuntimeFactAttribute()

src/test/burn/WixTestTools/UserVerifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static void VerifyUserInformation(string domainName, string userName, boo
172172
Assert.False(null == user, String.Format("User '{0}' was not found under domain '{1}'.", userName, domainName));
173173

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

177177
DateTime expirationDate = user.AccountExpirationDate.GetValueOrDefault();
178178
bool accountExpired = expirationDate.ToLocalTime().CompareTo(DateTime.Now) <= 0;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
<Project Sdk="WixToolset.Sdk">
3+
<PropertyGroup>
4+
<UpgradeCode>{08806ED8-3CE7-4BC3-A319-3ACCE3AAE7DC}</UpgradeCode>
5+
<ProductComponentsRef>true</ProductComponentsRef>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="..\..\Templates\Product.wxs" Link="Product.wxs" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<PackageReference Include="WixToolset.Util.wixext" />
12+
</ItemGroup>
13+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
4+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
5+
<Fragment>
6+
<ComponentGroup Id="ProductComponents">
7+
<ComponentRef Id="Component1" />
8+
</ComponentGroup>
9+
10+
<Property Id="TEMPDOMAIN" Secure="yes" />
11+
<Property Id="TEMPUSERNAME" Secure="yes" />
12+
</Fragment>
13+
14+
<Fragment>
15+
<util:Group Id="ADMIN" Name="Administrators" />
16+
<util:Group Id="DOMAIN_GUESTS" Name="Domain Guests" Domain="TESTDOMAIN" />
17+
18+
<Component Id="Component1" Guid="09624A9A-4BBC-4126-BBF9-0713C5217DB1" Directory="INSTALLFOLDER">
19+
<File Source="$(sys.SOURCEFILEPATH)" KeyPath="yes" />
20+
21+
<util:User Id="TEST_USER1" Name="testName1" Domain="TESTDOMAIN" Comment="testComment1"
22+
Password="test123!@#"
23+
PasswordNeverExpires="no"
24+
PasswordExpired="yes"
25+
Disabled="yes"
26+
CreateUser="yes"
27+
RemoveOnUninstall="yes">
28+
<util:GroupRef Id="ADMIN" />
29+
<util:GroupRef Id="DOMAIN_GUESTS" />
30+
</util:User>
31+
</Component>
32+
</Fragment>
33+
</Wix>

src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void CanRollbackUsers()
7474
// Verify that command-line parameters aer not blocked by repair switches.
7575
// Original code signalled repair mode by using "-f ", which silently
7676
// terminated the command-line parsing, ignoring any parameters that followed.
77-
[RuntimeFact()]
77+
[RuntimeFact]
7878
public void CanRepairUsersWithCommandLineParameters()
7979
{
8080
var arguments = new string[]
@@ -98,7 +98,7 @@ public void CanRepairUsersWithCommandLineParameters()
9898

9999

100100
// Verify that the users specified in the authoring are created as expected on repair.
101-
[RuntimeFact()]
101+
[RuntimeFact]
102102
public void CanRepairUsers()
103103
{
104104
UserVerifier.CreateLocalUser("testName3", "test123!@#");
@@ -274,5 +274,25 @@ public void CanDeleteCommentOfExistingUser()
274274
// clean up
275275
UserVerifier.DeleteLocalUser("testName1");
276276
}
277+
278+
// Verify that the users specified in the authoring are created as expected.
279+
[RuntimeFact(DomainRequired = true)]
280+
public void CanInstallAndUninstallDomainUsers()
281+
{
282+
283+
var productDomain = this.CreatePackageInstaller("ProductDomain");
284+
285+
productDomain.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
286+
287+
// Validate New User Information.
288+
UserVerifier.VerifyUserInformation("TESTDOMAIN", "testName1", true, false, true);
289+
UserVerifier.VerifyUserIsMemberOf("TESTDOMAIN", "testName1", "Administrators", "TESTDOMAIN\\Domain Guests");
290+
UserVerifier.VerifyUserComment("TESTDOMAIN", "testName1", "testComment1");
291+
292+
productDomain.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
293+
294+
// Verify Users marked as RemoveOnUninstall were removed.
295+
Assert.False(UserVerifier.UserExists("TESTDOMAIN", "testName1"), String.Format("User '{0}\\{1}' was not removed on Uninstall", "TESTDOMAIN", "testName1"));
296+
}
277297
}
278298
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
SET RuntimeTestsEnabled=true
2+
SET RuntimeDomainTestsEnabled=true
23
dotnet test WixToolsetTest.MsiE2E.dll -v normal --logger trx

0 commit comments

Comments
 (0)