forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloader.cpp
More file actions
70 lines (54 loc) · 2.32 KB
/
Copy pathDownloader.cpp
File metadata and controls
70 lines (54 loc) · 2.32 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include "AppInstallerDownloader.h"
#include "AppInstallerSHA256.h"
using namespace AppInstaller;
using namespace AppInstaller::Utility;
using namespace std::string_literals;
TEST_CASE("DownloadValidFileAndVerifyHash", "[Downloader]")
{
TestCommon::TempFile tempFile("downloader_test"s, ".test"s);
INFO("Using temporary file named: " << tempFile.GetPath());
// Todo: point to files from our repo when the repo goes public
ProgressCallback callback;
auto result = Download("https://raw.githubusercontent.com/microsoft/msix-packaging/master/LICENSE", tempFile.GetPath(), callback, true);
REQUIRE(result.has_value());
auto resultHash = result.value();
auto expectedHash = SHA256::ConvertToBytes("d2a45116709136462ee7a1c42f0e75f0efa258fe959b1504dc8ea4573451b759");
REQUIRE(std::equal(
expectedHash.begin(),
expectedHash.end(),
resultHash.begin()));
REQUIRE(std::filesystem::file_size(tempFile.GetPath()) > 0);
// Verify motw content
std::filesystem::path motwFile(tempFile);
motwFile += ":Zone.Identifier:$data";
std::ifstream motwStream(motwFile);
std::stringstream motwContent;
motwContent << motwStream.rdbuf();
std::string motwContentStr = motwContent.str();
REQUIRE(motwContentStr.find("ZoneId=3") != std::string::npos);
}
TEST_CASE("DownloadValidFileAndCancel", "[Downloader]")
{
TestCommon::TempFile tempFile("downloader_test"s, ".test"s);
INFO("Using temporary file named: " << tempFile.GetPath());
ProgressCallback callback;
std::optional<std::vector<BYTE>> waitResult;
std::thread waitThread([&]
{
waitResult = Download("https://aka.ms/win32-x64-user-stable", tempFile.GetPath(), callback, true);
});
callback.Cancel();
waitThread.join();
REQUIRE(!waitResult.has_value());
}
TEST_CASE("DownloadInvalidUrl", "[Downloader]")
{
TestCommon::TempFile tempFile("downloader_test"s, ".test"s);
INFO("Using temporary file named: " << tempFile.GetPath());
ProgressCallback callback;
REQUIRE_THROWS_HR(Download("blargle-flargle-fluff", tempFile.GetPath(), callback, true), WININET_E_UNRECOGNIZED_SCHEME);
}