tests: fix style

This commit is contained in:
Éloi Rivard 2025-01-10 14:50:17 +01:00
parent d18a0e1a80
commit af2f71c978
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
7 changed files with 22 additions and 22 deletions

View file

@ -234,7 +234,7 @@ def validate_smtp_configuration(config):
except smtplib.SMTPAuthenticationError as exc: except smtplib.SMTPAuthenticationError as exc:
raise ConfigurationException( raise ConfigurationException(
f'SMTP authentication failed with user \'{config["LOGIN"]}\'' f"SMTP authentication failed with user '{config['LOGIN']}'"
) from exc ) from exc
except smtplib.SMTPNotSupportedError as exc: except smtplib.SMTPNotSupportedError as exc:
@ -270,7 +270,7 @@ def validate_theme(config):
if not os.path.exists(config["THEME"]) and not os.path.exists( if not os.path.exists(config["THEME"]) and not os.path.exists(
os.path.join(ROOT, "themes", config["THEME"]) os.path.join(ROOT, "themes", config["THEME"])
): ):
raise ConfigurationException(f'Cannot find theme \'{config["THEME"]}\'') raise ConfigurationException(f"Cannot find theme '{config['THEME']}'")
def validate_admin_email(config): def validate_admin_email(config):

View file

@ -135,8 +135,8 @@ class LDAPBackend(Backend):
except ldap.INSUFFICIENT_ACCESS as exc: except ldap.INSUFFICIENT_ACCESS as exc:
raise ConfigurationException( raise ConfigurationException(
f'LDAP user \'{config["CANAILLE_LDAP"]["BIND_DN"]}\' cannot create ' f"LDAP user '{config['CANAILLE_LDAP']['BIND_DN']}' cannot create "
f'users at \'{config["CANAILLE_LDAP"]["USER_BASE"]}\'' f"users at '{config['CANAILLE_LDAP']['USER_BASE']}'"
) from exc ) from exc
try: try:
@ -160,8 +160,8 @@ class LDAPBackend(Backend):
except ldap.INSUFFICIENT_ACCESS as exc: except ldap.INSUFFICIENT_ACCESS as exc:
raise ConfigurationException( raise ConfigurationException(
f'LDAP user \'{config["CANAILLE_LDAP"]["BIND_DN"]}\' cannot create ' f"LDAP user '{config['CANAILLE_LDAP']['BIND_DN']}' cannot create "
f'groups at \'{config["CANAILLE_LDAP"]["GROUP_BASE"]}\'' f"groups at '{config['CANAILLE_LDAP']['GROUP_BASE']}'"
) from exc ) from exc
finally: finally:
@ -430,7 +430,7 @@ def setup_ldap_models(config):
LDAPObject.root_dn = config["CANAILLE_LDAP"]["ROOT_DN"] LDAPObject.root_dn = config["CANAILLE_LDAP"]["ROOT_DN"]
user_base = config["CANAILLE_LDAP"]["USER_BASE"].replace( user_base = config["CANAILLE_LDAP"]["USER_BASE"].replace(
f',{config["CANAILLE_LDAP"]["ROOT_DN"]}', "" f",{config['CANAILLE_LDAP']['ROOT_DN']}", ""
) )
models.User.base = user_base models.User.base = user_base
models.User.rdn_attribute = config["CANAILLE_LDAP"]["USER_RDN"] models.User.rdn_attribute = config["CANAILLE_LDAP"]["USER_RDN"]
@ -438,7 +438,7 @@ def setup_ldap_models(config):
models.User.ldap_object_class = listify(object_class) models.User.ldap_object_class = listify(object_class)
group_base = config["CANAILLE_LDAP"]["GROUP_BASE"].replace( group_base = config["CANAILLE_LDAP"]["GROUP_BASE"].replace(
f',{config["CANAILLE_LDAP"]["ROOT_DN"]}', "" f",{config['CANAILLE_LDAP']['ROOT_DN']}", ""
) )
models.Group.base = group_base or None models.Group.base = group_base or None
models.Group.rdn_attribute = config["CANAILLE_LDAP"]["GROUP_RDN"] models.Group.rdn_attribute = config["CANAILLE_LDAP"]["GROUP_RDN"]

View file

