Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
spookylukey committed Sep 10, 2009
1 parent a2b46ca commit 84ef9da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/contrib/admin/sites.py
Expand Up @@ -300,7 +300,7 @@ def login(self, request):
user = authenticate(username=username, password=password) user = authenticate(username=username, password=password)
if user is None: if user is None:
message = ERROR_MESSAGE 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. # Mistakenly entered e-mail address instead of username? Look it up.
try: try:
user = User.objects.get(email=username) user = User.objects.get(email=username)
Expand Down
11 changes: 11 additions & 0 deletions tests/regressiontests/admin_views/tests.py
Expand Up @@ -353,6 +353,9 @@ def setUp(self):
LOGIN_FORM_KEY: 1, LOGIN_FORM_KEY: 1,
'username': 'joepublic', 'username': 'joepublic',
'password': 'secret'} 'password': 'secret'}
self.no_username_login = {
LOGIN_FORM_KEY: 1,
'password': 'secret'}


def testLogin(self): def testLogin(self):
""" """
Expand Down Expand Up @@ -416,6 +419,14 @@ def testLogin(self):
# Login.context is a list of context dicts we just need to check the first one. # Login.context is a list of context dicts we just need to check the first one.
self.assert_(login.context[0].get('error_message')) 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): def testLoginSuccessfullyRedirectsToOriginalUrl(self):
request = self.client.get('/test_admin/admin/') request = self.client.get('/test_admin/admin/')
self.failUnlessEqual(request.status_code, 200) self.failUnlessEqual(request.status_code, 200)
Expand Down

0 comments on commit 84ef9da

Please sign in to comment.