Revised the User class in the AuthenticationTestCase and FlaskLoginTestCase test classes to accept the clear-text password instead of the password hash, to simplify the code.
This commit is contained in:
parent
7e71115844
commit
2028cb1362
@ -35,14 +35,15 @@ _PASSWORD: str = "Circle Of Life"
|
|||||||
class User:
|
class User:
|
||||||
"""A dummy user"""
|
"""A dummy user"""
|
||||||
|
|
||||||
def __init__(self, username: str, password_hash: str):
|
def __init__(self, username: str, password: str):
|
||||||
"""Constructs a dummy user.
|
"""Constructs a dummy user.
|
||||||
|
|
||||||
:param username: The username.
|
:param username: The username.
|
||||||
:param password_hash: The password hash.
|
:param password: The clear-text password.
|
||||||
"""
|
"""
|
||||||
self.username: str = username
|
self.username: str = username
|
||||||
self.password_hash: str = password_hash
|
self.password_hash: str = make_password_hash(
|
||||||
|
_REALM, username, password)
|
||||||
self.visits: int = 0
|
self.visits: int = 0
|
||||||
|
|
||||||
|
|
||||||
@ -63,8 +64,7 @@ class AuthenticationTestCase(TestCase):
|
|||||||
|
|
||||||
auth: DigestAuth = DigestAuth(realm=_REALM)
|
auth: DigestAuth = DigestAuth(realm=_REALM)
|
||||||
auth.init_app(app)
|
auth.init_app(app)
|
||||||
self.user: User = User(
|
self.user: User = User(_USERNAME, _PASSWORD)
|
||||||
_USERNAME, make_password_hash(_REALM, _USERNAME, _PASSWORD))
|
|
||||||
user_db: t.Dict[str, User] = {_USERNAME: self.user}
|
user_db: t.Dict[str, User] = {_USERNAME: self.user}
|
||||||
|
|
||||||
@auth.register_get_password
|
@auth.register_get_password
|
||||||
|
@ -35,14 +35,15 @@ _PASSWORD: str = "Circle Of Life"
|
|||||||
class User:
|
class User:
|
||||||
"""A dummy user."""
|
"""A dummy user."""
|
||||||
|
|
||||||
def __init__(self, username: str, password_hash: str):
|
def __init__(self, username: str, password: str):
|
||||||
"""Constructs a dummy user.
|
"""Constructs a dummy user.
|
||||||
|
|
||||||
:param username: The username.
|
:param username: The username.
|
||||||
:param password_hash: The password hash.
|
:param password: The clear-text password.
|
||||||
"""
|
"""
|
||||||
self.username: str = username
|
self.username: str = username
|
||||||
self.password_hash: str = password_hash
|
self.password_hash: str = make_password_hash(
|
||||||
|
_REALM, username, password)
|
||||||
self.visits: int = 0
|
self.visits: int = 0
|
||||||
self.is_authenticated: bool = True
|
self.is_authenticated: bool = True
|
||||||
self.is_active: bool = True
|
self.is_active: bool = True
|
||||||
@ -85,8 +86,7 @@ class FlaskLoginTestCase(TestCase):
|
|||||||
auth: DigestAuth = DigestAuth(realm=_REALM)
|
auth: DigestAuth = DigestAuth(realm=_REALM)
|
||||||
auth.init_app(app)
|
auth.init_app(app)
|
||||||
|
|
||||||
self.user: User = User(
|
self.user: User = User(_USERNAME, _PASSWORD)
|
||||||
_USERNAME, make_password_hash(_REALM, _USERNAME, _PASSWORD))
|
|
||||||
user_db: t.Dict[str, User] = {_USERNAME: self.user}
|
user_db: t.Dict[str, User] = {_USERNAME: self.user}
|
||||||
|
|
||||||
@auth.register_get_password
|
@auth.register_get_password
|
||||||
|
Loading…
Reference in New Issue
Block a user