From 8b7ca439ffff9c69d89dac7f59e90ecc0f7b3f13 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 30 Apr 2022 15:15:24 -0700 Subject: [PATCH] mediawiki: Handle password rejection from MediaWiki Closes: #2063. When admin password is being set in MediaWiki, if the password is found in the common list of passwords, MediaWiki will fail instead of setting the password. Detect this case and show an error instead of a hard server. Tests: - Setting the admin password to 'passwordpassword' fails due to check in common passwords list. A message is shown that strong password is needed instead of a 500 error page. - Set the password to 'passwordpassword' and update other settings. Settings are updated with success message but password update fails with error message. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/mediawiki/views.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plinth/modules/mediawiki/views.py b/plinth/modules/mediawiki/views.py index 1a0045eff..44401433b 100644 --- a/plinth/modules/mediawiki/views.py +++ b/plinth/modules/mediawiki/views.py @@ -9,6 +9,7 @@ from django.contrib import messages from django.utils.translation import gettext as _ from plinth import actions, views +from plinth.errors import ActionError from plinth.modules import mediawiki from . import (get_default_skin, get_server_url, is_private_mode_enabled, @@ -44,9 +45,16 @@ class MediaWikiAppView(views.AppView): return old_config.get(key) != new_config.get(key) if new_config['password']: - actions.superuser_run('mediawiki', ['change-password'], - input=new_config['password'].encode()) - messages.success(self.request, _('Password updated')) + try: + actions.superuser_run('mediawiki', ['change-password'], + input=new_config['password'].encode()) + messages.success(self.request, _('Password updated')) + except ActionError as exception: + logger.exception('Failed to update password: %s', exception) + messages.error( + self.request, + _('Password update failed. Please choose a stronger ' + 'password')) if is_changed('enable_public_registrations'): # note action public-registration restarts, if running now