Skip to content

Commit

Permalink
Fix regex validation for SHA 512 hashes (#2020)
Browse files Browse the repository at this point in the history
The regex searched for `521` instead of `512`.

Closes #2018
  • Loading branch information
jugmac00 authored Apr 12, 2021
1 parent 368ce4d commit 5118401
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/2018.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regex validation for SHA 512 hashes - by :user:`jugmac00`.
2 changes: 1 addition & 1 deletion src/tox/tox_env/python/pip/req/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _req_options(parser: ArgumentParser, cli_only: bool) -> None:
parser.add_argument("--hash", action=AddSortedUniqueAction, type=_validate_hash)


_HASH = re.compile(r"sha(256:[a-z0-9]{64}|384:[a-z0-9]{96}|521:[a-z0-9]{128})")
_HASH = re.compile(r"sha(256:[a-z0-9]{64}|384:[a-z0-9]{96}|512:[a-z0-9]{128})")


def _validate_hash(value: str) -> str:
Expand Down
10 changes: 10 additions & 0 deletions tests/tox_env/python/pip/req/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@
],
id="hash with escaped newline",
),
pytest.param(
"attrs --hash=sha512:7a91e5a3d1a1238525e477385ef5ee6cecdc8f8fcc2a79d1b35a9f57ad15c814"
"dada670026f41fdd62e5e10b3fd75d6112704a9521c3df105f0b6f3bb11b128a",
{},
[
"attrs --hash sha512:7a91e5a3d1a1238525e477385ef5ee6cecdc8f8fcc2a79d1b35a9f57ad15c814"
"dada670026f41fdd62e5e10b3fd75d6112704a9521c3df105f0b6f3bb11b128a"
],
id="sha512 hash is supported",
),
],
)
def test_req_file(tmp_path: Path, req: str, opts: Dict[str, Any], requirements: List[str]) -> None:
Expand Down

0 comments on commit 5118401

Please sign in to comment.