← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/username-fuzzing into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/username-fuzzing into lp:maas.

Commit message:
Ensure that users created by the factory have a username drawn from the full range of valid characters.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1152211 in MAAS: "IDs in rendered HTML contain CSS selector characters"
  https://bugs.launchpad.net/maas/+bug/1152211

For more details, see:
https://code.launchpad.net/~allenap/maas/username-fuzzing/+merge/152200
-- 
https://code.launchpad.net/~allenap/maas/username-fuzzing/+merge/152200
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/username-fuzzing into lp:maas.
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py	2013-03-05 08:18:47 +0000
+++ src/maasserver/testing/factory.py	2013-03-07 15:36:26 +0000
@@ -269,7 +269,7 @@
 
     def make_user(self, username=None, password=None, email=None):
         if username is None:
-            username = self.getRandomString(10)
+            username = self.getRandomUsername()
         if email is None:
             email = '%s@xxxxxxxxxxx' % self.getRandomString(10)
         if password is None:

=== modified file 'src/maasserver/tests/test_views_settings.py'
--- src/maasserver/tests/test_views_settings.py	2013-03-07 15:05:44 +0000
+++ src/maasserver/tests/test_views_settings.py	2013-03-07 15:36:26 +0000
@@ -59,7 +59,7 @@
         # "Add a user" link.
         self.assertIn(reverse('accounts-add'), all_links)
         for user in users:
-            rows = tab.cssselect('tr#%s' % user.username)
+            rows = tab.cssselect('tr#"%s"' % user.username)
             # Only one row for the user.
             self.assertEqual(1, len(rows))
             row = rows[0]

=== modified file 'src/maastesting/factory.py'
--- src/maastesting/factory.py	2012-11-27 10:26:19 +0000
+++ src/maastesting/factory.py	2013-03-07 15:36:26 +0000
@@ -42,6 +42,10 @@
     random_letters_with_spaces = imap(
         random.choice, repeat(string.letters + string.digits + ' '))
 
+    # See django.contrib.auth.forms.UserCreationForm.username.
+    random_letters_for_usernames = imap(
+        random.choice, repeat(string.letters + '.@+-'))
+
     random_http_responses = imap(
         random.choice, repeat(tuple(httplib.responses)))
 
@@ -55,6 +59,9 @@
         else:
             return "".join(islice(self.random_letters, size))
 
+    def getRandomUsername(self, size=10):
+        return "".join(islice(self.random_letters_for_usernames, size))
+
     def getRandomEmail(self, login_size=10):
         return "%s@xxxxxxxxxxx" % self.getRandomString(size=login_size)