From 26e80441c2cecc34c9fdb9b800f8ba021fefd86a Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 9 Sep 2021 08:14:18 +0000 Subject: [PATCH] Increase password complexity Use upper and lower case letter as well as digits for characters in password, also increase password length. Change-Id: I2739166a95a09b4363eebe6b8cc6aac8e87f3c2d --- src/charm.py | 6 ++++-- unit_tests/test_ceph_dashboard_charm.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/charm.py b/src/charm.py index bed3f58..9a2cc02 100755 --- a/src/charm.py +++ b/src/charm.py @@ -424,9 +424,11 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm): self.TLS_KEY_PATH) self.kick_dashboard() - def _gen_user_password(self, length: int = 8) -> str: + def _gen_user_password(self, length: int = 12) -> str: """Generate a password""" - alphabet = string.ascii_letters + string.digits + alphabet = ( + string.ascii_lowercase + string.ascii_uppercase + string.digits) + return ''.join(secrets.choice(alphabet) for i in range(length)) def _add_user_action(self, event: ActionEvent) -> None: diff --git a/unit_tests/test_ceph_dashboard_charm.py b/unit_tests/test_ceph_dashboard_charm.py index b835c0a..14d226a 100644 --- a/unit_tests/test_ceph_dashboard_charm.py +++ b/unit_tests/test_ceph_dashboard_charm.py @@ -470,7 +470,7 @@ class TestCephDashboardCharmBase(CharmTestCase): _choice.return_value = 'r' self.assertEqual( self.harness.charm._gen_user_password(), - 'rrrrrrrr') + 'rrrrrrrrrrrr') @patch.object(charm.tempfile, 'NamedTemporaryFile') @patch.object(charm.secrets, 'choice')