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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-04-30 15:15:24 -07:00 committed by James Valleroy
parent 8875bc32ae
commit 8b7ca439ff
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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