mirror of https://github.com/pypa/pip
Fix a NoneType AttributeError when evaluating hashes.
This commit is contained in:
parent
369ec7c0a8
commit
0a1571ba03
|
@ -0,0 +1,2 @@
|
|||
Fix a ``NoneType`` ``AttributeError`` when evaluating hashes and no hashes
|
||||
are provided.
|
|
@ -200,11 +200,11 @@ class Link(KeyBasedCompareMixin):
|
|||
return self.hash_name is not None
|
||||
|
||||
def is_hash_allowed(self, hashes):
|
||||
# type: (Hashes) -> bool
|
||||
# type: (Optional[Hashes]) -> bool
|
||||
"""
|
||||
Return True if the link has a hash and it is allowed.
|
||||
"""
|
||||
if not self.has_hash:
|
||||
if hashes is None or not self.has_hash:
|
||||
return False
|
||||
# Assert non-None so mypy knows self.hash_name and self.hash are str.
|
||||
assert self.hash_name is not None
|
||||
|
|
|
@ -117,3 +117,13 @@ class TestLink:
|
|||
}
|
||||
hashes = Hashes(hashes_data)
|
||||
assert not link.is_hash_allowed(hashes)
|
||||
|
||||
@pytest.mark.parametrize('hashes, expected', [
|
||||
(None, False),
|
||||
# Also test a success case to show the test is correct.
|
||||
(Hashes({'sha512': [128 * 'a']}), True),
|
||||
])
|
||||
def test_is_hash_allowed__none_hashes(self, hashes, expected):
|
||||
url = 'https://example.com/wheel.whl#sha512={}'.format(128 * 'a')
|
||||
link = Link(url)
|
||||
assert link.is_hash_allowed(hashes) == expected
|
||||
|
|
Loading…
Reference in New Issue