SearchCommand.cs (9780B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="SearchCommand.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace AppInstallerCLIE2ETests 8 { 9 using AppInstallerCLIE2ETests.Helpers; 10 using NUnit.Framework; 11 12 /// <summary> 13 /// Test search command. 14 /// </summary> 15 public class SearchCommand : BaseCommand 16 { 17 /// <summary> 18 /// Test search without args. 19 /// </summary> 20 [Test] 21 public void SearchWithoutArgs() 22 { 23 var result = TestCommon.RunAICLICommand("search", string.Empty); 24 Assert.AreEqual(Constants.ErrorCode.ERROR_INVALID_CL_ARGUMENTS, result.ExitCode); 25 } 26 27 /// <summary> 28 /// Test search with query. 29 /// </summary> 30 [Test] 31 public void SearchQuery() 32 { 33 var result = TestCommon.RunAICLICommand("search", "TestExampleInstaller"); 34 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 35 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 36 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 37 } 38 39 /// <summary> 40 /// Test search with alias. 41 /// </summary> 42 public void SearchUsingAlias() 43 { 44 var result = TestCommon.RunAICLICommand("find", "TestExampleInstaller"); 45 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 46 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 47 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 48 } 49 50 /// <summary> 51 /// Test search with name. 52 /// </summary> 53 [Test] 54 public void SearchWithName() 55 { 56 var result = TestCommon.RunAICLICommand("search", "--name testexampleinstaller"); 57 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 58 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 59 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 60 } 61 62 /// <summary> 63 /// Test search with Id. 64 /// </summary> 65 [Test] 66 public void SearchWithID() 67 { 68 var result = TestCommon.RunAICLICommand("search", "--id appinstallertest.testexampleinstaller"); 69 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 70 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 71 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 72 } 73 74 /// <summary> 75 /// Test search with invalid name. 76 /// </summary> 77 [Test] 78 public void SearchWithInvalidName() 79 { 80 var result = TestCommon.RunAICLICommand("search", "--name InvalidName"); 81 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 82 Assert.True(result.StdOut.Contains("No package found matching input criteria.")); 83 } 84 85 /// <summary> 86 /// Test search where it returns multiple results. 87 /// </summary> 88 [Test] 89 public void SearchReturnsMultiple() 90 { 91 // Search Microsoft should return multiple 92 var result = TestCommon.RunAICLICommand("search", "AppInstallerTest"); 93 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 94 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExeInstaller")); 95 Assert.True(result.StdOut.Contains("AppInstallerTest.TestBurnInstaller")); 96 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 97 } 98 99 /// <summary> 100 /// Test search with exact name. 101 /// </summary> 102 [Test] 103 public void SearchWithExactName() 104 { 105 var result = TestCommon.RunAICLICommand("search", "--exact TestExampleInstaller"); 106 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 107 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 108 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 109 } 110 111 /// <summary> 112 /// Test search with exact ID. 113 /// </summary> 114 [Test] 115 public void SearchWithExactID() 116 { 117 var result = TestCommon.RunAICLICommand("search", "--exact AppInstallerTest.TestExampleInstaller"); 118 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 119 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 120 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 121 } 122 123 /// <summary> 124 /// Test search with exact case-sensitive. 125 /// </summary> 126 [Test] 127 public void SearchWithExactArgCaseSensitivity() 128 { 129 var result = TestCommon.RunAICLICommand("search", "--exact testexampleinstaller"); 130 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 131 Assert.True(result.StdOut.Contains("No package found matching input criteria.")); 132 } 133 134 /// <summary> 135 /// Test search with a failed source. 136 /// </summary> 137 [Test] 138 public void SearchWithSingleSourceFailure() 139 { 140 TestCommon.RunAICLICommand("source add", "failSearch \"{ \"\"OpenHR\"\": \"\"0x80070002\"\" }\" Microsoft.Test.Configurable --header \"{}\""); 141 142 try 143 { 144 var result = TestCommon.RunAICLICommand("search", "--exact AppInstallerTest.TestExampleInstaller"); 145 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 146 Assert.True(result.StdOut.Contains("Failed when searching source; results will not be included: failSearch")); 147 Assert.True(result.StdOut.Contains("TestExampleInstaller")); 148 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExampleInstaller")); 149 } 150 finally 151 { 152 this.ResetTestSource(); 153 } 154 } 155 156 /// <summary> 157 /// Test search with bad pin. 158 /// </summary> 159 [Test] 160 public void SearchStoreWithBadPin() 161 { 162 // Configure as close as possible to the real chain but use the test cert for everything 163 // This will at least force the public key to be checked rather than simply failing based on chain length 164 GroupPolicyHelper.EnableAdditionalSources.SetEnabledList(new GroupPolicyHelper.GroupPolicySource[] 165 { 166 new GroupPolicyHelper.GroupPolicySource 167 { 168 Name = Constants.TestAlternateSourceName, 169 Arg = Constants.DefaultMSStoreSourceUrl, 170 Type = Constants.DefaultMSStoreSourceType, 171 Data = string.Empty, 172 Identifier = Constants.DefaultMSStoreSourceIdentifier, 173 CertificatePinning = new GroupPolicyHelper.GroupPolicyCertificatePinning 174 { 175 Chains = new GroupPolicyHelper.GroupPolicyCertificatePinningChain[] 176 { 177 new GroupPolicyHelper.GroupPolicyCertificatePinningChain 178 { 179 Chain = new GroupPolicyHelper.GroupPolicyCertificatePinningDetails[] 180 { 181 new GroupPolicyHelper.GroupPolicyCertificatePinningDetails 182 { 183 Validation = new string[] { "publickey" }, 184 EmbeddedCertificate = TestCommon.GetTestServerCertificateHexString(), 185 }, 186 new GroupPolicyHelper.GroupPolicyCertificatePinningDetails 187 { 188 Validation = new string[] { "subject", "issuer" }, 189 EmbeddedCertificate = TestCommon.GetTestServerCertificateHexString(), 190 }, 191 new GroupPolicyHelper.GroupPolicyCertificatePinningDetails 192 { 193 Validation = new string[] { "subject", "issuer" }, 194 EmbeddedCertificate = TestCommon.GetTestServerCertificateHexString(), 195 }, 196 }, 197 }, 198 }, 199 }, 200 TrustLevel = new string[] { "None" }, 201 Explicit = false, 202 }, 203 }); 204 205 try 206 { 207 var result = TestCommon.RunAICLICommand("search", $"-s {Constants.TestAlternateSourceName} foo --verbose-logs"); 208 Assert.AreEqual(Constants.ErrorCode.ERROR_PINNED_CERTIFICATE_MISMATCH, result.ExitCode); 209 } 210 finally 211 { 212 this.ResetTestSource(); 213 } 214 } 215 } 216 }