Skip to content

Commit f8052c7

Browse files
authored
Transform SHA512s to lowercase for azurl. (#1574)
Same as #1564 but for azurl as well.
1 parent 89068dd commit f8052c7

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ $expected = @(
137137
"$"
138138
) -join "`n"
139139

140-
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a", "--url", "https://localhost:1234/foobar.html", "--url", "https://localhost:1235/baz.html"))
140+
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--sha512", "D06B93C883F8126A04589937A884032DF031B05518EED9D433EFB6447834DF2596AEBD500D69B8283E5702D988ED49655AE654C1683C7A4AE58BFA6B92F2B73A", "--url", "https://localhost:1234/foobar.html", "--url", "https://localhost:1235/baz.html"))
141141
Throw-IfNotFailed
142142
if (-not ($actual -match $expected)) {
143143
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (fail)"
144144
}
145145

146146
#azurl (no), x-block-origin (no), asset-cache (n/a), download (sha-mismatch)
147-
#Expected: Hash check failed message expected/actual sha
147+
#Expected: Hash check failed message expected/actual sha. Note that the expected sha is changed to lowercase.
148148
Refresh-TestRoot
149149
$expected = @(
150150
"^Downloading https://example\.com -> example3\.html",
@@ -230,7 +230,7 @@ Throw-IfNotFailed
230230

231231

232232
# azurl (yes), x-block-origin (no), asset-cache (miss), download (fail)
233-
# Expected: Download failure message, asset cache named, nothing about x-block-origin
233+
# Expected: Download failure message, asset cache named, nothing about x-block-origin. Note that the expected SHA is changed to lowercase.
234234
Refresh-TestRoot
235235
$expected = @(
236236
"^Trying to download example3\.html using asset cache file://$assetCacheRegex/[0-9a-z]+",
@@ -250,7 +250,7 @@ $expected = @(
250250
"$"
251251
) -join "`n"
252252

253-
$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"))
253+
$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"))
254254
Throw-IfNotFailed
255255
if (-not ($actual -match $expected)) {
256256
throw "Failure: azurl (yes), x-block-origin (no), asset-cache (miss), download (fail)"

include/vcpkg/base/strings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ namespace vcpkg::Strings
129129
void inplace_ascii_to_lowercase(std::string& s);
130130
[[nodiscard]] std::string ascii_to_lowercase(StringView s);
131131
[[nodiscard]] std::string ascii_to_uppercase(StringView s);
132-
void append_ascii_lowercase(std::string& target, StringView s);
133132

134133
bool case_insensitive_ascii_starts_with(StringView s, StringView pattern);
135134
bool case_insensitive_ascii_ends_with(StringView s, StringView pattern);

src/vcpkg/base/downloads.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,16 @@ namespace vcpkg
599599
const Path& downloaded_path,
600600
StringView sha512)
601601
{
602+
if (!std::all_of(sha512.begin(), sha512.end(), ParserBase::is_hex_digit_lower))
603+
{
604+
Checks::unreachable(VCPKG_LINE_INFO);
605+
}
606+
602607
auto maybe_actual_hash =
603608
vcpkg::Hash::get_file_hash_required(context, fs, downloaded_path, Hash::Algorithm::Sha512);
604609
if (auto actual_hash = maybe_actual_hash.get())
605610
{
606-
if (Strings::case_insensitive_ascii_equals(sha512, *actual_hash))
611+
if (sha512 == *actual_hash)
607612
{
608613
return true;
609614
}
@@ -1427,7 +1432,7 @@ namespace vcpkg
14271432
{
14281433
if (auto sha512 = maybe_sha512.get())
14291434
{
1430-
Strings::append_ascii_lowercase(out, *sha512);
1435+
out.append(*sha512);
14311436
return true;
14321437
}
14331438

@@ -1607,7 +1612,7 @@ namespace vcpkg
16071612
View<std::string> raw_urls,
16081613
View<std::string> headers,
16091614
const Path& download_path,
1610-
const Optional<std::string>& maybe_sha512)
1615+
const Optional<std::string>& maybe_sha512_mixed_case)
16111616
{
16121617
// Design goals:
16131618
// * We want it to be clear when asset cache(s) are used. This means not printing the authoritative URL in a
@@ -1627,6 +1632,8 @@ namespace vcpkg
16271632
//
16281633
// See examples of console output in asset-caching.ps1
16291634

1635+
auto maybe_sha512 =
1636+
maybe_sha512_mixed_case.map([](const std::string& sha512) { return Strings::ascii_to_lowercase(sha512); });
16301637
// Note: no secrets for the input URLs
16311638
std::vector<SanitizedUrl> sanitized_urls =
16321639
Util::fmap(raw_urls, [&](const std::string& url) { return SanitizedUrl{url, {}}; });

src/vcpkg/base/strings.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void Strings::inplace_ascii_to_lowercase(std::string& s)
202202
std::string Strings::ascii_to_lowercase(StringView s)
203203
{
204204
std::string result;
205-
append_ascii_lowercase(result, s);
205+
std::transform(s.begin(), s.end(), std::back_inserter(result), tolower_char);
206206
return result;
207207
}
208208

@@ -213,11 +213,6 @@ std::string Strings::ascii_to_uppercase(StringView s)
213213
return result;
214214
}
215215

216-
void Strings::append_ascii_lowercase(std::string& target, StringView s)
217-
{
218-
std::transform(s.begin(), s.end(), std::back_inserter(target), tolower_char);
219-
}
220-
221216
bool Strings::case_insensitive_ascii_starts_with(StringView s, StringView pattern)
222217
{
223218
if (s.size() < pattern.size()) return false;

0 commit comments

Comments
 (0)