Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19807 -- Sanitized getpass input in createsuperuser

Python 2 getpass on Windows doesn't accept unicode, even when
containing only ascii chars.
Thanks Semmel for the report and tests.
  • Loading branch information...
commit 02e5909f7ae436dab8e4d13370670c467163b8aa 1 parent dcf8cd3
Claude Paroz authored February 15, 2013
2  django/contrib/auth/management/commands/createsuperuser.py
@@ -122,7 +122,7 @@ def handle(self, *args, **options):
122 122
                 while password is None:
123 123
                     if not password:
124 124
                         password = getpass.getpass()
125  
-                        password2 = getpass.getpass('Password (again): ')
  125
+                        password2 = getpass.getpass(force_str('Password (again): '))
126 126
                         if password != password2:
127 127
                             self.stderr.write("Error: Your passwords didn't match.")
128 128
                             password = None
9  django/contrib/auth/tests/basic.py
@@ -13,7 +13,7 @@
13 13
 from django.test import TestCase
14 14
 from django.test.utils import override_settings
15 15
 from django.utils.encoding import force_str
16  
-from django.utils.six import StringIO
  16
+from django.utils.six import binary_type, StringIO
17 17
 
18 18
 
19 19
 def mock_inputs(inputs):
@@ -24,8 +24,11 @@ def mock_inputs(inputs):
24 24
     def inner(test_func):
25 25
         def wrapped(*args):
26 26
             class mock_getpass:
27  
-                pass
28  
-            mock_getpass.getpass = staticmethod(lambda p=None: inputs['password'])
  27
+                @staticmethod
  28
+                def getpass(prompt=b'Password: ', stream=None):
  29
+                    # getpass on Windows only supports prompt as bytestring (#19807)
  30
+                    assert isinstance(prompt, binary_type)
  31
+                    return inputs['password']
29 32
 
30 33
             def mock_input(prompt):
31 34
                 # prompt should be encoded in Python 2. This line will raise an

0 notes on commit 02e5909

Please sign in to comment.
Something went wrong with that request. Please try again.