Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@spookylukey spookylukey authored
View
2  django/contrib/admin/sites.py
@@ -300,7 +300,7 @@ def login(self, request):
user = authenticate(username=username, password=password)
if user is None:
message = ERROR_MESSAGE
- if u'@' in username:
+ if username is not None and u'@' in username:
# Mistakenly entered e-mail address instead of username? Look it up.
try:
user = User.objects.get(email=username)
View
11 tests/regressiontests/admin_views/tests.py
@@ -353,6 +353,9 @@ def setUp(self):
LOGIN_FORM_KEY: 1,
'username': 'joepublic',
'password': 'secret'}
+ self.no_username_login = {
+ LOGIN_FORM_KEY: 1,
+ 'password': 'secret'}
def testLogin(self):
"""
@@ -416,6 +419,14 @@ def testLogin(self):
# Login.context is a list of context dicts we just need to check the first one.
self.assert_(login.context[0].get('error_message'))
+ # Requests without username should not return 500 errors.
+ request = self.client.get('/test_admin/admin/')
+ self.failUnlessEqual(request.status_code, 200)
+ login = self.client.post('/test_admin/admin/', self.no_username_login)
+ self.failUnlessEqual(login.status_code, 200)
+ # Login.context is a list of context dicts we just need to check the first one.
+ self.assert_(login.context[0].get('error_message'))
+
def testLoginSuccessfullyRedirectsToOriginalUrl(self):
request = self.client.get('/test_admin/admin/')
self.failUnlessEqual(request.status_code, 200)
Please sign in to comment.
Something went wrong with that request. Please try again.