Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11061: Malformed POST request causes TypeError in AdminSite.lo…

…gin().

Thanks vvd


git-svn-id: http://code.djangoproject.com/svn/django/trunk@11493 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 84ef9dabfab371a1e0f14a846a509e045369280d 1 parent a2b46ca
Luke Plant authored September 10, 2009
2  django/contrib/admin/sites.py
@@ -300,7 +300,7 @@ def login(self, request):
300 300
         user = authenticate(username=username, password=password)
301 301
         if user is None:
302 302
             message = ERROR_MESSAGE
303  
-            if u'@' in username:
  303
+            if username is not None and u'@' in username:
304 304
                 # Mistakenly entered e-mail address instead of username? Look it up.
305 305
                 try:
306 306
                     user = User.objects.get(email=username)
11  tests/regressiontests/admin_views/tests.py
@@ -353,6 +353,9 @@ def setUp(self):
353 353
                      LOGIN_FORM_KEY: 1,
354 354
                      'username': 'joepublic',
355 355
                      'password': 'secret'}
  356
+        self.no_username_login = {
  357
+                     LOGIN_FORM_KEY: 1,
  358
+                     'password': 'secret'}
356 359
 
357 360
     def testLogin(self):
358 361
         """
@@ -416,6 +419,14 @@ def testLogin(self):
416 419
         # Login.context is a list of context dicts we just need to check the first one.
417 420
         self.assert_(login.context[0].get('error_message'))
418 421
 
  422
+        # Requests without username should not return 500 errors.
  423
+        request = self.client.get('/test_admin/admin/')
  424
+        self.failUnlessEqual(request.status_code, 200)
  425
+        login = self.client.post('/test_admin/admin/', self.no_username_login)
  426
+        self.failUnlessEqual(login.status_code, 200)
  427
+        # Login.context is a list of context dicts we just need to check the first one.
  428
+        self.assert_(login.context[0].get('error_message'))
  429
+
419 430
     def testLoginSuccessfullyRedirectsToOriginalUrl(self):
420 431
         request = self.client.get('/test_admin/admin/')
421 432
         self.failUnlessEqual(request.status_code, 200)

0 notes on commit 84ef9da

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