mirror of
https://github.com/wassname/flask-security.git
synced 2026-08-20 12:20:08 +08:00
Convert all tests to use pytest. Phew!
This commit is contained in:
+70
-33
@@ -92,38 +92,74 @@ _default_config = {
|
||||
|
||||
#: Default Flask-Security messages
|
||||
_default_messages = {
|
||||
'UNAUTHORIZED': ('You do not have permission to view this resource.', 'error'),
|
||||
'CONFIRM_REGISTRATION': ('Thank you. Confirmation instructions have been sent to %(email)s.', 'success'),
|
||||
'EMAIL_CONFIRMED': ('Thank you. Your email has been confirmed.', 'success'),
|
||||
'ALREADY_CONFIRMED': ('Your email has already been confirmed.', 'info'),
|
||||
'INVALID_CONFIRMATION_TOKEN': ('Invalid confirmation token.', 'error'),
|
||||
'EMAIL_ALREADY_ASSOCIATED': ('%(email)s is already associated with an account.', 'error'),
|
||||
'PASSWORD_MISMATCH': ('Password does not match', 'error'),
|
||||
'RETYPE_PASSWORD_MISMATCH': ('Passwords do not match', 'error'),
|
||||
'INVALID_REDIRECT': ('Redirections outside the domain are forbidden', 'error'),
|
||||
'PASSWORD_RESET_REQUEST': ('Instructions to reset your password have been sent to %(email)s.', 'info'),
|
||||
'PASSWORD_RESET_EXPIRED': ('You did not reset your password within %(within)s. New instructions have been sent to %(email)s.', 'error'),
|
||||
'INVALID_RESET_PASSWORD_TOKEN': ('Invalid reset password token.', 'error'),
|
||||
'CONFIRMATION_REQUIRED': ('Email requires confirmation.', 'error'),
|
||||
'CONFIRMATION_REQUEST': ('Confirmation instructions have been sent to %(email)s.', 'info'),
|
||||
'CONFIRMATION_EXPIRED': ('You did not confirm your email within %(within)s. New instructions to confirm your email have been sent to %(email)s.', 'error'),
|
||||
'LOGIN_EXPIRED': ('You did not login within %(within)s. New instructions to login have been sent to %(email)s.', 'error'),
|
||||
'LOGIN_EMAIL_SENT': ('Instructions to login have been sent to %(email)s.', 'success'),
|
||||
'INVALID_LOGIN_TOKEN': ('Invalid login token.', 'error'),
|
||||
'DISABLED_ACCOUNT': ('Account is disabled.', 'error'),
|
||||
'EMAIL_NOT_PROVIDED': ('Email not provided', 'error'),
|
||||
'INVALID_EMAIL_ADDRESS': ('Invalid email address', 'error'),
|
||||
'PASSWORD_NOT_PROVIDED': ('Password not provided', 'error'),
|
||||
'PASSWORD_NOT_SET': ('No password is set for this user', 'error'),
|
||||
'PASSWORD_INVALID_LENGTH': ('Password must be at least 6 characters', 'error'),
|
||||
'USER_DOES_NOT_EXIST': ('Specified user does not exist', 'error'),
|
||||
'INVALID_PASSWORD': ('Invalid password', 'error'),
|
||||
'PASSWORDLESS_LOGIN_SUCCESSFUL': ('You have successfuly logged in.', 'success'),
|
||||
'PASSWORD_RESET': ('You successfully reset your password and you have been logged in automatically.', 'success'),
|
||||
'PASSWORD_IS_THE_SAME': ('Your new password must be different than your previous password.', 'error'),
|
||||
'PASSWORD_CHANGE': ('You successfully changed your password.', 'success'),
|
||||
'LOGIN': ('Please log in to access this page.', 'info'),
|
||||
'REFRESH': ('Please reauthenticate to access this page.', 'info'),
|
||||
'UNAUTHORIZED': (
|
||||
'You do not have permission to view this resource.', 'error'),
|
||||
'CONFIRM_REGISTRATION': (
|
||||
'Thank you. Confirmation instructions have been sent to %(email)s.', 'success'),
|
||||
'EMAIL_CONFIRMED': (
|
||||
'Thank you. Your email has been confirmed.', 'success'),
|
||||
'ALREADY_CONFIRMED': (
|
||||
'Your email has already been confirmed.', 'info'),
|
||||
'INVALID_CONFIRMATION_TOKEN': (
|
||||
'Invalid confirmation token.', 'error'),
|
||||
'EMAIL_ALREADY_ASSOCIATED': (
|
||||
'%(email)s is already associated with an account.', 'error'),
|
||||
'PASSWORD_MISMATCH': (
|
||||
'Password does not match', 'error'),
|
||||
'RETYPE_PASSWORD_MISMATCH': (
|
||||
'Passwords do not match', 'error'),
|
||||
'INVALID_REDIRECT': (
|
||||
'Redirections outside the domain are forbidden', 'error'),
|
||||
'PASSWORD_RESET_REQUEST': (
|
||||
'Instructions to reset your password have been sent to %(email)s.', 'info'),
|
||||
'PASSWORD_RESET_EXPIRED': (
|
||||
'You did not reset your password within %(within)s. New instructions have been sent '
|
||||
'to %(email)s.', 'error'),
|
||||
'INVALID_RESET_PASSWORD_TOKEN': (
|
||||
'Invalid reset password token.', 'error'),
|
||||
'CONFIRMATION_REQUIRED': (
|
||||
'Email requires confirmation.', 'error'),
|
||||
'CONFIRMATION_REQUEST': (
|
||||
'Confirmation instructions have been sent to %(email)s.', 'info'),
|
||||
'CONFIRMATION_EXPIRED': (
|
||||
'You did not confirm your email within %(within)s. New instructions to confirm your email '
|
||||
'have been sent to %(email)s.', 'error'),
|
||||
'LOGIN_EXPIRED': (
|
||||
'You did not login within %(within)s. New instructions to login have been sent to '
|
||||
'%(email)s.', 'error'),
|
||||
'LOGIN_EMAIL_SENT': (
|
||||
'Instructions to login have been sent to %(email)s.', 'success'),
|
||||
'INVALID_LOGIN_TOKEN': (
|
||||
'Invalid login token.', 'error'),
|
||||
'DISABLED_ACCOUNT': (
|
||||
'Account is disabled.', 'error'),
|
||||
'EMAIL_NOT_PROVIDED': (
|
||||
'Email not provided', 'error'),
|
||||
'INVALID_EMAIL_ADDRESS': (
|
||||
'Invalid email address', 'error'),
|
||||
'PASSWORD_NOT_PROVIDED': (
|
||||
'Password not provided', 'error'),
|
||||
'PASSWORD_NOT_SET': (
|
||||
'No password is set for this user', 'error'),
|
||||
'PASSWORD_INVALID_LENGTH': (
|
||||
'Password must be at least 6 characters', 'error'),
|
||||
'USER_DOES_NOT_EXIST': (
|
||||
'Specified user does not exist', 'error'),
|
||||
'INVALID_PASSWORD': (
|
||||
'Invalid password', 'error'),
|
||||
'PASSWORDLESS_LOGIN_SUCCESSFUL': (
|
||||
'You have successfuly logged in.', 'success'),
|
||||
'PASSWORD_RESET': (
|
||||
'You successfully reset your password and you have been logged in automatically.',
|
||||
'success'),
|
||||
'PASSWORD_IS_THE_SAME': (
|
||||
'Your new password must be different than your previous password.', 'error'),
|
||||
'PASSWORD_CHANGE': (
|
||||
'You successfully changed your password.', 'success'),
|
||||
'LOGIN': (
|
||||
'Please log in to access this page.', 'info'),
|
||||
'REFRESH': (
|
||||
'Please reauthenticate to access this page.', 'info'),
|
||||
}
|
||||
|
||||
_allowed_password_hash_schemes = [
|
||||
@@ -207,7 +243,8 @@ def _get_principal(app):
|
||||
def _get_pwd_context(app):
|
||||
pw_hash = cv('PASSWORD_HASH', app=app)
|
||||
if pw_hash not in _allowed_password_hash_schemes:
|
||||
allowed = ', '.join(_allowed_password_hash_schemes[:-1]) + ' and ' + _allowed_password_hash_schemes[-1]
|
||||
allowed = (', '.join(_allowed_password_hash_schemes[:-1]) +
|
||||
' and ' + _allowed_password_hash_schemes[-1])
|
||||
raise ValueError("Invalid hash scheme %r. Allowed values are %s" % (pw_hash, allowed))
|
||||
return CryptContext(schemes=_allowed_password_hash_schemes, default=pw_hash)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user