mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-13 14:11:37 +00:00
improve error messages (#10207)
* fix remove mfa task * add test for command * clean up after schema test * add assert to esure authenticators are really present/removed * simplify handler * improve error message * make more readable
This commit is contained in:
@@ -28,7 +28,16 @@ class Command(BaseCommand):
|
||||
if len(mfa_user) == 0:
|
||||
logger.warning('No user with this mail associated')
|
||||
elif len(mfa_user) > 1:
|
||||
logger.error('More than one user found with this mail')
|
||||
emails_list = ', '.join(
|
||||
sorted(
|
||||
{b.email for a in mfa_user for b in a.emailaddress_set.all()}
|
||||
| {a.email for a in mfa_user}
|
||||
)
|
||||
)
|
||||
usernames_list = ', '.join(sorted({a.username for a in mfa_user}))
|
||||
logger.error(
|
||||
f"Multiple users found with the provided email; Usernames: '{usernames_list}', Emails: '{emails_list}'"
|
||||
)
|
||||
else:
|
||||
# and clean out all MFA methods
|
||||
auths = mfa_user[0].authenticator_set.all()
|
||||
|
@@ -34,17 +34,25 @@ class CommandTestCase(TestCase):
|
||||
self.assertIn('No user with this mail associated', str(cm[1]))
|
||||
|
||||
# correct removal
|
||||
my_admin = User.objects.create_user(username='admin', email='admin@example.org')
|
||||
my_admin.authenticator_set.create(type='TOTP', data={})
|
||||
self.assertEqual(my_admin.authenticator_set.all().count(), 1)
|
||||
my_admin1 = User.objects.create_user(
|
||||
username='admin', email='admin@example.org'
|
||||
)
|
||||
my_admin1.authenticator_set.create(type='TOTP', data={})
|
||||
self.assertEqual(my_admin1.authenticator_set.all().count(), 1)
|
||||
output = call_command('remove_mfa', 'admin@example.org', verbosity=0)
|
||||
self.assertEqual(output, 'done')
|
||||
self.assertEqual(my_admin.authenticator_set.all().count(), 0)
|
||||
self.assertEqual(my_admin1.authenticator_set.all().count(), 0)
|
||||
|
||||
# two users with same email
|
||||
User.objects.create_user(username='admin2', email='admin@example.org')
|
||||
my_admin2 = User.objects.create_user(
|
||||
username='admin2', email='admin@example.org'
|
||||
)
|
||||
my_admin2.emailaddress_set.create(email='456')
|
||||
my_admin2.emailaddress_set.create(email='123')
|
||||
with self.assertLogs('inventree') as cm:
|
||||
self.assertFalse(
|
||||
call_command('remove_mfa', 'admin@example.org', verbosity=0)
|
||||
)
|
||||
self.assertIn('More than one user found with this mail', str(cm[1]))
|
||||
self.assertIn('Multiple users found with the provided email', str(cm[1]))
|
||||
self.assertIn('admin, admin2', str(cm[1]))
|
||||
self.assertIn('123, 456, admin@example.org', str(cm[1]))
|
||||
|
Reference in New Issue
Block a user