Repository navigation
Expand file tree
/
Copy pathRestInterface_1_0.cpp
More file actions
2439 lines (2306 loc) · 111 KB
/
Copy pathRestInterface_1_0.cpp
File metadata and controls
2439 lines (2306 loc) · 111 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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include "TestRestRequestHandler.h"
#include <Rest/RestSource.h>
#include <Rest/Schema/1_0/Interface.h>
#include <Rest/Schema/1_4/Interface.h>
#include <Rest/Schema/1_28/Json/ManifestDeserializer.h>
#include <Rest/Schema/IRestClient.h>
#include <AppInstallerVersions.h>
#include <AppInstallerErrors.h>
#include <AppInstallerRuntime.h>
#include <winget/ManifestValidation.h>
#include <AppInstallerSHA256.h>
using namespace TestCommon;
using namespace AppInstaller::Http;
using namespace AppInstaller::Utility;
using namespace AppInstaller::Manifest;
using namespace AppInstaller::Repository;
using namespace AppInstaller::Repository::Rest;
using namespace AppInstaller::Repository::Rest::Schema;
using namespace AppInstaller::Repository::Rest::Schema::V1_0;
namespace
{
const std::string TestRestUriString = "http://restsource.com/api";
utility::string_t GetSearchResponse_PackageIds(
std::initializer_list<utility::string_t> identifiers, const utility::string_t& continuationToken = {})
{
web::json::value response;
response[L"Data"] = web::json::value::array();
size_t index = 0;
for (const auto& identifier : identifiers)
{
web::json::value package;
package[L"PackageIdentifier"] = web::json::value::string(identifier);
package[L"PackageName"] = web::json::value::string(L"Microsoft Teams");
package[L"Publisher"] = web::json::value::string(L"Microsoft");
package[L"Versions"][0][L"PackageVersion"] = web::json::value::string(L"1.0.0");
response[L"Data"][index++] = std::move(package);
}
if (!continuationToken.empty())
{
response[L"ContinuationToken"] = web::json::value::string(continuationToken);
}
return response.serialize();
}
struct CachedMetadataInterface : Interface
{
using Interface::Interface;
std::vector<IRestClient::VersionInfo> Versions;
protected:
IRestClient::SearchResult GetSearchResult(const web::json::value& response) const override
{
auto result = Interface::GetSearchResult(response);
result.Matches.at(0).Versions = Versions;
return result;
}
};
struct QueryValidationTrackingInterface : V1_1::Interface
{
using V1_1::Interface::Interface;
mutable size_t QueryValidations = 0;
protected:
std::map<std::string_view, std::string> GetValidatedQueryParams(const std::map<std::string_view, std::string>& params) const override
{
++QueryValidations;
return V1_1::Interface::GetValidatedQueryParams(params);
}
};
utility::string_t GetGoodManifest_RequiredFields()
{
return _XPLATSTR(
R"delimiter({
"Data": {
"PackageIdentifier": "Foo.Bar",
"Versions": [
{
"PackageVersion": "5.0.0",
"DefaultLocale": {
"PackageLocale": "en-us",
"Publisher": "Foo",
"PackageName": "Bar",
"License": "Foo bar license",
"ShortDescription": "Foo bar description"
},
"Installers": [
{
"Architecture": "x64",
"InstallerSha256": "011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6",
"InstallerType": "exe",
"InstallerUrl": "https://installer.example.com/foobar.exe"
}
]
}
]
}
})delimiter");
}
utility::string_t GetManifestsResponse_MultipleVersions()
{
return _XPLATSTR(
R"delimiter({
"Data": {
"PackageIdentifier": "Foo.Bar",
"Versions": [
{
"PackageVersion": "5.0.0",
"DefaultLocale": {
"PackageLocale": "en-us",
"Publisher": "Foo",
"PackageName": "Bar",
"License": "Foo bar license",
"ShortDescription": "Foo bar description"
},
"Installers": [
{
"Architecture": "x64",
"InstallerSha256": "011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6",
"InstallerType": "exe",
"InstallerUrl": "https://installer.example.com/foobar.exe"
}
]
},
{
"PackageVersion": "6.0.0",
"DefaultLocale": {
"PackageLocale": "en-us",
"Publisher": "Foo",
"PackageName": "Bar",
"License": "Foo bar license",
"ShortDescription": "Foo bar description"
},
"Installers": [
{
"Architecture": "x64",
"InstallerSha256": "011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6",
"InstallerType": "exe",
"InstallerUrl": "https://installer.example.com/foobar.exe"
}
]
}
]
}
})delimiter");
}
struct SearchAndManifestResponses
{
web::json::value SearchResponse = web::json::value::parse(GetSearchResponse_PackageIds({ L"Foo.Bar" }));
web::json::value ManifestResponse = web::json::value::parse(GetGoodManifest_RequiredFields());
web::http::status_code ManifestStatus = web::http::status_codes::OK;
size_t SearchRequests = 0;
size_t ManifestRequests = 0;
web::http::http_request LastSearchRequest;
web::http::http_request LastManifestRequest;
SearchAndManifestResponses()
{
ManifestResponse[L"Data"][L"Versions"][0][L"PackageVersion"] = web::json::value::string(L"1.0.0");
}
void SetManifestNotFound()
{
ManifestStatus = web::http::status_codes::NotFound;
ManifestResponse = web::json::value::parse(LR"({"code":"DataNotFound","message":"Not found"})");
}
std::shared_ptr<TestRestRequestHandler> GetHandler()
{
return std::make_shared<TestRestRequestHandler>(
[this](web::http::http_request request) -> pplx::task<web::http::http_response>
{
web::http::http_response response{ web::http::status_codes::BadRequest };
response.headers().set_content_type(web::http::details::mime_types::application_json);
response.headers().set_cache_control(L"no-store");
if (request.method() == web::http::methods::POST)
{
++SearchRequests;
LastSearchRequest = request;
response.set_status_code(web::http::status_codes::OK);
response.set_body(SearchResponse);
}
else if (request.method() == web::http::methods::GET)
{
++ManifestRequests;
LastManifestRequest = request;
response.set_status_code(ManifestStatus);
response.set_body(ManifestResponse);
}
return pplx::task_from_result(response);
});
}
};
struct GoodManifest_AllFields
{
utility::string_t GetSampleManifest_AllFields()
{
return _XPLATSTR(
R"delimiter(
{
"Data": {
"PackageIdentifier": "Foo.Bar",
"Versions": [
{
"PackageVersion": "3.0.0abc",
"DefaultLocale": {
"PackageLocale": "en-US",
"Publisher": "Foo",
"PublisherUrl": "http://publisher.net",
"PublisherSupportUrl": "http://publisherSupport.net",
"PrivacyUrl": "http://packagePrivacyUrl.net",
"Author": "FooBar",
"PackageName": "Bar",
"PackageUrl": "http://packageUrl.net",
"License": "Foo Bar License",
"LicenseUrl": "http://licenseUrl.net",
"Copyright": "Foo Bar Copyright",
"CopyrightUrl": "http://copyrightUrl.net",
"ShortDescription": "Foo bar is a foo bar.",
"Description": "Foo bar is a placeholder.",
"Tags": [
"FooBar",
"Foo",
"Bar"
],
"Moniker": "FooBarMoniker"
},
"Channel": "",
"Locales": [
{
"PackageLocale": "fr-Fr",
"Publisher": "Foo French",
"PublisherUrl": "http://publisher-fr.net",
"PublisherSupportUrl": "http://publisherSupport-fr.net",
"PrivacyUrl": "http://packagePrivacyUrl-fr.net",
"Author": "FooBar French",
"PackageName": "Bar",
"PackageUrl": "http://packageUrl-fr.net",
"License": "Foo Bar License",
"LicenseUrl": "http://licenseUrl-fr.net",
"Copyright": "Foo Bar Copyright",
"CopyrightUrl": "http://copyrightUrl-fr.net",
"ShortDescription": "Foo bar is a foo bar French.",
"Description": "Foo bar is a placeholder French.",
"Tags": [
"FooBarFr",
"FooFr",
"BarFr"
]
}
],
"Installers": [
{
"InstallerSha256": "011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6",
"InstallerUrl": "http://foobar.exe",
"Architecture": "x86",
"InstallerLocale": "en-US",
"Platform": [
"Windows.Desktop"
],
"MinimumOSVersion": "1078",
"InstallerType": "msix",
"Scope": "user",
"SignatureSha256": "011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6",
"InstallModes": [
"interactive"
],
"InstallerSwitches": {
"Silent": "/s",
"SilentWithProgress": "/s",
"Interactive": "/i",
"InstallLocation": "C:\\Users\\User1",
"Log": "/l",
"Upgrade": "/u",
"Custom": "/custom"
},
"InstallerSuccessCodes": [
0
],
"UpgradeBehavior": "install",
"Commands": [
"command1"
],
"Protocols": [
"protocol1"
],
"FileExtensions": [
".file-extension"
],
"Dependencies": {
"WindowsFeatures": [
"feature1"
],
"WindowsLibraries": [
"library1"
],
"PackageDependencies": [
{
"PackageIdentifier": "Foo.Baz",
"MinimumVersion": "2.0.0"
}
],
"ExternalDependencies": [
"FooBarBaz"
]
},
"PackageFamilyName": "FooBar.PackageFamilyName",
"ProductCode": "",
"Capabilities": [
"Bluetooth"
],
"RestrictedCapabilities": [
"restrictedCapability"
]
}
]
}
]
},
"ContinuationToken": "abcd"
})delimiter");
}
void VerifyLocalizations_AllFields(const Manifest& manifest)
{
REQUIRE(manifest.DefaultLocalization.Locale == "en-US");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Publisher>() == "Foo");
REQUIRE(manifest.DefaultLocalization.Get<Localization::PublisherUrl>() == "http://publisher.net");
REQUIRE(manifest.DefaultLocalization.Get<Localization::PublisherSupportUrl>() == "http://publisherSupport.net");
REQUIRE(manifest.DefaultLocalization.Get<Localization::PrivacyUrl>() == "http://packagePrivacyUrl.net");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Author>() == "FooBar");
REQUIRE(manifest.DefaultLocalization.Get<Localization::PackageName>() == "Bar");
REQUIRE(manifest.DefaultLocalization.Get<Localization::PackageUrl>() == "http://packageUrl.net");
REQUIRE(manifest.DefaultLocalization.Get<Localization::License>() == "Foo Bar License");
REQUIRE(manifest.DefaultLocalization.Get<Localization::LicenseUrl>() == "http://licenseUrl.net");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Copyright>() == "Foo Bar Copyright");
REQUIRE(manifest.DefaultLocalization.Get<Localization::CopyrightUrl>() == "http://copyrightUrl.net");
REQUIRE(manifest.DefaultLocalization.Get<Localization::ShortDescription>() == "Foo bar is a foo bar.");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Description>() == "Foo bar is a placeholder.");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Tags>().size() == 3);
REQUIRE(manifest.DefaultLocalization.Get<Localization::Tags>().at(0) == "FooBar");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Tags>().at(1) == "Foo");
REQUIRE(manifest.DefaultLocalization.Get<Localization::Tags>().at(2) == "Bar");
REQUIRE(manifest.Localizations.size() == 1);
ManifestLocalization frenchLocalization = manifest.Localizations.at(0);
REQUIRE(frenchLocalization.Locale == "fr-Fr");
REQUIRE(frenchLocalization.Get<Localization::Publisher>() == "Foo French");
REQUIRE(frenchLocalization.Get<Localization::PublisherUrl>() == "http://publisher-fr.net");
REQUIRE(frenchLocalization.Get<Localization::PublisherSupportUrl>() == "http://publisherSupport-fr.net");
REQUIRE(frenchLocalization.Get<Localization::PrivacyUrl>() == "http://packagePrivacyUrl-fr.net");
REQUIRE(frenchLocalization.Get<Localization::Author>() == "FooBar French");
REQUIRE(frenchLocalization.Get<Localization::PackageName>() == "Bar");
REQUIRE(frenchLocalization.Get<Localization::PackageUrl>() == "http://packageUrl-fr.net");
REQUIRE(frenchLocalization.Get<Localization::License>() == "Foo Bar License");
REQUIRE(frenchLocalization.Get<Localization::LicenseUrl>() == "http://licenseUrl-fr.net");
REQUIRE(frenchLocalization.Get<Localization::Copyright>() == "Foo Bar Copyright");
REQUIRE(frenchLocalization.Get<Localization::CopyrightUrl>() == "http://copyrightUrl-fr.net");
REQUIRE(frenchLocalization.Get<Localization::ShortDescription>() == "Foo bar is a foo bar French.");
REQUIRE(frenchLocalization.Get<Localization::Description>() == "Foo bar is a placeholder French.");
REQUIRE(frenchLocalization.Get<Localization::Tags>().size() == 3);
REQUIRE(frenchLocalization.Get<Localization::Tags>().at(0) == "FooBarFr");
REQUIRE(frenchLocalization.Get<Localization::Tags>().at(1) == "FooFr");
REQUIRE(frenchLocalization.Get<Localization::Tags>().at(2) == "BarFr");
}
void VerifyInstallers_AllFields(const Manifest& manifest)
{
REQUIRE(manifest.Installers.size() == 1);
ManifestInstaller actualInstaller = manifest.Installers.at(0);
REQUIRE(actualInstaller.Sha256 == AppInstaller::Utility::SHA256::ConvertToBytes("011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6"));
REQUIRE(actualInstaller.Url == "http://foobar.exe");
REQUIRE(actualInstaller.Arch == Architecture::X86);
REQUIRE(actualInstaller.Locale == "en-US");
REQUIRE(actualInstaller.Platform.size() == 1);
REQUIRE(actualInstaller.Platform[0] == PlatformEnum::Desktop);
REQUIRE(actualInstaller.MinOSVersion == "1078");
REQUIRE(actualInstaller.BaseInstallerType == InstallerTypeEnum::Msix);
REQUIRE(actualInstaller.Scope == ScopeEnum::User);
REQUIRE(actualInstaller.SignatureSha256 == AppInstaller::Utility::SHA256::ConvertToBytes("011048877dfaef109801b3f3ab2b60afc74f3fc4f7b3430e0c897f5da1df84b6"));
REQUIRE(actualInstaller.InstallModes.size() == 1);
REQUIRE(actualInstaller.InstallModes.at(0) == InstallModeEnum::Interactive);
REQUIRE(actualInstaller.Switches.size() == 7);
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::Silent) == "/s");
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::SilentWithProgress) == "/s");
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::Interactive) == "/i");
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::InstallLocation) == "C:\\Users\\User1");
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::Log) == "/l");
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::Update) == "/u");
REQUIRE(actualInstaller.Switches.at(InstallerSwitchType::Custom) == "/custom");
REQUIRE(actualInstaller.InstallerSuccessCodes.size() == 1);
REQUIRE(actualInstaller.InstallerSuccessCodes.at(0) == 0);
REQUIRE(actualInstaller.UpdateBehavior == UpdateBehaviorEnum::Install);
REQUIRE(actualInstaller.Commands.at(0) == "command1");
REQUIRE(actualInstaller.Protocols.at(0) == "protocol1");
REQUIRE(actualInstaller.FileExtensions.at(0) == ".file-extension");
REQUIRE(actualInstaller.Dependencies.HasExactDependency(DependencyType::WindowsFeature, "feature1"));
REQUIRE(actualInstaller.Dependencies.HasExactDependency(DependencyType::WindowsLibrary, "library1"));
REQUIRE(actualInstaller.Dependencies.HasExactDependency(DependencyType::Package, "Foo.Baz", "2.0.0"));
REQUIRE(actualInstaller.Dependencies.HasExactDependency(DependencyType::External, "FooBarBaz"));
REQUIRE(actualInstaller.PackageFamilyName == "FooBar.PackageFamilyName");
REQUIRE(actualInstaller.ProductCode == "");
REQUIRE(actualInstaller.Capabilities.at(0) == "Bluetooth");
REQUIRE(actualInstaller.RestrictedCapabilities.at(0) == "restrictedCapability");
}
};
}
TEST_CASE("Search_GoodResponse", "[RestSource][Interface_1_0]")
{
utility::string_t sample = _XPLATSTR(
R"delimiter({
"Data" : [
{
"PackageIdentifier": "git.package",
"PackageName": "package",
"Publisher": "git",
"Versions": [
{ "PackageVersion": "1.0.0" },
{ "PackageVersion": "2.0.0" }]
}]
})delimiter");
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1{ TestRestUriString, std::move(helper) };
Schema::IRestClient::SearchResult searchResponse = v1.Search({});
REQUIRE(searchResponse.Matches.size() == 1);
Schema::IRestClient::Package package = searchResponse.Matches.at(0);
REQUIRE(package.PackageInformation.PackageIdentifier.compare("git.package") == 0);
REQUIRE(package.PackageInformation.Publisher.compare("git") == 0);
REQUIRE(package.PackageInformation.PackageName.compare("package") == 0);
REQUIRE(package.Versions.size() == 2);
REQUIRE(package.Versions.at(0).VersionAndChannel.GetVersion().ToString().compare("1.0.0") == 0);
REQUIRE(package.Versions.at(1).VersionAndChannel.GetVersion().ToString().compare("2.0.0") == 0);
}
TEST_CASE("Search_GoodResponse_AllFields", "[RestSource][Interface_1_0]")
{
utility::string_t sample = _XPLATSTR(
R"delimiter({
"Data" : [
{
"PackageIdentifier": "git.package",
"PackageName": "package",
"Publisher": "git",
"Versions": [
{
"PackageVersion": "1.0.0",
"PackageFamilyNames" : [
"pfn1",
"pfn2",
"pfn2"
],
"ProductCodes" : [
"pc1",
"pc2"
]
}]
}]
})delimiter");
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1{ TestRestUriString, std::move(helper) };
Schema::IRestClient::SearchResult searchResponse = v1.Search({});
REQUIRE(searchResponse.Matches.size() == 1);
Schema::IRestClient::Package package = searchResponse.Matches.at(0);
REQUIRE(package.PackageInformation.PackageIdentifier.compare("git.package") == 0);
REQUIRE(package.PackageInformation.Publisher.compare("git") == 0);
REQUIRE(package.PackageInformation.PackageName.compare("package") == 0);
REQUIRE(package.Versions.size() == 1);
REQUIRE(package.Versions.at(0).VersionAndChannel.GetVersion().ToString().compare("1.0.0") == 0);
REQUIRE(package.Versions.at(0).PackageFamilyNames.size() == 2);
REQUIRE(package.Versions.at(0).PackageFamilyNames.at(0) == "pfn1");
REQUIRE(package.Versions.at(0).PackageFamilyNames.at(1) == "pfn2");
REQUIRE(package.Versions.at(0).ProductCodes.at(0) == "pc1");
REQUIRE(package.Versions.at(0).ProductCodes.at(1) == "pc2");
}
TEST_CASE("Search_GoodResponse_404AsEmpty", "[RestSource][Interface_1_0]")
{
utility::string_t notFoundResponse = _XPLATSTR(
R"delimiter({"code":"DataNotFound","data":[],"details":[],"innererror":{"code":"DataNotFound","data":[],"details":[],"message":"Product is not present","source":"StoreEdgeFD"},"message":"Product is not present","source":"StoreEdgeFD"})delimiter");
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::NotFound, std::move(notFoundResponse)) };
Interface v1{ TestRestUriString, std::move(helper) };
Schema::IRestClient::SearchResult searchResponse = v1.Search({});
REQUIRE(searchResponse.Matches.size() == 0);
}
TEST_CASE("Search_ExplicitIdFilters", "[RestSource][Interface_1_0]")
{
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK,
GetSearchResponse_PackageIds({ L"XP8BT8DW290MPQ", L"Microsoft.Teams", L"Microsoft.Teams.Preview" })) };
Interface v1{ TestRestUriString, helper };
SearchRequest request;
request.Filters.emplace_back(PackageMatchField::Name, MatchType::CaseInsensitive, "Microsoft Teams");
std::vector<std::string> expected{ "Microsoft.Teams" };
SECTION("Exact")
{
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Microsoft.Teams");
}
SECTION("Exact case mismatch")
{
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "microsoft.teams");
expected.clear();
}
SECTION("Case insensitive")
{
request.Filters.emplace_back(PackageMatchField::Id, MatchType::CaseInsensitive, "microsoft.teams");
}
SECTION("Starts with")
{
request.Filters.emplace_back(PackageMatchField::Id, MatchType::StartsWith, "microsoft.teams");
expected.emplace_back("Microsoft.Teams.Preview");
}
SECTION("Substring")
{
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Substring, "teams");
expected.emplace_back("Microsoft.Teams.Preview");
}
SECTION("All ID filters must match")
{
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Microsoft.Teams");
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Microsoft.Teams.Preview");
expected.clear();
}
SECTION("Query and inclusions cannot override a failed filter")
{
request.Query.emplace(MatchType::Substring, "Teams");
request.Inclusions.emplace_back(PackageMatchField::Name, MatchType::Exact, "Microsoft Teams");
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Other.Package");
expected.clear();
}
auto result = v1.Search(request);
REQUIRE(result.Matches.size() == expected.size());
REQUIRE_FALSE(result.Truncated);
for (size_t i = 0; i < expected.size(); ++i)
{
REQUIRE(result.Matches[i].PackageInformation.PackageIdentifier == expected[i]);
}
}
TEST_CASE("Search_ExplicitIdFilters_UnicodePrefix", "[RestSource][Interface_1_0]")
{
std::wstring id = GENERATE(L"Vendor.\u1E9EApp", L"Vendor.\u00DFApp", L"Vendor.SSApp");
std::string prefix = GENERATE(u8"vendor.\u00DF", u8"vendor.\u1E9E", "vendor.ss");
CAPTURE(id, prefix);
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK,
GetSearchResponse_PackageIds({ L"Vendor.Other", id })) };
Interface v1{ TestRestUriString, helper };
SearchRequest request;
request.Filters.emplace_back(PackageMatchField::Id, MatchType::StartsWith, prefix);
request.MaximumResults = 1;
auto result = v1.Search(request);
REQUIRE(result.Matches.size() == 1);
REQUIRE(result.Matches[0].PackageInformation.PackageIdentifier == ConvertToUTF8(id));
REQUIRE_FALSE(result.Truncated);
}
TEST_CASE("Search_IdInclusions", "[RestSource][Interface_1_0]")
{
SearchAndManifestResponses responses;
responses.SearchResponse = web::json::value::parse(GetSearchResponse_PackageIds({ L"Foo.Bar", L"Foo.Baz", L"Other.Package" }));
responses.SetManifestNotFound();
HttpClientHelper helper{ responses.GetHandler() };
Interface v1{ TestRestUriString, helper };
SearchRequest request;
request.Inclusions.emplace_back(PackageMatchField::Id, MatchType::Exact, "Foo.Bar");
const std::vector<std::string> allIds{ "Foo.Bar", "Foo.Baz", "Other.Package" };
std::vector<std::string> expected{ "Foo.Bar" };
size_t expectedManifestRequests = 0;
SECTION("Matching inclusion") {}
SECTION("Any inclusion may match")
{
request.Inclusions.emplace_back(PackageMatchField::Id, MatchType::Exact, "Other.Package");
expected.emplace_back("Other.Package");
}
SECTION("No matching inclusion")
{
request.Inclusions[0].Value = "Missing.Package";
expected.clear();
}
SECTION("Filters narrow matching inclusions")
{
request.Inclusions.emplace_back(PackageMatchField::Id, MatchType::Exact, "Other.Package");
request.Filters.emplace_back(PackageMatchField::Id, MatchType::StartsWith, "Foo.");
}
SECTION("Matching filters cannot override failed inclusions")
{
request.Inclusions[0].Value = "Missing.Package";
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Foo.Bar");
expected.clear();
}
SECTION("Unknown inclusion preserves candidates")
{
request.Inclusions.emplace_back(PackageMatchField::Name, MatchType::Exact, "Localized name");
expected = allIds;
expectedManifestRequests = 2;
}
SECTION("Unknown filter does not disable inclusion matching")
{
request.Filters.emplace_back(PackageMatchField::Name, MatchType::Exact, "Localized name");
expectedManifestRequests = 1;
}
SECTION("A query may select independently of inclusions")
{
request.Query.emplace(MatchType::Substring, "Source-defined query");
expected = allIds;
}
SECTION("Unsupported match types remain unknown")
{
request.Inclusions[0].Type = GENERATE(MatchType::Fuzzy, MatchType::FuzzySubstring, MatchType::Wildcard);
expected = allIds;
}
auto result = v1.Search(request);
REQUIRE(responses.SearchRequests == 1);
REQUIRE(responses.ManifestRequests == expectedManifestRequests);
REQUIRE(result.Matches.size() == expected.size());
REQUIRE_FALSE(result.Truncated);
for (size_t i = 0; i < expected.size(); ++i)
{
REQUIRE(result.Matches[i].PackageInformation.PackageIdentifier == expected[i]);
}
}
TEST_CASE("Search_CachedManifestMetadata", "[RestSource][Interface_1_0]")
{
auto field = GENERATE(PackageMatchField::Name, PackageMatchField::Moniker, PackageMatchField::Tag,
PackageMatchField::Command, PackageMatchField::PackageFamilyName, PackageMatchField::ProductCode,
PackageMatchField::UpgradeCode);
bool useInclusions = GENERATE(false, true);
CAPTURE(ToString(field), useInclusions);
SearchAndManifestResponses responses;
responses.SetManifestNotFound();
HttpClientHelper helper{ responses.GetHandler() };
CachedMetadataInterface v1{ TestRestUriString, helper };
auto createManifest = [](std::string_view version, const NormalizedString& value)
{
Manifest manifest;
manifest.Id = "Foo.Bar";
manifest.Version = version;
manifest.Moniker = value;
manifest.DefaultLocalization.Add<Localization::PackageName>(value);
manifest.DefaultLocalization.Add<Localization::Tags>({ value });
auto& installer = manifest.Installers.emplace_back();
installer.Commands.emplace_back(value);
installer.PackageFamilyName = value;
installer.ProductCode = value;
installer.AppsAndFeaturesEntries.emplace_back().UpgradeCode = value;
return manifest;
};
v1.Versions.emplace_back(VersionAndChannel{ Version{ "1.0.0" }, Channel{} }, createManifest("1.0.0", "Other"));
v1.Versions.emplace_back(VersionAndChannel{ Version{ "2.0.0" }, Channel{} }, createManifest("2.0.0", "Other"));
SearchRequest request;
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Foo.Bar");
auto& criteria = useInclusions ? request.Inclusions : request.Filters;
criteria.emplace_back(field, MatchType::Exact, "Match");
size_t expectedCount = 0;
size_t expectedManifestRequests = 0;
SECTION("All cached versions mismatch") {}
SECTION("An earlier cached version matches")
{
v1.Versions[0].Manifest = createManifest("1.0.0", "Match");
expectedCount = 1;
}
SECTION("A later cached version matches")
{
v1.Versions[1].Manifest = createManifest("2.0.0", "Match");
expectedCount = 1;
}
SECTION("An uncached version preserves unknown")
{
v1.Versions[0].Manifest.reset();
expectedCount = 1;
expectedManifestRequests = 1;
}
SECTION("A match alongside an uncached version is retained")
{
v1.Versions[0].Manifest.reset();
v1.Versions[1].Manifest = createManifest("2.0.0", "Match");
expectedCount = 1;
}
SECTION("Missing manifests remain unknown")
{
v1.Versions[0].Manifest.reset();
v1.Versions[1].Manifest.reset();
expectedCount = 1;
expectedManifestRequests = 1;
}
SECTION("Unsupported comparisons remain unknown")
{
criteria.back().Type = GENERATE(MatchType::Fuzzy, MatchType::FuzzySubstring, MatchType::Wildcard);
expectedCount = 1;
}
SECTION("A query can select independently but cannot bypass filters")
{
request.Query.emplace(MatchType::Substring, "Source-defined query");
expectedCount = useInclusions ? size_t{ 1 } : size_t{ 0 };
}
SECTION("An ID mismatch still rejects matching metadata")
{
request.Filters[0].Value = "Other.Package";
v1.Versions[1].Manifest = createManifest("2.0.0", "Match");
}
auto result = v1.Search(request);
REQUIRE(result.Matches.size() == expectedCount);
REQUIRE(responses.SearchRequests == 1);
REQUIRE(responses.ManifestRequests == expectedManifestRequests);
REQUIRE_FALSE(result.Truncated);
}
TEST_CASE("Search_ReturnedMetadata", "[RestSource][Interface_1_0]")
{
auto field = GENERATE(PackageMatchField::Name, PackageMatchField::PackageFamilyName,
PackageMatchField::ProductCode, PackageMatchField::UpgradeCode);
auto type = GENERATE(MatchType::Exact, MatchType::CaseInsensitive);
CAPTURE(ToString(field), ToString(type));
SearchAndManifestResponses responses;
responses.SetManifestNotFound();
HttpClientHelper helper{ responses.GetHandler() };
CachedMetadataInterface v1{ TestRestUriString, helper };
Manifest manifest;
manifest.Id = "Foo.Bar";
manifest.Version = "1.0.0";
manifest.DefaultLocalization.Add<Localization::PackageName>("Other");
v1.Versions.emplace_back(VersionAndChannel{ manifest.Version, manifest.Channel }, manifest);
auto setReturnedValue = [&](std::string_view value)
{
switch (field)
{
case PackageMatchField::Name:
responses.SearchResponse[L"Data"][0][L"PackageName"] = web::json::value::string(ConvertToUTF16(value));
break;
case PackageMatchField::PackageFamilyName:
v1.Versions[0].PackageFamilyNames = { std::string{ value } };
break;
case PackageMatchField::ProductCode:
v1.Versions[0].ProductCodes = { std::string{ value } };
break;
case PackageMatchField::UpgradeCode:
v1.Versions[0].UpgradeCodes = { std::string{ value } };
break;
}
};
setReturnedValue("Match");
SearchRequest request;
request.Filters.emplace_back(field, type, "Match");
size_t expectedCount = 1;
size_t expectedManifestRequests = 0;
SECTION("Returned metadata confirms a match despite cached metadata") {}
SECTION("Case differences follow field-specific rules")
{
request.Filters[0].Value = "match";
if (field == PackageMatchField::Name && type == MatchType::Exact)
{
expectedCount = 0;
}
}
SECTION("Nonmatching response metadata is inconclusive without a manifest")
{
setReturnedValue("Other");
v1.Versions[0].Manifest.reset();
expectedManifestRequests = 1;
}
auto result = v1.Search(request);
REQUIRE(result.Matches.size() == expectedCount);
REQUIRE(responses.SearchRequests == 1);
REQUIRE(responses.ManifestRequests == expectedManifestRequests);
REQUIRE_FALSE(result.Truncated);
}
TEST_CASE("Search_ManifestResolution_Fields", "[RestSource][Interface_1_4]")
{
auto field = GENERATE(PackageMatchField::Name, PackageMatchField::Moniker, PackageMatchField::Tag,
PackageMatchField::Command, PackageMatchField::PackageFamilyName, PackageMatchField::ProductCode,
PackageMatchField::UpgradeCode);
bool useInclusions = GENERATE(false, true);
CAPTURE(ToString(field), useInclusions);
SearchAndManifestResponses responses;
auto& version = responses.ManifestResponse[L"Data"][L"Versions"][0];
std::string value = "Wanted";
switch (field)
{
case PackageMatchField::Name:
version[L"Locales"][0][L"PackageLocale"] = web::json::value::string(L"fr-FR");
version[L"Locales"][0][L"PackageName"] = web::json::value::string(L"Wanted");
break;
case PackageMatchField::Moniker:
version[L"DefaultLocale"][L"Moniker"] = web::json::value::string(L"Wanted");
break;
case PackageMatchField::Tag:
version[L"DefaultLocale"][L"Tags"][0] = web::json::value::string(L"Wanted");
break;
case PackageMatchField::Command:
version[L"Installers"][0][L"Commands"][0] = web::json::value::string(L"Wanted");
break;
case PackageMatchField::PackageFamilyName:
value = "Test.Package_8wekyb3d8bbwe";
version[L"Installers"][0][L"InstallerType"] = web::json::value::string(L"msix");
version[L"Installers"][0][L"PackageFamilyName"] = web::json::value::string(ConvertToUTF16(value));
break;
case PackageMatchField::ProductCode:
value = "{A0000000-0000-0000-0000-000000000001}";
version[L"Installers"][0][L"ProductCode"] = web::json::value::string(ConvertToUTF16(value));
break;
case PackageMatchField::UpgradeCode:
value = "{A0000000-0000-0000-0000-000000000002}";
version[L"Installers"][0][L"AppsAndFeaturesEntries"][0][L"UpgradeCode"] = web::json::value::string(ConvertToUTF16(value));
break;
}
size_t expectedCount = 1;
bool hasManifest = true;
SECTION("Retrieved metadata matches") {}
SECTION("Retrieved metadata rejects the candidate")
{
value = "Missing";
expectedCount = 0;
}
SECTION("Missing manifests preserve unknown")
{
responses.SetManifestNotFound();
hasManifest = false;
}
HttpClientHelper helper{ responses.GetHandler() };
V1_4::Interface rest{ TestRestUriString, helper, {} };
SearchRequest request;
auto& criteria = useInclusions ? request.Inclusions : request.Filters;
criteria.emplace_back(field, MatchType::Exact, value);
auto result = rest.Search(request);
REQUIRE(responses.SearchRequests == 1);
REQUIRE(responses.ManifestRequests == 1);
REQUIRE(responses.LastManifestRequest.absolute_uri().path() == L"/api/packageManifests/Foo.Bar");
REQUIRE(result.Matches.size() == expectedCount);
REQUIRE_FALSE(result.Truncated);
if (expectedCount)
{
REQUIRE(result.Matches[0].PackageInformation.PackageName ==
ConvertToUTF8(responses.SearchResponse[L"Data"][0][L"PackageName"].as_string()));
REQUIRE(result.Matches[0].Versions[0].Manifest.has_value() == hasManifest);
REQUIRE(result.Matches[0].Versions[0].VersionAndChannel.GetVersion().ToString() == "1.0.0");
}
}
TEST_CASE("Search_ManifestResolution_PositionalQuery", "[RestSource][Interface_1_0]")
{
std::string query = GENERATE("browser", ".");
bool matches = GENERATE(false, true);
bool unknownVersion = GENERATE(false, true);
CAPTURE(query, matches, unknownVersion);
SearchAndManifestResponses responses;
responses.SearchResponse[L"Data"][0][L"PackageName"] = web::json::value::string(L"Unrelated application");
if (unknownVersion)
{
responses.SearchResponse[L"Data"][0][L"Versions"][0][L"PackageVersion"] = web::json::value::string(L"Unknown");
}
if (matches)
{
responses.ManifestResponse[L"Data"][L"Versions"][0][L"DefaultLocale"][L"PackageName"] =
web::json::value::string(ConvertToUTF16(query));
}
HttpClientHelper helper{ responses.GetHandler() };
Interface rest{ TestRestUriString, helper };
SearchRequest request;
request.Inclusions.emplace_back(PackageMatchField::PackageFamilyName, MatchType::Exact, query);
request.Inclusions.emplace_back(PackageMatchField::ProductCode, MatchType::Exact, query);
request.Inclusions.emplace_back(PackageMatchField::Id, MatchType::CaseInsensitive, query);
request.Inclusions.emplace_back(PackageMatchField::Name, MatchType::CaseInsensitive, query);
request.Inclusions.emplace_back(PackageMatchField::Moniker, MatchType::CaseInsensitive, query);
auto result = rest.Search(request);
REQUIRE(responses.SearchRequests == 1);
REQUIRE(responses.ManifestRequests == 1);
REQUIRE(result.Matches.size() == (matches ? size_t{ 1 } : size_t{ 0 }));
if (matches)
{
REQUIRE(result.Matches[0].Versions[0].Manifest.has_value());
REQUIRE(result.Matches[0].Versions[0].VersionAndChannel.GetVersion().ToString() == "1.0.0");
}
}
TEST_CASE("Search_ManifestResolution_SkipsUnnecessaryLookups", "[RestSource][Interface_1_0]")
{
SearchAndManifestResponses responses;
responses.ManifestStatus = web::http::status_codes::ServiceUnavailable;
SearchRequest request;
size_t expectedCount = 1;
SECTION("No selectors") {}
SECTION("Generic query")
{
request.Query.emplace(MatchType::Substring, "browser");
}
SECTION("Generic query can select independently")
{
request.Query.emplace(MatchType::Substring, "browser");
request.Inclusions.emplace_back(PackageMatchField::Moniker, MatchType::Exact, "browser");
}
SECTION("Known inclusion matches after unknown inclusion")
{
request.Inclusions.emplace_back(PackageMatchField::Moniker, MatchType::Exact, "browser");
request.Inclusions.emplace_back(PackageMatchField::Id, MatchType::Exact, "Foo.Bar");
}
SECTION("Known filter fails after unknown filter")
{
request.Filters.emplace_back(PackageMatchField::Moniker, MatchType::Exact, "browser");
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Other.Package");
expectedCount = 0;
}
SECTION("Known inclusions fail despite unknown filter")
{
request.Filters.emplace_back(PackageMatchField::Moniker, MatchType::Exact, "browser");
request.Inclusions.emplace_back(PackageMatchField::Id, MatchType::Exact, "Other.Package");
expectedCount = 0;
}
SECTION("Unsupported comparison")
{
auto type = GENERATE(MatchType::Fuzzy, MatchType::FuzzySubstring, MatchType::Wildcard);
request.Filters.emplace_back(PackageMatchField::Name, type, "browser");
}
SECTION("Market remains unvalidated")
{
request.Filters.emplace_back(PackageMatchField::Market, MatchType::Exact, "value");
}
SECTION("Normalized pair remains unvalidated")
{
request.Purpose = GENERATE(SearchPurpose::Default, SearchPurpose::CorrelationToInstalled, SearchPurpose::CorrelationToAvailable);
bool useInclusions = GENERATE(false, true);
CAPTURE(request.Purpose, useInclusions);
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, "Foo.Bar");
auto& criteria = useInclusions ? request.Inclusions : request.Filters;
criteria.emplace_back(PackageMatchField::NormalizedNameAndPublisher, MatchType::Exact, "Other Name", "Other Publisher");
}
SECTION("Installed-package correlation")
{
request.Purpose = GENERATE(SearchPurpose::CorrelationToInstalled, SearchPurpose::CorrelationToAvailable);
request.Inclusions.emplace_back(PackageMatchField::ProductCode, MatchType::Exact, "Missing.Code");
}
SECTION("Returned name proves the filter")
{
request.Filters.emplace_back(PackageMatchField::Name, MatchType::Exact,
ConvertToUTF8(responses.SearchResponse[L"Data"][0][L"PackageName"].as_string()));
}
HttpClientHelper helper{ responses.GetHandler() };
Interface rest{ TestRestUriString, helper };
auto result = rest.Search(request);
REQUIRE(result.Matches.size() == expectedCount);
REQUIRE(responses.SearchRequests == 1);
REQUIRE(responses.ManifestRequests == 0);
}
TEST_CASE("Search_ManifestResolution_Errors", "[RestSource][Interface_1_1]")
{
SearchAndManifestResponses responses;
HRESULT expectedError = APPINSTALLER_CLI_ERROR_RESTSOURCE_INVALID_DATA;
SECTION("Mismatching package identifier")
{
responses.ManifestResponse[L"Data"][L"PackageIdentifier"] = web::json::value::string(L"Other.Package");
}
SECTION("Malformed manifest data")
{
responses.ManifestResponse[L"Data"][L"Versions"] = web::json::value::array();
}
SECTION("Invalid installer")
{
responses.ManifestResponse[L"Data"][L"Versions"][0][L"Installers"][0].as_object().erase(L"InstallerUrl");
}
SECTION("Access denied")
{
responses.ManifestStatus = web::http::status_codes::Unauthorized;
expectedError = HTTP_E_STATUS_DENIED;
}
SECTION("Service unavailable")
{
responses.ManifestStatus = web::http::status_codes::ServiceUnavailable;
expectedError = APPINSTALLER_CLI_ERROR_SERVICE_UNAVAILABLE;
}
SECTION("Unsupported request reported by the server")