forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchCommand.cs
More file actions
216 lines (201 loc) · 9.55 KB
/
Copy pathSearchCommand.cs
File metadata and controls
216 lines (201 loc) · 9.55 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
// -----------------------------------------------------------------------------
// <copyright file="SearchCommand.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
namespace AppInstallerCLIE2ETests
{
using AppInstallerCLIE2ETests.Helpers;
using NUnit.Framework;
/// <summary>
/// Test search command.
/// </summary>
public class SearchCommand : BaseCommand
{
/// <summary>
/// Test search without args.
/// </summary>
[Test]
public void SearchWithoutArgs()
{
var result = TestCommon.RunAICLICommand("search", string.Empty);
Assert.AreEqual(Constants.ErrorCode.ERROR_INVALID_CL_ARGUMENTS, result.ExitCode);
}
/// <summary>
/// Test search with query.
/// </summary>
[Test]
public void SearchQuery()
{
var result = TestCommon.RunAICLICommand("search", "TestExampleInstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with alias.
/// </summary>
public void SearchUsingAlias()
{
var result = TestCommon.RunAICLICommand("find", "TestExampleInstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with name.
/// </summary>
[Test]
public void SearchWithName()
{
var result = TestCommon.RunAICLICommand("search", "--name testexampleinstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with Id.
/// </summary>
[Test]
public void SearchWithID()
{
var result = TestCommon.RunAICLICommand("search", "--id appinstallertest.testexampleinstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with invalid name.
/// </summary>
[Test]
public void SearchWithInvalidName()
{
var result = TestCommon.RunAICLICommand("search", "--name InvalidName");
Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode);
Assert.True(result.StdOut.Contains("No package found matching input criteria."));
}
/// <summary>
/// Test search where it returns multiple results.
/// </summary>
[Test]
public void SearchReturnsMultiple()
{
// Search Microsoft should return multiple
var result = TestCommon.RunAICLICommand("search", "AppInstallerTest");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExeInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestBurnInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with exact name.
/// </summary>
[Test]
public void SearchWithExactName()
{
var result = TestCommon.RunAICLICommand("search", "--exact TestExampleInstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with exact ID.
/// </summary>
[Test]
public void SearchWithExactID()
{
var result = TestCommon.RunAICLICommand("search", "--exact AppInstallerTest.TestExampleInstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
/// <summary>
/// Test search with exact case-sensitive.
/// </summary>
[Test]
public void SearchWithExactArgCaseSensitivity()
{
var result = TestCommon.RunAICLICommand("search", "--exact testexampleinstaller");
Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode);
Assert.True(result.StdOut.Contains("No package found matching input criteria."));
}
/// <summary>
/// Test search with a failed source.
/// </summary>
[Test]
public void SearchWithSingleSourceFailure()
{
TestCommon.RunAICLICommand("source add", "failSearch \"{ \"\"OpenHR\"\": \"\"0x80070002\"\" }\" Microsoft.Test.Configurable --header \"{}\"");
try
{
var result = TestCommon.RunAICLICommand("search", "--exact AppInstallerTest.TestExampleInstaller");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Failed when searching source; results will not be included: failSearch"));
Assert.True(result.StdOut.Contains("TestExampleInstaller"));
Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
}
finally
{
this.ResetTestSource();
}
}
/// <summary>
/// Test search with bad pin.
/// </summary>
[Test]
public void SearchStoreWithBadPin()
{
// Configure as close as possible to the real chain but use the test cert for everything
// This will at least force the public key to be checked rather than simply failing based on chain length
GroupPolicyHelper.EnableAdditionalSources.SetEnabledList(new GroupPolicyHelper.GroupPolicySource[]
{
new GroupPolicyHelper.GroupPolicySource
{
Name = Constants.TestAlternateSourceName,
Arg = Constants.DefaultMSStoreSourceUrl,
Type = Constants.DefaultMSStoreSourceType,
Data = string.Empty,
Identifier = Constants.DefaultMSStoreSourceIdentifier,
CertificatePinning = new GroupPolicyHelper.GroupPolicyCertificatePinning
{
Chains = new GroupPolicyHelper.GroupPolicyCertificatePinningChain[]
{
new GroupPolicyHelper.GroupPolicyCertificatePinningChain
{
Chain = new GroupPolicyHelper.GroupPolicyCertificatePinningDetails[]
{
new GroupPolicyHelper.GroupPolicyCertificatePinningDetails
{
Validation = new string[] { "publickey" },
EmbeddedCertificate = TestCommon.GetTestServerCertificateHexString(),
},
new GroupPolicyHelper.GroupPolicyCertificatePinningDetails
{
Validation = new string[] { "subject", "issuer" },
EmbeddedCertificate = TestCommon.GetTestServerCertificateHexString(),
},
new GroupPolicyHelper.GroupPolicyCertificatePinningDetails
{
Validation = new string[] { "subject", "issuer" },
EmbeddedCertificate = TestCommon.GetTestServerCertificateHexString(),
},
},
},
},
},
TrustLevel = new string[] { "None" },
Explicit = false,
},
});
try
{
var result = TestCommon.RunAICLICommand("search", $"-s {Constants.TestAlternateSourceName} foo --verbose-logs");
Assert.AreEqual(Constants.ErrorCode.ERROR_PINNED_CERTIFICATE_MISMATCH, result.ExitCode);
}
finally
{
this.ResetTestSource();
}
}
}
}