mirror of https://github.com/mamba-org/mamba.git
Support SHA256 hashes in @EXPLICIT files (#3866)
This commit is contained in:
parent
d1ca95e356
commit
b3a48ce365
|
@ -215,9 +215,24 @@ namespace mamba::specs
|
|||
return parse_url(url).transform(
|
||||
[&](PackageInfo&& pkg) -> PackageInfo
|
||||
{
|
||||
if (is_hash(hash))
|
||||
if (util::starts_with(hash, "sha256:"))
|
||||
{
|
||||
pkg.md5 = hash;
|
||||
hash = hash.substr(7);
|
||||
if (hash.size() == 64 && is_hash(hash))
|
||||
{
|
||||
pkg.sha256 = hash;
|
||||
}
|
||||
}
|
||||
else if (is_hash(hash))
|
||||
{
|
||||
if (hash.size() == 32)
|
||||
{
|
||||
pkg.md5 = hash;
|
||||
}
|
||||
else if (hash.size() == 64)
|
||||
{
|
||||
pkg.sha256 = hash;
|
||||
}
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace
|
|||
REQUIRE(pkg.filename == "pkg-6.4-bld.conda");
|
||||
REQUIRE(pkg.package_url == url);
|
||||
REQUIRE(pkg.md5 == "");
|
||||
REQUIRE(pkg.sha256 == "");
|
||||
REQUIRE(pkg.platform == "linux-64");
|
||||
REQUIRE(pkg.channel == "https://conda.anaconda.org/conda-forge");
|
||||
}
|
||||
|
@ -48,6 +49,43 @@ namespace
|
|||
REQUIRE(pkg.filename == "pkg-6.4-bld.conda");
|
||||
REQUIRE(pkg.package_url == url.substr(0, url.rfind('#')));
|
||||
REQUIRE(pkg.md5 == url.substr(url.rfind('#') + 1));
|
||||
REQUIRE(pkg.sha256 == "");
|
||||
REQUIRE(pkg.platform == "linux-64");
|
||||
REQUIRE(pkg.channel == "https://conda.anaconda.org/conda-forge");
|
||||
}
|
||||
|
||||
SECTION("https://conda.anaconda.org/conda-forge/linux-64/pkg-6.4-bld.conda#7dbaa197d7ba6032caf7ae7f32c1efa07dbaa197d7ba6032caf7ae7f32c1efa0"
|
||||
)
|
||||
{
|
||||
static constexpr std::string_view url = "https://conda.anaconda.org/conda-forge/linux-64/pkg-6.4-bld.conda#7dbaa197d7ba6032caf7ae7f32c1efa07dbaa197d7ba6032caf7ae7f32c1efa0";
|
||||
|
||||
auto pkg = PackageInfo::from_url(url).value();
|
||||
|
||||
REQUIRE(pkg.name == "pkg");
|
||||
REQUIRE(pkg.version == "6.4");
|
||||
REQUIRE(pkg.build_string == "bld");
|
||||
REQUIRE(pkg.filename == "pkg-6.4-bld.conda");
|
||||
REQUIRE(pkg.package_url == url.substr(0, url.rfind('#')));
|
||||
REQUIRE(pkg.md5 == "");
|
||||
REQUIRE(pkg.sha256 == url.substr(url.rfind('#') + 1));
|
||||
REQUIRE(pkg.platform == "linux-64");
|
||||
REQUIRE(pkg.channel == "https://conda.anaconda.org/conda-forge");
|
||||
}
|
||||
|
||||
SECTION("https://conda.anaconda.org/conda-forge/linux-64/pkg-6.4-bld.conda#sha256:7dbaa197d7ba6032caf7ae7f32c1efa07dbaa197d7ba6032caf7ae7f32c1efa0"
|
||||
)
|
||||
{
|
||||
static constexpr std::string_view url = "https://conda.anaconda.org/conda-forge/linux-64/pkg-6.4-bld.conda#sha256:7dbaa197d7ba6032caf7ae7f32c1efa07dbaa197d7ba6032caf7ae7f32c1efa0";
|
||||
|
||||
auto pkg = PackageInfo::from_url(url).value();
|
||||
|
||||
REQUIRE(pkg.name == "pkg");
|
||||
REQUIRE(pkg.version == "6.4");
|
||||
REQUIRE(pkg.build_string == "bld");
|
||||
REQUIRE(pkg.filename == "pkg-6.4-bld.conda");
|
||||
REQUIRE(pkg.package_url == url.substr(0, url.rfind('#')));
|
||||
REQUIRE(pkg.md5 == "");
|
||||
REQUIRE(pkg.sha256 == url.substr(url.rfind("#sha256:") + 8));
|
||||
REQUIRE(pkg.platform == "linux-64");
|
||||
REQUIRE(pkg.channel == "https://conda.anaconda.org/conda-forge");
|
||||
}
|
||||
|
@ -65,6 +103,7 @@ namespace
|
|||
REQUIRE(pkg.filename == "_libgcc_mutex-0.1-conda_forge.tar.bz2");
|
||||
REQUIRE(pkg.package_url == url.substr(0, url.rfind('#')));
|
||||
REQUIRE(pkg.md5 == url.substr(url.rfind('#') + 1));
|
||||
REQUIRE(pkg.sha256 == "");
|
||||
REQUIRE(pkg.platform == "linux-64");
|
||||
// Make sure the token is not censored when setting the channel
|
||||
REQUIRE(
|
||||
|
|
|
@ -767,12 +767,27 @@ def test_PackageInfo():
|
|||
# str
|
||||
assert str(pkg) == "pkg-1.0-bld"
|
||||
|
||||
# from_url
|
||||
pkg = PackageInfo.from_url("https://repo.mamba.pm/conda-forge/linux-64/bar-5.1-xld.conda#01234")
|
||||
# from_url with md5
|
||||
pkg = PackageInfo.from_url(
|
||||
"https://repo.mamba.pm/conda-forge/linux-64/bar-5.1-xld.conda"
|
||||
"#01234012340123401234012340123401"
|
||||
)
|
||||
assert pkg.name == "bar"
|
||||
assert pkg.version == "5.1"
|
||||
assert pkg.build_string == "xld"
|
||||
assert pkg.md5 == "01234"
|
||||
assert pkg.md5 == "01234012340123401234012340123401"
|
||||
assert pkg.sha256 == ""
|
||||
|
||||
# from_url with sha256
|
||||
pkg = PackageInfo.from_url(
|
||||
"https://repo.mamba.pm/conda-forge/linux-64/bar-5.1-xld.conda"
|
||||
"#0123401234012340123401234012340101234012340123401234012340123401"
|
||||
)
|
||||
assert pkg.name == "bar"
|
||||
assert pkg.version == "5.1"
|
||||
assert pkg.build_string == "xld"
|
||||
assert pkg.md5 == ""
|
||||
assert pkg.sha256 == "0123401234012340123401234012340101234012340123401234012340123401"
|
||||
|
||||
# getters and setters
|
||||
pkg.name = "foo"
|
||||
|
|
Loading…
Reference in New Issue