summaryrefslogtreecommitdiff
path: root/src/test/msi/WixToolsetTest.MsiE2E
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-04-28 21:02:23 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-04-29 00:23:14 -0500
commit5b04bce6567855325810bc4e6bcd2f6e05b329c7 (patch)
treea36e140d36c83a2ef7e81a88d941dd792bef3f55 /src/test/msi/WixToolsetTest.MsiE2E
parent681da11cfc9a266304b47b88843cb8a365015c63 (diff)
downloadwix-5b04bce6567855325810bc4e6bcd2f6e05b329c7.tar.gz
wix-5b04bce6567855325810bc4e6bcd2f6e05b329c7.tar.bz2
wix-5b04bce6567855325810bc4e6bcd2f6e05b329c7.zip
Port UtilExtension.UserTests from wix3.
Diffstat (limited to 'src/test/msi/WixToolsetTest.MsiE2E')
-rw-r--r--src/test/msi/WixToolsetTest.MsiE2E/MsiE2EFixture.cs28
-rw-r--r--src/test/msi/WixToolsetTest.MsiE2E/MsiE2ETests.cs44
-rw-r--r--src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs162
-rw-r--r--src/test/msi/WixToolsetTest.MsiE2E/WixToolsetTest.MsiE2E.csproj31
-rw-r--r--src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd2
5 files changed, 267 insertions, 0 deletions
diff --git a/src/test/msi/WixToolsetTest.MsiE2E/MsiE2EFixture.cs b/src/test/msi/WixToolsetTest.MsiE2E/MsiE2EFixture.cs
new file mode 100644
index 00000000..a7646568
--- /dev/null
+++ b/src/test/msi/WixToolsetTest.MsiE2E/MsiE2EFixture.cs
@@ -0,0 +1,28 @@
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
3namespace WixToolsetTest.MsiE2E
4{
5 using System;
6 using System.Security.Principal;
7
8 public class MsiE2EFixture
9 {
10 const string RequiredEnvironmentVariableName = "RuntimeTestsEnabled";
11
12 public MsiE2EFixture()
13 {
14 using var identity = WindowsIdentity.GetCurrent();
15 var principal = new WindowsPrincipal(identity);
16 if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
17 {
18 throw new InvalidOperationException("These tests must run elevated.");
19 }
20
21 var testsEnabledString = Environment.GetEnvironmentVariable(RequiredEnvironmentVariableName);
22 if (!bool.TryParse(testsEnabledString, out var testsEnabled) || !testsEnabled)
23 {
24 throw new InvalidOperationException($"These tests affect machine state. Set the {RequiredEnvironmentVariableName} environment variable to true to accept the consequences.");
25 }
26 }
27 }
28}
diff --git a/src/test/msi/WixToolsetTest.MsiE2E/MsiE2ETests.cs b/src/test/msi/WixToolsetTest.MsiE2E/MsiE2ETests.cs
new file mode 100644
index 00000000..22f2173b
--- /dev/null
+++ b/src/test/msi/WixToolsetTest.MsiE2E/MsiE2ETests.cs
@@ -0,0 +1,44 @@
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
3namespace WixToolsetTest.MsiE2E
4{
5 using System;
6 using System.Collections.Generic;
7 using WixTestTools;
8 using Xunit;
9 using Xunit.Abstractions;
10
11 [Collection("MsiE2E")]
12 public abstract class MsiE2ETests : WixTestBase, IDisposable
13 {
14 protected MsiE2ETests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
15 {
16 }
17
18 private Stack<IDisposable> Installers { get; } = new Stack<IDisposable>();
19
20 protected PackageInstaller CreatePackageInstaller(string filename)
21 {
22 var installer = new PackageInstaller(this.TestContext, filename);
23 this.Installers.Push(installer);
24 return installer;
25 }
26
27 public void Dispose()
28 {
29 while (this.Installers.TryPop(out var installer))
30 {
31 try
32 {
33 installer.Dispose();
34 }
35 catch { }
36 }
37 }
38 }
39
40 [CollectionDefinition("MsiE2E", DisableParallelization = true)]
41 public class MsiE2ECollectionDefinition : ICollectionFixture<MsiE2EFixture>
42 {
43 }
44}
diff --git a/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs b/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs
new file mode 100644
index 00000000..21491858
--- /dev/null
+++ b/src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionUserTests.cs
@@ -0,0 +1,162 @@
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
3namespace WixToolsetTest.MsiE2E
4{
5 using System;
6 using WixTestTools;
7 using Xunit;
8 using Xunit.Abstractions;
9
10 public class UtilExtensionUserTests : MsiE2ETests
11 {
12 public UtilExtensionUserTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
13
14 const string TempDomain = "USERDOMAIN";
15 const string TempUsername = "USERNAME";
16
17 // Verify that the users specified in the authoring are created as expected.
18 [Fact]
19 public void CanInstallAndUninstallUsers()
20 {
21 var arguments = new string[]
22 {
23 $"TEMPDOMAIN={Environment.GetEnvironmentVariable(TempDomain)}",
24 $"TEMPUSERNAME={Environment.GetEnvironmentVariable(TempUsername)}",
25 };
26 var productA = this.CreatePackageInstaller("ProductA");
27
28 productA.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
29
30 // Validate New User Information.
31 UserVerifier.VerifyUserInformation(String.Empty, "testName1", true, false, false);
32 UserVerifier.VerifyUserIsMemberOf(String.Empty, "testName1", "Administrators", "Power Users");
33
34 UserVerifier.VerifyUserInformation(String.Empty, "testName2", true, true, true);
35 UserVerifier.VerifyUserIsMemberOf(String.Empty, "testName2", "Power Users");
36
37 UserVerifier.VerifyUserIsMemberOf(Environment.GetEnvironmentVariable(TempDomain), Environment.GetEnvironmentVariable(TempUsername), "Power Users");
38
39 productA.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
40
41 // Verify Users marked as RemoveOnUninstall were removed.
42 Assert.False(UserVerifier.UserExists(String.Empty, "testName1"), String.Format("User '{0}' was not removed on Uninstall", "testName1"));
43 Assert.True(UserVerifier.UserExists(String.Empty, "testName2"), String.Format("User '{0}' was removed on Uninstall", "testName2"));
44
45 // clean up
46 UserVerifier.DeleteLocalUser("testName2");
47
48 UserVerifier.VerifyUserIsNotMemberOf(Environment.GetEnvironmentVariable(TempDomain), Environment.GetEnvironmentVariable(TempUsername), "Power Users");
49 }
50
51 // Verify the rollback action reverts all Users changes.
52 [Fact]
53 public void CanRollbackUsers()
54 {
55 var arguments = new string[]
56 {
57 $"TEMPDOMAIN={Environment.GetEnvironmentVariable(TempDomain)}",
58 $"TEMPUSERNAME={Environment.GetEnvironmentVariable(TempUsername)}",
59 };
60 var productFail = this.CreatePackageInstaller("ProductFail");
61
62 // make sure the user accounts are deleted before we start
63 UserVerifier.DeleteLocalUser("testName1");
64 UserVerifier.DeleteLocalUser("testName2");
65 UserVerifier.VerifyUserIsNotMemberOf(Environment.GetEnvironmentVariable(TempDomain), Environment.GetEnvironmentVariable(TempUsername), "Power Users");
66
67 productFail.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, arguments);
68
69 // Verify Users marked as RemoveOnUninstall were removed.
70 Assert.False(UserVerifier.UserExists(String.Empty, "testName1"), String.Format("User '{0}' was not removed on Rollback", "testName1"));
71 Assert.False(UserVerifier.UserExists(String.Empty, "testName2"), String.Format("User '{0}' was not removed on Rollback", "testName2"));
72
73 UserVerifier.VerifyUserIsNotMemberOf(Environment.GetEnvironmentVariable(TempDomain), Environment.GetEnvironmentVariable(TempUsername), "Power Users");
74 }
75
76 // Verify that the users specified in the authoring are created as expected on repair.
77 [Fact(Skip = "Test demonstrates failure")]
78 public void CanRepairUsers()
79 {
80 var arguments = new string[]
81 {
82 $"TEMPDOMAIN={Environment.GetEnvironmentVariable(TempDomain)}",
83 $"TEMPUSERNAME={Environment.GetEnvironmentVariable(TempUsername)}",
84 };
85 var productA = this.CreatePackageInstaller("ProductA");
86
87 productA.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
88
89 UserVerifier.DeleteLocalUser("testName1");
90 UserVerifier.SetUserInformation(String.Empty, "testName2", true, false, false);
91
92 productA.RepairProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
93
94 // Validate New User Information.
95 UserVerifier.VerifyUserInformation(String.Empty, "testName1", true, false, false);
96 UserVerifier.VerifyUserIsMemberOf(String.Empty, "testName1", "Administrators", "Power Users");
97
98 UserVerifier.VerifyUserInformation(String.Empty, "testName2", true, true, true);
99 UserVerifier.VerifyUserIsMemberOf(String.Empty, "testName2", "Power Users");
100
101 UserVerifier.VerifyUserIsMemberOf(Environment.GetEnvironmentVariable(TempDomain), Environment.GetEnvironmentVariable(TempUsername), "Power Users");
102
103 productA.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
104
105 // Verify Users marked as RemoveOnUninstall were removed.
106 Assert.False(UserVerifier.UserExists(String.Empty, "testName1"), String.Format("User '{0}' was not removed on Uninstall", "testName1"));
107 Assert.True(UserVerifier.UserExists(String.Empty, "testName2"), String.Format("User '{0}' was removed on Uninstall", "testName2"));
108
109 // clean up
110 UserVerifier.DeleteLocalUser("testName2");
111
112 UserVerifier.VerifyUserIsNotMemberOf(Environment.GetEnvironmentVariable(TempDomain), Environment.GetEnvironmentVariable(TempUsername), "Power Users");
113 }
114
115 // Verify that Installation fails if FailIfExisits is set.
116 [Fact]
117 public void FailsIfUserExists()
118 {
119 var productFailIfExists = this.CreatePackageInstaller("ProductFailIfExists");
120
121 // Create 'existinguser'
122 UserVerifier.CreateLocalUser("existinguser", "test123!@#");
123
124 try
125 {
126 productFailIfExists.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE);
127
128 // Verify User still exists.
129 bool userExists = UserVerifier.UserExists(String.Empty, "existinguser");
130
131 Assert.True(userExists, String.Format("User '{0}' was removed on Rollback", "existinguser"));
132 }
133 finally
134 {
135 // clean up
136 UserVerifier.DeleteLocalUser("existinguser");
137 }
138
139 }
140
141 // Verify that a user cannot be created on a domain on which you dont have create user permission.
142 [Fact]
143 public void FailsIfRestrictedDomain()
144 {
145 var productRestrictedDomain = this.CreatePackageInstaller("ProductRestrictedDomain");
146
147 string logFile = productRestrictedDomain.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "TEMPDOMAIN=DOESNOTEXIST");
148
149 // Verify expected error message in the log file
150 Assert.True(LogVerifier.MessageInLogFile(logFile, "ConfigureUsers: Failed to check existence of domain: DOESNOTEXIST, user: testName1 (error code 0x800706ba) - continuing"));
151 }
152
153 // Verify that adding a user to a non-existent group does not fail the install when non-vital.
154 [Fact]
155 public void IgnoresMissingGroupWhenNonVital()
156 {
157 var productNonVitalGroup = this.CreatePackageInstaller("ProductNonVitalUserGroup");
158
159 productNonVitalGroup.InstallProduct();
160 }
161 }
162}
diff --git a/src/test/msi/WixToolsetTest.MsiE2E/WixToolsetTest.MsiE2E.csproj b/src/test/msi/WixToolsetTest.MsiE2E/WixToolsetTest.MsiE2E.csproj
new file mode 100644
index 00000000..ccf98042
--- /dev/null
+++ b/src/test/msi/WixToolsetTest.MsiE2E/WixToolsetTest.MsiE2E.csproj
@@ -0,0 +1,31 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- 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. -->
3
4<Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netcoreapp3.1</TargetFramework>
7 <PlatformTarget>x64</PlatformTarget>
8 <RollForward>Major</RollForward>
9 </PropertyGroup>
10
11 <ItemGroup>
12 <Content Include="runtests.cmd" CopyToOutputDirectory="PreserveNewest" />
13 </ItemGroup>
14
15 <ItemGroup>
16 <ProjectReference Include="..\..\burn\WixTestTools\WixTestTools.csproj" />
17 </ItemGroup>
18
19 <ItemGroup>
20 <PackageReference Include="Microsoft.Win32.Registry" />
21 <PackageReference Include="System.Security.Principal.Windows" />
22 <PackageReference Include="WixBuildTools.TestSupport" />
23 <PackageReference Include="WixToolset.Data" />
24 </ItemGroup>
25
26 <ItemGroup>
27 <PackageReference Include="Microsoft.NET.Test.Sdk" />
28 <PackageReference Include="xunit" />
29 <PackageReference Include="xunit.runner.visualstudio" PrivateAssets="All" />
30 </ItemGroup>
31</Project>
diff --git a/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd b/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd
new file mode 100644
index 00000000..f609ebe4
--- /dev/null
+++ b/src/test/msi/WixToolsetTest.MsiE2E/runtests.cmd
@@ -0,0 +1,2 @@
1SET RuntimeTestsEnabled=true
2dotnet test WixToolsetTest.MsiE2E.dll -v normal \ No newline at end of file