1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
// 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.
namespace WixToolsetTest.MsiE2E
{
using System;
using WixTestTools;
using Xunit;
using Xunit.Abstractions;
public class UtilExtensionGroupTests : MsiE2ETests
{
public UtilExtensionGroupTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
// Verify that the users specified in the authoring are created as expected.
[RuntimeFact]
public void CanInstallAndUninstallGroups()
{
UserGroupVerifier.CreateLocalGroup("testName3");
var productA = this.CreatePackageInstaller("ProductA");
productA.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Validate New User Information.
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName1"), String.Format("Group '{0}' was not created on Install", "testName1"));
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName2"), String.Format("Group '{0}' was not created on Install", "testName2"));
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName3"), String.Format("Group '{0}' was not created on Install", "testName3"));
productA.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Verify Users marked as RemoveOnUninstall were removed.
Assert.False(UserGroupVerifier.GroupExists(String.Empty, "testName1"), String.Format("Group '{0}' was not removed on Uninstall", "testName1"));
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName2"), String.Format("Group '{0}' was removed on Uninstall", "testName2"));
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
UserGroupVerifier.DeleteLocalGroup("testName2");
UserGroupVerifier.DeleteLocalGroup("testName3");
}
// Verify the rollback action reverts all Users changes.
[RuntimeFact]
public void CanRollbackGroups()
{
UserGroupVerifier.CreateLocalGroup("testName3");
var productFail = this.CreatePackageInstaller("ProductFail");
// make sure the user accounts are deleted before we start
UserGroupVerifier.DeleteLocalGroup("testName1");
UserGroupVerifier.DeleteLocalGroup("testName2");
productFail.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE);
// Verify added Users were removed on rollback.
Assert.False(UserGroupVerifier.GroupExists(String.Empty, "testName1"), String.Format("Group '{0}' was not removed on Rollback", "testName1"));
Assert.False(UserGroupVerifier.GroupExists(String.Empty, "testName2"), String.Format("Group '{0}' was not removed on Rollback", "testName2"));
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
UserGroupVerifier.DeleteLocalGroup("testName2");
UserGroupVerifier.DeleteLocalGroup("testName3");
}
// 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()]
public void CanRepairGroupsWithCommandLineParameters()
{
var arguments = new string[]
{
"TESTPARAMETER1=testName1",
};
var productWithCommandLineParameters = this.CreatePackageInstaller("ProductWithCommandLineParameters");
// Make sure that the user doesn't exist when we start the test.
UserGroupVerifier.DeleteLocalGroup("testName1");
// Install
productWithCommandLineParameters.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
// Repair
productWithCommandLineParameters.RepairProduct(MSIExec.MSIExecReturnCode.SUCCESS, arguments);
// Clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that the groups specified in the authoring are created as expected on repair.
[RuntimeFact()]
public void CanRepairGroups()
{
UserGroupVerifier.CreateLocalGroup("testName3");
var productA = this.CreatePackageInstaller("ProductA");
productA.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Validate New User Information.
UserGroupVerifier.DeleteLocalGroup("testName1");
productA.RepairProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Validate New User Information.
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName1"), String.Format("User '{0}' was not installed on Repair", "testName1"));
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName2"), String.Format("User '{0}' was not installed after Repair", "testName2"));
productA.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Verify Users marked as RemoveOnUninstall were removed.
Assert.False(UserGroupVerifier.GroupExists(String.Empty, "testName1"), String.Format("User '{0}' was not removed on Uninstall", "testName1"));
Assert.True(UserGroupVerifier.GroupExists(String.Empty, "testName2"), String.Format("User '{0}' was removed on Uninstall", "testName2"));
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
UserGroupVerifier.DeleteLocalGroup("testName2");
UserGroupVerifier.DeleteLocalGroup("testName3");
}
// Verify that Installation fails if FailIfExists is set.
[RuntimeFact]
public void FailsIfGroupExists()
{
var productFailIfExists = this.CreatePackageInstaller("ProductFailIfExists");
// Create 'existinggroup'
UserGroupVerifier.CreateLocalGroup("existinggroup");
try
{
productFailIfExists.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE);
// Verify User still exists.
bool userExists = UserGroupVerifier.GroupExists(String.Empty, "existinggroup");
Assert.True(userExists, String.Format("Group '{0}' was removed on Rollback", "existinggroup"));
}
finally
{
// clean up
UserGroupVerifier.DeleteLocalGroup("existinggroup");
}
}
// Verify that a group cannot be created on a domain on which you don't have create user permission.
[RuntimeFact]
public void FailsIfRestrictedDomain()
{
var productRestrictedDomain = this.CreatePackageInstaller("ProductRestrictedDomain");
string logFile = productRestrictedDomain.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "TEMPDOMAIN=DOESNOTEXIST");
// Verify expected error message in the log file
Assert.True(LogVerifier.MessageInLogFile(logFile, "CreateGroup: Error 0x8007054b: failed to find Domain DOESNOTEXIST."));
}
// Verify that a group can be created with a group comment
[RuntimeFact]
public void CanCreateNewGroupWithComment()
{
var productNewUserWithComment = this.CreatePackageInstaller("ProductNewGroupWithComment");
productNewUserWithComment.InstallProduct();
UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1");
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that a comment can be added to an existing group
[RuntimeFact]
public void CanAddCommentToExistingGroup()
{
UserGroupVerifier.CreateLocalGroup("testName1");
var productAddCommentToExistingUser = this.CreatePackageInstaller("ProductAddCommentToExistingGroup");
productAddCommentToExistingUser.InstallProduct();
UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1");
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that a comment can be repaired for a new group
[RuntimeFact]
public void CanRepairCommentOfNewGroup()
{
var productNewUserWithComment = this.CreatePackageInstaller("ProductNewGroupWithComment");
productNewUserWithComment.InstallProduct();
UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "");
productNewUserWithComment.RepairProduct();
UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1");
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that a comment can be changed for an existing group
[RuntimeFact]
public void CanChangeCommentOfExistingGroup()
{
UserGroupVerifier.CreateLocalGroup("testName1");
UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "initialTestComment1");
var productNewUserWithComment = this.CreatePackageInstaller("ProductNewGroupWithComment");
productNewUserWithComment.InstallProduct();
UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "testComment1");
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that a comment can be rolled back for an existing group
[RuntimeFact]
public void CanRollbackCommentOfExistingGroup()
{
UserGroupVerifier.CreateLocalGroup("testName1");
UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "initialTestComment1");
var productCommentFail = this.CreatePackageInstaller("ProductCommentFail");
productCommentFail.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE);
// Verify that comment change was rolled back.
UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "initialTestComment1");
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that a comment can be deleted for an existing group
[RuntimeFact]
public void CanDeleteCommentOfExistingGroup()
{
UserGroupVerifier.CreateLocalGroup("testName1");
UserGroupVerifier.SetGroupComment(String.Empty, "testName1", "testComment1");
var productCommentDelete = this.CreatePackageInstaller("ProductCommentDelete");
productCommentDelete.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Verify that comment was removed.
UserGroupVerifier.VerifyGroupComment(String.Empty, "testName1", "");
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
}
// Verify that a comment can be deleted for an existing group
[RuntimeFact]
public void CanNestGroups()
{
var productNestedGroups = this.CreatePackageInstaller("ProductNestedGroups");
productNestedGroups.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
// Verify group nested membership
UserGroupVerifier.VerifyIsMemberOf(String.Empty, "Authenticated Users", new string[] { "testName1", "testName2" });
UserGroupVerifier.VerifyIsMemberOf(String.Empty, "Everyone", new string[] { "testName1" });
UserGroupVerifier.VerifyIsNotMemberOf(String.Empty, "Authenticated Users", new string[] { "testName3" });
UserGroupVerifier.VerifyIsNotMemberOf(String.Empty, "Everyone", new string[] { "testName2", "testName3" });
// clean up
UserGroupVerifier.DeleteLocalGroup("testName1");
UserGroupVerifier.DeleteLocalGroup("testName2");
UserGroupVerifier.DeleteLocalGroup("testName3");
}
}
}
|