Small cleanups with pwned handling (#2625)

This commit is contained in:
Pascal Vizeli 2021-02-25 15:36:02 +01:00 committed by GitHub
parent 115af4cadf
commit 739cfbb273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -138,7 +138,7 @@ class AddonOptions(CoreSysAttributes):
range_args[group_name[2:]] = float(group_value)
if typ.startswith(_STR) or typ.startswith(_PASSWORD):
if typ.startswith(_PASSWORD):
if typ.startswith(_PASSWORD) and value:
self.pwned.add(hashlib.sha1(str(value).encode()).hexdigest())
return vol.All(str(value), vol.Range(**range_args))(value)
elif typ.startswith(_INT):

View File

@ -22,7 +22,7 @@ async def check_pwned_password(websession: aiohttp.ClientSession, sha1_pw: str)
data = await request.text()
buffer = io.StringIO(data)
for line in buffer.readline():
for line in buffer:
if sha1_pw != line.split(":")[0]:
continue
return True

View File

@ -181,6 +181,11 @@ def test_simple_schema_password(coresys):
assert validate.pwned == {"7110eda4d09e062aa5e4a390b0a572ac0d2c0220"}
validate.pwned.clear()
assert validate({"name": "Pascal", "password": "", "fires": True, "alias": "test"})
assert not validate.pwned
def test_ui_simple_schema(coresys):
"""Test with simple schema."""