Opened 14 years ago

Closed 13 years ago

#16040 closed New feature (fixed)

test.Client does not handle domain changes on redirection follow

Reported by: Jeremy Dunck Owned by: nobody
Component: Testing framework Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jeremy Dunck)

The default SERVER_NAME used by the test client is testserver.

I have a multi-tenant site serving www.foo.com and www.bar.com. I also have a view which redirects from /spam/ to /eggs/.

Middleware handles the domain redirection, while a view handles the /spam/ -> /eggs/ redirection.

If the test client requests http://www.foo.com/spam/, it is redirected to http://www.bar.com/spam/, but _handle_redirects, while parsing url into scheme and path, does not also update SERVER_NAME in extras. This causes the 2nd request handling to be handled as though it were for http://www.foo.com/spam/ (again), causing a redirection loop.

I think that just as wsgi.url_scheme is updated for scheme, extra['SERVER_NAME'] should be updated for netloc.

It's debatable to me whether this is a bug or a feature -- I realize multi-tenancy is relatively unusual under Django.

Attachments (1)

16040.patch (3.5 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Jeremy Dunck, 14 years ago

Description: modified (diff)

comment:2 by Jeremy Dunck, 14 years ago

Description: modified (diff)

comment:3 by Jeremy Dunck, 14 years ago

Description: modified (diff)

comment:4 by Aymeric Augustin, 13 years ago

Component: UncategorizedTesting framework
Triage Stage: UnreviewedAccepted

Indeed, it seems that the server name should be preserved, like the url scheme. See also #12011.

by Aymeric Augustin, 13 years ago

Attachment: 16040.patch added

comment:5 by Aymeric Augustin, 13 years ago

Has patch: set

comment:6 by Aymeric Augustin, 13 years ago

Resolution: fixed
Status: newclosed

In [17157]:

Fixed #16040 -- Preserved scheme, host and port in the test client when following a redirect.

Note: See TracTickets for help on using tickets.
Back to Top