Merge lp:~allenap/maas/username-fuzzing into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 1452
Proposed branch: lp:~allenap/maas/username-fuzzing
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 49 lines (+9/-2)
3 files modified
src/maasserver/testing/factory.py (+1/-1)
src/maasserver/tests/test_views_settings.py (+1/-1)
src/maastesting/factory.py (+7/-0)
To merge this branch: bzr merge lp:~allenap/maas/username-fuzzing
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+152200@code.launchpad.net

Commit message

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

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/testing/factory.py'
2--- src/maasserver/testing/factory.py 2013-03-05 08:18:47 +0000
3+++ src/maasserver/testing/factory.py 2013-03-07 15:36:26 +0000
4@@ -269,7 +269,7 @@
5
6 def make_user(self, username=None, password=None, email=None):
7 if username is None:
8- username = self.getRandomString(10)
9+ username = self.getRandomUsername()
10 if email is None:
11 email = '%s@example.com' % self.getRandomString(10)
12 if password is None:
13
14=== modified file 'src/maasserver/tests/test_views_settings.py'
15--- src/maasserver/tests/test_views_settings.py 2013-03-07 15:05:44 +0000
16+++ src/maasserver/tests/test_views_settings.py 2013-03-07 15:36:26 +0000
17@@ -59,7 +59,7 @@
18 # "Add a user" link.
19 self.assertIn(reverse('accounts-add'), all_links)
20 for user in users:
21- rows = tab.cssselect('tr#%s' % user.username)
22+ rows = tab.cssselect('tr#"%s"' % user.username)
23 # Only one row for the user.
24 self.assertEqual(1, len(rows))
25 row = rows[0]
26
27=== modified file 'src/maastesting/factory.py'
28--- src/maastesting/factory.py 2012-11-27 10:26:19 +0000
29+++ src/maastesting/factory.py 2013-03-07 15:36:26 +0000
30@@ -42,6 +42,10 @@
31 random_letters_with_spaces = imap(
32 random.choice, repeat(string.letters + string.digits + ' '))
33
34+ # See django.contrib.auth.forms.UserCreationForm.username.
35+ random_letters_for_usernames = imap(
36+ random.choice, repeat(string.letters + '.@+-'))
37+
38 random_http_responses = imap(
39 random.choice, repeat(tuple(httplib.responses)))
40
41@@ -55,6 +59,9 @@
42 else:
43 return "".join(islice(self.random_letters, size))
44
45+ def getRandomUsername(self, size=10):
46+ return "".join(islice(self.random_letters_for_usernames, size))
47+
48 def getRandomEmail(self, login_size=10):
49 return "%s@example.com" % self.getRandomString(size=login_size)
50