Skip to content

Commit

Permalink
Fixed code smells, disabled silly lgtm alers
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticuproject committed Jan 28, 2022
1 parent 447fb4f commit eb15a4b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions hibpwned/__init__.py
Expand Up @@ -37,7 +37,7 @@ def _check(resp: requests.models.Response) -> None:
" has therefore not been pwned")
elif resp.status_code == 429:
print("Too many requests: The rate limit has been exceeded\n")
print(resp.text)
print(resp.text) # lgtm [py/clear-text-logging-sensitive-data]
except requests.RequestException:
print("ERROR: Could not connect to server")

Expand Down Expand Up @@ -445,7 +445,9 @@ def search_password(self, password: str) -> Union[int, str]:
>>> data = foo.search_password("BadPassword")
"""
url = "https://api.pwnedpasswords.com/range/"
hash_object = hashlib.sha1(bytes(password, encoding="utf-8"))
hash_object = hashlib.sha1(
bytes(password,
encoding="utf-8")) # lgtm [py/weak-sensitive-data-hashing]
hexdig = hash_object.hexdigest()
hexdig = hexdig.upper()
hsh = hexdig[:5]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
"""Setup file"""
from setuptools import setup # type: ignore

VERSION = "1.3.0"
VERSION = "1.3.1"

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
Expand Down
7 changes: 4 additions & 3 deletions test.py
Expand Up @@ -24,6 +24,7 @@
# pylint: disable=unused-argument
def mocked_requests_get(*args: Any, **kwargs: Any) -> Any:
"""This method will be used by the mock to replace requests.get."""
fake_email: str = "test@example.com"

class MockResponse: # pylint: disable=too-few-public-methods
"""Mock API responses."""
Expand All @@ -39,13 +40,13 @@ def json(self) -> Optional[Union[List[str], Dict[str, str]]]:
return self.response_data

if args[0] == ("https://haveibeenpwned.com/api/v3/breachedaccount/" +
"test@example.com"):
fake_email):
return MockResponse(["FakeSite"], 200)
if args[0] == ("https://haveibeenpwned.com/api/v3/breachedaccount/" +
"test@example.com?truncateResponse=false"):
fake_email + "?truncateResponse=false"):
return MockResponse({"testKey": "testValue"}, 200)
if args[0] == ("https://haveibeenpwned.com/api/v3/pasteaccount/" +
"test@example.com"):
fake_email):
return MockResponse({"testKey": "testValue"}, 200)
return MockResponse(None, 404)

Expand Down

0 comments on commit eb15a4b

Please sign in to comment.