Skip to content

Commit 1393ad8

Browse files
authored
Fix all download failures claiming that the download was disabled by x-block-origin. (#1513)
1 parent af3caca commit 1393ad8

File tree

4 files changed

+153
-29
lines changed

4 files changed

+153
-29
lines changed

azure-pipelines/end-to-end-tests-dir/asset-caching.ps1

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ $actual = $actual -replace "`r`n", "`n"
5757
$expected = @(
5858
"A suitable version of .* was not found \(required v[0-9\.]+\)."
5959
"Asset cache miss; downloading from .*"
60+
"Downloading .*"
61+
"Successfully downloaded .*."
6062
"Successfully stored .* to .*."
6163
) -join "`n"
6264

@@ -82,26 +84,116 @@ if (-not ($actual -match $expected)) {
8284
# Testing asset caching && x-block-orgin promises when --debug is passed (enabled)
8385
Refresh-TestRoot
8486
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("install", "vcpkg-internal-e2e-test-port", "--overlay-ports=$PSScriptRoot/../e2e-ports", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite;x-block-origin", "--downloads-root=$DownloadsRoot", "--debug"))
85-
$actual = $actual -replace "`r`n", "`n"
86-
87-
# Define the regex pattern that accounts for multiline input
88-
$expectedPattern = "(?s)" +
89-
".*\[DEBUG\] External asset downloads are blocked \(x-block-origin is enabled\)\.\.\.?" +
90-
".*\[DEBUG\] Asset caching is enabled\..*"
91-
92-
if (-not ($actual -match $expectedPattern)) {
87+
if (-not ($actual.Contains("[DEBUG] External asset downloads are blocked (x-block-origin is enabled)") -and $actual.Contains("[DEBUG] Asset caching is enabled."))) {
9388
throw "Failure: couldn't find expected debug promises (asset caching enabled + x-block-origin enabled)"
9489
}
9590

9691
# Testing asset caching && x-block-orgin promises when --debug is passed (disabled)
9792
Refresh-TestRoot
9893
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("install", "vcpkg-internal-e2e-test-port", "--overlay-ports=$PSScriptRoot/../e2e-ports", "--x-asset-sources=clear", "--downloads-root=$DownloadsRoot", "--debug"))
94+
if (-not ($actual.Contains("[DEBUG] External asset downloads are allowed (x-block-origin is disabled)") -and $actual.Contains("[DEBUG] Asset cache is not configured"))) {
95+
throw "Failure: couldn't find expected debug promises (asset caching disabled + x-block-origin disabled)"
96+
}
97+
98+
# azurl (no), x-block-origin (no), asset-cache (n/a), download (fail)
99+
# Expected: Download failure message, nothing about asset caching
100+
Refresh-TestRoot
101+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://localhost:1234/foobar.html"))
102+
if (-not ($actual.Contains("error: https://localhost:1234/foobar.html: curl failed to download with exit code 7"))) {
103+
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (fail)"
104+
}
105+
106+
#azurl (no), x-block-origin (no), asset-cache (n/a), download (sha-mismatch)
107+
#Expected: Download message with the "you might need to configure a proxy" message and with expected/actual sha
108+
Refresh-TestRoot
109+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b", "--url", "https://example.com"))
110+
if (-not ($actual.Contains("Failed to download example3.html.") -and
111+
$actual.Contains("If you are using a proxy, please ensure your proxy settings are correct.") -and
112+
$actual.Contains("error: File does not have the expected hash:") -and
113+
$actual.Contains("url: https://example.com") -and
114+
$actual.Contains("Expected hash: d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b") -and
115+
$actual.Contains("Actual hash: d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a"))) {
116+
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (sha-mismatch)"
117+
}
118+
119+
# azurl (no), x-block-origin (no), asset-cache (n/a), download (succeed)
120+
# Expected: Download success message, nothing about asset caching
121+
Refresh-TestRoot
122+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com"))
123+
if (-not ($actual.Contains("Downloading example3.html") -and
124+
$actual.Contains("Successfully downloaded example3.html."))) {
125+
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (succeed)"
126+
}
127+
128+
# azurl (no), x-block-origin (yes), asset-cache (n/a), download (n/a)
129+
# Expected: Download failure message, nothing about asset caching, x-block-origin complaint
130+
Refresh-TestRoot
131+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=clear;x-block-origin"))
132+
if (-not ($actual.Contains("error: Missing example3.html and downloads are blocked by x-block-origin."))) {
133+
throw "Failure: azurl (no), x-block-origin (yes), asset-cache (n/a), download (n/a)"
134+
}
135+
136+
# azurl (yes), x-block-origin (no), asset-cache (miss), download (fail)
137+
# Expected: Download failure message, asset cache named, nothing about x-block-origin
138+
Refresh-TestRoot
139+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://localhost:1234/foobar.html", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"))
140+
if (-not ($actual.Contains("Asset cache miss; downloading from https://localhost:1234/foobar.html") -and
141+
$actual.Contains("Downloading example3.html") -and
142+
$actual.Contains("error: file://$AssetCache") -and
143+
$actual.Contains("curl failed to download with exit code 37"))) {
144+
throw "Failure: azurl (yes), x-block-origin (no), asset-cache (miss), download (fail)"
145+
}
146+
147+
# azurl (yes), x-block-origin (no), asset-cache (hit), download (n/a)
148+
# Expected: Download success message, asset cache named, nothing about x-block-origin
149+
Refresh-TestRoot
99150
$actual = $actual -replace "`r`n", "`n"
151+
Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"))
152+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"))
153+
if (-not ($actual.Contains("Asset cache hit for example3.html; downloaded from: file://$AssetCache"))) {
154+
throw "Failure: azurl (yes), x-block-origin (no), asset-cache (hit), download (n/a)"
155+
}
156+
157+
# azurl (yes), x-block-origin (no), asset-cache (miss), download (sha-mismatch)
158+
# Expected: Download message with "you might need to configure a proxy" and expected/actual sha
159+
Refresh-TestRoot
160+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"))
161+
if (-not ($actual.Contains("Asset cache miss; downloading from https://example.com") -and
162+
$actual.Contains("Downloading example3.html") -and
163+
$actual.Contains("error: file://$AssetCache") -and
164+
$actual.Contains("curl failed to download with exit code 37") -and
165+
$actual.Contains("error: File does not have the expected hash:") -and
166+
$actual.Contains("url: https://example.com") -and
167+
$actual.Contains("Expected hash: d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b") -and
168+
$actual.Contains("Actual hash: d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a"))) {
169+
throw "Failure: azurl (yes), x-block-origin (no), asset-cache (miss), download (sha-mismatch)"
170+
}
100171

101-
$expectedPattern = "(?s)" +
102-
".*\[DEBUG\] External asset downloads are allowed \(x-block-origin is disabled\)\.\.\.?" +
103-
".*\[DEBUG\] Asset cache is not configured.*"
172+
# azurl (yes), x-block-origin (no), asset-cache (miss), download (succeed)
173+
# Expected: Download success message, asset cache upload, nothing about x-block-origin
174+
Refresh-TestRoot
175+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"))
176+
if (-not ($actual.Contains("Asset cache miss; downloading from https://example.com") -and
177+
$actual.Contains("Downloading example3.html") -and
178+
$actual.Contains("Successfully downloaded example3.html.") -and
179+
$actual.Contains("Successfully stored example3.html to file://$AssetCache"))) {
180+
throw "Failure: azurl (yes), x-block-origin (no), asset-cache (miss), download (succeed)"
181+
}
104182

105-
if (-not ($actual -match $expectedPattern)) {
106-
throw "Failure: couldn't find expected debug promises (asset caching disabled + x-block-origin disabled)"
183+
# azurl (yes), x-block-origin (yes), asset-cache (miss), download (n/a)
184+
# Expected: Download failure message, which asset cache was tried, x-block-origin complaint
185+
Refresh-TestRoot
186+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite;x-block-origin"))
187+
if (-not ($actual.Contains("Asset cache miss for example3.html and downloads are blocked by x-block-origin.") -and
188+
$actual.Contains("error: Missing example3.html and downloads are blocked by x-block-origin."))) {
189+
throw "Failure: azurl (yes), x-block-origin (yes), asset-cache (miss), download (n/a)"
190+
}
191+
192+
# azurl (yes), x-block-origin (yes), asset-cache (hit), download (n/a)
193+
# Expected: Download success message, asset cache named, nothing about x-block-origin
194+
Refresh-TestRoot
195+
Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"))
196+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://example.com", "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite;x-block-origin"))
197+
if (-not ($actual.Contains("Asset cache hit for example3.html; downloaded from: file://$AssetCache"))) {
198+
throw "Failure: azurl (yes), x-block-origin (yes), asset-cache (hit), download (n/a)"
107199
}

include/vcpkg/base/message-data.inc.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ DECLARE_MESSAGE(ArtifactsSwitchX86, (), "", "Forces host detection to x86 when a
248248
DECLARE_MESSAGE(ArtifactsSwitchWindows, (), "", "Forces host detection to Windows when acquiring artifacts")
249249
DECLARE_MESSAGE(AssetCacheHit, (msg::path, msg::url), "", "Asset cache hit for {path}; downloaded from: {url}")
250250
DECLARE_MESSAGE(AssetCacheMiss, (msg::url), "", "Asset cache miss; downloading from {url}")
251+
DECLARE_MESSAGE(AssetCacheMissBlockOrigin,
252+
(msg::path),
253+
"x-block-origin is a vcpkg term. Do not translate",
254+
"Asset cache miss for {path} and downloads are blocked by x-block-origin.")
255+
DECLARE_MESSAGE(DownloadSuccesful, (msg::path), "", "Successfully downloaded {path}.")
251256
DECLARE_MESSAGE(DownloadingUrl, (msg::url), "", "Downloading {url}")
252257
DECLARE_MESSAGE(AssetCacheProviderAcceptsNoArguments,
253258
(msg::value),
@@ -1046,6 +1051,22 @@ DECLARE_MESSAGE(DownloadFailedStatusCode,
10461051
(msg::url, msg::value),
10471052
"{value} is an HTTP status code",
10481053
"{url}: failed: status code {value}")
1054+
DECLARE_MESSAGE(DownloadFailedProxySettings,
1055+
(msg::path, msg::url),
1056+
"",
1057+
"Failed to download {path}.\nIf you are using a proxy, please ensure your proxy settings are "
1058+
"correct.\nPossible causes are:\n"
1059+
"1. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable "
1060+
"to `https//address:port`.\nThis is not correct, because `https://` prefix "
1061+
"claims the proxy is an HTTPS proxy, while your proxy (v2ray, shadowsocksr, etc...) is an HTTP proxy.\n"
1062+
"Try setting `http://address:port` to both HTTP_PROXY and HTTPS_PROXY instead.\n"
1063+
"2. If you are using Windows, vcpkg will automatically use your Windows IE Proxy Settings "
1064+
"set by your proxy software. See, {url}\n"
1065+
"The value set by your proxy might be wrong, or have same `https://` prefix issue.\n"
1066+
"3. Your proxy's remote server is our of service.\n"
1067+
"If you've tried directly download the link, and believe this is not a temporay download server "
1068+
"failure, please submit an issue at https://github.com/Microsoft/vcpkg/issues\n"
1069+
"to report this upstream download server failure.")
10491070
DECLARE_MESSAGE(DownloadingPortableToolVersionX,
10501071
(msg::tool_name, msg::version),
10511072
"",
@@ -1240,10 +1261,6 @@ DECLARE_MESSAGE(MissingShaVariable,
12401261
(),
12411262
"{{sha}} should not be translated",
12421263
"The {{sha}} variable must be used in the template if other variables are used.")
1243-
DECLARE_MESSAGE(AssetCacheMissBlockOrigin,
1244-
(msg::path),
1245-
"x-block-origin is a vcpkg term. Do not translate",
1246-
"Asset cache miss for {path} and downloads are blocked by x-block-origin.")
12471264
DECLARE_MESSAGE(FailedToExtract, (msg::path), "", "Failed to extract \"{path}\":")
12481265
DECLARE_MESSAGE(FailedToFetchRepo, (msg::url), "", "Failed to fetch {url}.")
12491266
DECLARE_MESSAGE(FailedToFindPortFeature,

locales/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,16 @@
595595
"_DownloadFailedCurl.comment": "An example of {url} is https://github.com/microsoft/vcpkg. An example of {exit_code} is 127.",
596596
"DownloadFailedHashMismatch": "File does not have the expected hash:\nurl: {url}\nFile: {path}\nExpected hash: {expected}\nActual hash: {actual}",
597597
"_DownloadFailedHashMismatch.comment": "{expected} and {actual} are SHA512 hashes in hex format. An example of {url} is https://github.com/microsoft/vcpkg. An example of {path} is /foo/bar.",
598+
"DownloadFailedProxySettings": "Failed to download {path}.\nIf you are using a proxy, please ensure your proxy settings are correct.\nPossible causes are:\n1. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable to `https//address:port`.\nThis is not correct, because `https://` prefix claims the proxy is an HTTPS proxy, while your proxy (v2ray, shadowsocksr, etc...) is an HTTP proxy.\nTry setting `http://address:port` to both HTTP_PROXY and HTTPS_PROXY instead.\n2. If you are using Windows, vcpkg will automatically use your Windows IE Proxy Settings set by your proxy software. See, {url}\nThe value set by your proxy might be wrong, or have same `https://` prefix issue.\n3. Your proxy's remote server is our of service.\nIf you've tried directly download the link, and believe this is not a temporay download server failure, please submit an issue at https://github.com/Microsoft/vcpkg/issues\nto report this upstream download server failure.",
599+
"_DownloadFailedProxySettings.comment": "An example of {path} is /foo/bar. An example of {url} is https://github.com/microsoft/vcpkg.",
598600
"DownloadFailedRetrying": "Download failed -- retrying after {value}ms",
599601
"_DownloadFailedRetrying.comment": "{value} is a number of milliseconds",
600602
"DownloadFailedStatusCode": "{url}: failed: status code {value}",
601603
"_DownloadFailedStatusCode.comment": "{value} is an HTTP status code An example of {url} is https://github.com/microsoft/vcpkg.",
602604
"DownloadRootsDir": "Downloads directory (default: {env_var})",
603605
"_DownloadRootsDir.comment": "An example of {env_var} is VCPKG_DEFAULT_TRIPLET.",
606+
"DownloadSuccesful": "Successfully downloaded {path}.",
607+
"_DownloadSuccesful.comment": "An example of {path} is /foo/bar.",
604608
"DownloadWinHttpError": "{url}: {system_api} failed with exit code {exit_code}",
605609
"_DownloadWinHttpError.comment": "An example of {system_api} is CreateProcessW. An example of {exit_code} is 127. An example of {url} is https://github.com/microsoft/vcpkg.",
606610
"DownloadedSources": "Downloaded sources for {spec}",

0 commit comments

Comments
 (0)