forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstallCommand.cs
More file actions
220 lines (194 loc) · 10.8 KB
/
Copy pathUninstallCommand.cs
File metadata and controls
220 lines (194 loc) · 10.8 KB
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
// -----------------------------------------------------------------------------
// <copyright file="UninstallCommand.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
namespace AppInstallerCLIE2ETests
{
using System.IO;
using AppInstallerCLIE2ETests.Helpers;
using NUnit.Framework;
/// <summary>
/// Test uninstall command.
/// </summary>
public class UninstallCommand : BaseCommand
{
// Custom product code for overriding the default in the test exe
private const string CustomProductCode = "{f08fc03c-0b7e-4fca-9b3c-3a384d18a9f3}";
// File written when uninstalling the test exe
private const string UninstallTestExeUninstalledFile = "TestExeUninstalled.txt";
// Name of a file installed by the MSI that will be removed during uninstall
private const string UninstallTestMsiInstalledFile = "AppInstallerTestExeInstaller.exe";
// Package name of the test MSIX package
private const string UninstallTestMsixName = "6c6338fe-41b7-46ca-8ba6-b5ad5312bb0e";
/// <summary>
/// Test uninstall exe.
/// </summary>
[Test]
public void UninstallTestExe()
{
// Uninstall an Exe
var installDir = TestCommon.GetRandomTestDir();
TestCommon.RunAICLICommand("install", $"{Constants.ExeInstallerPackageId} --silent -l {installDir}");
var result = TestCommon.RunAICLICommand("uninstall", Constants.ExeInstallerPackageId);
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
Assert.True(TestCommon.VerifyTestExeUninstalled(installDir));
}
/// <summary>
/// Test uninstall msi.
/// </summary>
[Test]
public void UninstallTestMsi()
{
if (string.IsNullOrEmpty(TestIndex.MsiInstaller))
{
Assert.Ignore("MSI installer not available");
}
// Uninstall an MSI
var installDir = TestCommon.GetRandomTestDir();
TestCommon.RunAICLICommand("install", $"{Constants.MsiInstallerPackageId} -l {installDir}");
var result = TestCommon.RunAICLICommand("uninstall", Constants.MsiInstallerPackageId);
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
Assert.True(TestCommon.VerifyTestMsiUninstalled(installDir));
}
/// <summary>
/// Test uninstall msix.
/// </summary>
[Test]
public void UninstallTestMsix()
{
// Uninstall an MSIX
TestCommon.RunAICLICommand("install", Constants.MsixInstallerPackageId);
var result = TestCommon.RunAICLICommand("uninstall", Constants.MsixInstallerPackageId);
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
Assert.True(TestCommon.VerifyTestMsixUninstalled());
}
/// <summary>
/// Test uninstall msix package with machine scope.
/// </summary>
[Test]
public void UninstallTestMsixMachineScope()
{
// TODO: Provision and Deprovision api not supported in build server.
Assert.Ignore();
// Uninstall an MSIX
TestCommon.RunAICLICommand("install", $"{Constants.MsixInstallerPackageId} --scope machine");
var result = TestCommon.RunAICLICommand("uninstall", $"{Constants.MsixInstallerPackageId} --scope machine");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
Assert.True(TestCommon.VerifyTestMsixUninstalled(true));
}
/// <summary>
/// Test uninstall portable package.
/// </summary>
[Test]
public void UninstallPortable()
{
// Uninstall a Portable
string installDir = Path.Combine(System.Environment.GetEnvironmentVariable("LocalAppData"), "Microsoft", "WinGet", "Packages");
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
TestCommon.RunAICLICommand("install", $"{packageId}");
var result = TestCommon.RunAICLICommand("uninstall", $"{packageId}");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, false);
}
/// <summary>
/// Test uninstall portable package with product code.
/// </summary>
[Test]
public void UninstallPortableWithProductCode()
{
// Uninstall a Portable with ProductCode
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
TestCommon.RunAICLICommand("install", $"{packageId}");
var result = TestCommon.RunAICLICommand("uninstall", $"--product-code {productCode}");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, false);
}
/// <summary>
/// Test uninstall portable package with modified symlink.
/// </summary>
[Test]
public void UninstallPortableModifiedSymlink()
{
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
TestCommon.RunAICLICommand("install", $"{packageId}");
string symlinkDirectory = TestCommon.GetPortableSymlinkDirectory(TestCommon.Scope.User);
string symlinkPath = Path.Combine(symlinkDirectory, commandAlias);
// Replace symlink with modified symlink
File.Delete(symlinkPath);
FileSystemInfo modifiedSymlinkInfo = File.CreateSymbolicLink(symlinkPath, "fakeTargetExe");
var result = TestCommon.RunAICLICommand("uninstall", $"{packageId}");
Assert.AreEqual(Constants.ErrorCode.ERROR_PORTABLE_UNINSTALL_FAILED, result.ExitCode);
Assert.True(result.StdOut.Contains("Unable to remove Portable package as it has been modified; to override this check use --force"));
Assert.True(modifiedSymlinkInfo.Exists, "Modified symlink should still exist");
// Try again with --force
var result2 = TestCommon.RunAICLICommand("uninstall", $"{packageId} --force");
Assert.AreEqual(Constants.ErrorCode.S_OK, result2.ExitCode);
Assert.True(result2.StdOut.Contains("Portable package has been modified; proceeding due to --force"));
Assert.True(result2.StdOut.Contains("Successfully uninstalled"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, false);
}
/// <summary>
/// Test uninstall zip portable package.
/// </summary>
[Test]
public void UninstallZip_Portable()
{
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestZipInstallerWithPortable";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = "TestPortable.exe";
fileName = "AppInstallerTestExeInstaller.exe";
var testResult = TestCommon.RunAICLICommand("install", $"{packageId}");
var result = TestCommon.RunAICLICommand("uninstall", $"{packageId}");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, false);
}
/// <summary>
/// Test uninstall not indexed.
/// </summary>
[Test]
public void UninstallNotIndexed()
{
// Uninstalls a package found with ARP not matching any known manifest.
// Install the test EXE providing a custom Product Code so that it cannot be mapped
// back to its manifest, then uninstall it using its Product Code
var installDir = TestCommon.GetRandomTestDir();
TestCommon.RunAICLICommand("install", $"{Constants.ExeInstallerPackageId} --override \"/ProductID {CustomProductCode} /InstallDir {installDir}");
var result = TestCommon.RunAICLICommand("uninstall", CustomProductCode);
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully uninstalled"));
Assert.True(TestCommon.VerifyTestExeUninstalled(installDir));
}
/// <summary>
/// Test uninstalled app not found.
/// </summary>
[Test]
public void UninstallAppNotInstalled()
{
// Verify failure when trying to uninstall an app that is not installed.
var result = TestCommon.RunAICLICommand("uninstall", $"TestMsixInstaller");
Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode);
Assert.True(result.StdOut.Contains("No installed package found matching input criteria."));
}
}
}