Skip to content

Commit

Permalink
Fixed #3210 -- Modified test Client.login() to use urlparse, allowing…
Browse files Browse the repository at this point in the history
… absolute URLs in the Location header. Thanks, Ben Dean Kawamura.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4540 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Feb 18, 2007
1 parent 2fe6476 commit 895633a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -104,6 +104,7 @@ answer newbie questions, and generally made Django that much better:
Michael Josephson <http://www.sdjournal.com/>
jpellerin@gmail.com
junzhang.jn@gmail.com
Ben Dean Kawamura <ben.dean.kawamura@gmail.com>
Garth Kidd <http://www.deadlybloodyserious.com/>
kilian <kilian.cavalotti@lip6.fr>
Sune Kirkeby <http://ibofobi.dk/>
Expand Down
6 changes: 4 additions & 2 deletions django/test/client.py
@@ -1,5 +1,6 @@
import sys
from cStringIO import StringIO
from urlparse import urlparse
from django.conf import settings
from django.core.handlers.base import BaseHandler
from django.core.handlers.wsgi import WSGIRequest
Expand Down Expand Up @@ -222,7 +223,7 @@ def login(self, path, username, password, **extra):
if response.status_code != 302:
return False

login_path, data = response['Location'].split('?')
_, _, login_path, _, data, _= urlparse(response['Location'])
next = data.split('=')[1]

# Second, GET the login page; required to set up cookies
Expand All @@ -239,7 +240,8 @@ def login(self, path, username, password, **extra):
response = self.post(login_path, data=form_data, **extra)

# Login page should 302 redirect to the originally requested page
if response.status_code != 302 or response['Location'] != path:
if (response.status_code != 302 or
urlparse(response['Location'])[2] != path):
return False

# Since we are logged in, request the actual page again
Expand Down

0 comments on commit 895633a

Please sign in to comment.