Merge ~andreserl/maas:lp1758760_random_random into maas:master

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: c780b9e2ba386d47232738ade38a5a077fe1d30d
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andreserl/maas:lp1758760_random_random
Merge into: maas:master
Diff against target: 34 lines (+10/-2)
2 files modified
src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py (+6/-2)
src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py (+4/-0)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
MAAS Lander Approve
Review via email: mp+342136@code.launchpad.net

Commit message

LP: #1758760 - Ensure there's no two consecutive occurrences of the same character

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1758760_random_random lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: d1568e5240eb620bd1149509b1596be3d9653d8a

review: Approve
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Are we unit testing this? We should try and unit test this new way of making sure there are no consecutive occurrences of the same character.

review: Needs Information
Revision history for this message
Andres Rodriguez (andreserl) wrote :

I'm happy to add a test for it, but is it really necessary to add yet another that brings no value to test a password that we already test?

Revision history for this message
Newell Jensen (newell-jensen) wrote :

Will let you make the call. Tested your regex loop quickly and seems to work. +1

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py b/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
2index 72e2496..e2c3ce5 100644
3--- a/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
4+++ b/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
5@@ -303,8 +303,12 @@ def generate_random_password(
6 # Create the extra characters to fullfill max_length
7 letters += ''.join([
8 random.choice(string.ascii_letters) for _ in range(length - 7)])
9- # Randomly mix the password
10- return ''.join(random.sample(letters, len(letters)))
11+ # LP: #1758760 - Randomly mix the password until we ensure there's
12+ # not consecutive occurrences of the same character.
13+ password = ''.join(random.sample(letters, len(letters)))
14+ while (bool(re.search(r'(.)\1', password))):
15+ password = ''.join(random.sample(letters, len(letters)))
16+ return password
17 else:
18 letters = string.ascii_letters + string.digits
19 return ''.join([random.choice(letters) for _ in range(length)])
20diff --git a/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py b/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
21index 86803eb..9d5fc50 100644
22--- a/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
23+++ b/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
24@@ -515,6 +515,10 @@ class TestGeneratesAcceptablePasswords(MAASTestCase):
25 required_character_sets += 1
26 if required_character_sets < 2:
27 return False
28+ # Test password doesn't have two or more occurrences of the
29+ # the same consecutive character.
30+ if bool(re.search(r'(.)\1', password)):
31+ return False
32 return True
33 max_attempts = 100
34 acceptable = 0

Subscribers

People subscribed via source and target branches