@ -103,7 +103,7 @@ def password():
if not success: if not success:
logout_user() logout_user()
current_app.logger.security( current_app.logger.security(
f'Failed login attempt for {session["attempt_login"]} from {request_ip}' f"Failed login attempt for {session['attempt_login']} from {request_ip}"
) )
flash(message or _("Login failed, please check your information"), "error") flash(message or _("Login failed, please check your information"), "error")
return render_template( return render_template(
@ -126,7 +126,7 @@ def password():
) )
else: else:
current_app.logger.security( current_app.logger.security(
f'Succeed login attempt for {session["attempt_login"]} from {request_ip}' f"Succeed login attempt for {session['attempt_login']} from {request_ip}"
) )
del session["attempt_login"] del session["attempt_login"]
login_user(user) login_user(user)
@ -359,7 +359,7 @@ def verify_two_factor_auth():
user.last_otp_login = datetime.datetime.now(datetime.timezone.utc) user.last_otp_login = datetime.datetime.now(datetime.timezone.utc)
Backend.instance.save(user) Backend.instance.save(user)
current_app.logger.security( current_app.logger.security(
f'Succeed login attempt for {session["attempt_login_with_correct_password"]} from {request_ip}' f"Succeed login attempt for {session['attempt_login_with_correct_password']} from {request_ip}"
) )
del session["attempt_login_with_correct_password"] del session["attempt_login_with_correct_password"]
login_user(user) login_user(user)
@ -380,7 +380,7 @@ def verify_two_factor_auth():
) )
request_ip = request.remote_addr or "unknown IP" request_ip = request.remote_addr or "unknown IP"
current_app.logger.security( current_app.logger.security(
f'Failed login attempt (wrong OTP) for {session["attempt_login_with_correct_password"]} from {request_ip}' f"Failed login attempt (wrong OTP) for {session['attempt_login_with_correct_password']} from {request_ip}"
) )
return redirect(url_for("core.auth.verify_two_factor_auth")) return redirect(url_for("core.auth.verify_two_factor_auth"))
@ -408,7 +408,7 @@ def send_mail_otp():
Backend.instance.save(user) Backend.instance.save(user)
request_ip = request.remote_addr or "unknown IP" request_ip = request.remote_addr or "unknown IP"
current_app.logger.security( current_app.logger.security(
f'Sent one-time password for {session["attempt_login_with_correct_password"]} to {user.emails[0]} from {request_ip}' f"Sent one-time password for {session['attempt_login_with_correct_password']} to {user.emails[0]} from {request_ip}"
) )
flash( flash(
"Code successfully sent!", "Code successfully sent!",
@ -448,7 +448,7 @@ def send_sms_otp():
Backend.instance.save(user) Backend.instance.save(user)
request_ip = request.remote_addr or "unknown IP" request_ip = request.remote_addr or "unknown IP"
current_app.logger.security( current_app.logger.security(
f'Sent one-time password for {session["attempt_login_with_correct_password"]} to {user.phone_numbers[0]} from {request_ip}' f"Sent one-time password for {session['attempt_login_with_correct_password']} to {user.phone_numbers[0]} from {request_ip}"
) )
flash( flash(
"Code successfully sent!", "Code successfully sent!",
@ -487,7 +487,7 @@ def redirect_to_verify_mfa(user, otp_method, request_ip, fail_redirect_url):
"info", "info",
) )
current_app.logger.security( current_app.logger.security(
f'Sent one-time password for {session["attempt_login_with_correct_password"]} to {user.emails[0]} from {request_ip}' f"Sent one-time password for {session['attempt_login_with_correct_password']} to {user.emails[0]} from {request_ip}"
) )
return redirect(url_for("core.auth.verify_two_factor_auth")) return redirect(url_for("core.auth.verify_two_factor_auth"))
else: else:
@ -510,7 +510,7 @@ def redirect_to_verify_mfa(user, otp_method, request_ip, fail_redirect_url):
"info", "info",
) )
current_app.logger.security( current_app.logger.security(
f'Sent one-time password for {session["attempt_login_with_correct_password"]} to {user.phone_numbers[0]} from {request_ip}' f"Sent one-time password for {session['attempt_login_with_correct_password']} to {user.phone_numbers[0]} from {request_ip}"
) )
return redirect(url_for("core.auth.verify_two_factor_auth")) return redirect(url_for("core.auth.verify_two_factor_auth"))
else: else:

View file

@ -96,7 +96,7 @@ def authorize_guards(client):
): ):
return { return {
"error": "invalid_request", "error": "invalid_request",
"error_description": f"prompt '{request.args['prompt'] }' value is not supported", "error_description": f"prompt '{request.args['prompt']}' value is not supported",
}, 400 }, 400

View file

@ -122,7 +122,7 @@ def test_intruder_lockout_two_consecutive_fails(testclient, backend, user, caplo
assert ( assert (
"error", "error",
f"Too much attempts. Please wait for {PASSWORD_MIN_DELAY*2 - ldap_shift} seconds before trying to login again.", f"Too much attempts. Please wait for {PASSWORD_MIN_DELAY * 2 - ldap_shift} seconds before trying to login again.",
) in res.flashes ) in res.flashes
assert ( assert (
"canaille", "canaille",

View file

@ -124,9 +124,9 @@ def test_edition(testclient, logged_user, admin, jpeg_photo, backend, caplog):
form["photo"] = Upload("logo.jpg", jpeg_photo) form["photo"] = Upload("logo.jpg", jpeg_photo)
res = form.submit(name="action", value="edit-profile") res = form.submit(name="action", value="edit-profile")
assert res.flashes == [ assert res.flashes == [("success", "Le profil a été mis à jour avec succès.")], (
("success", "Le profil a été mis à jour avec succès.") res.text
], res.text )
assert ( assert (
"canaille", "canaille",
logging.SECURITY, logging.SECURITY,

View file

@ -135,7 +135,7 @@ wheels = [
[[package]] [[package]]
name = "canaille" name = "canaille"
version = "0.0.57" version = "0.0.58"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "flask" }, { name = "flask" },