Opened 14 years ago

Closed 11 years ago

Last modified 11 years ago

#13725 closed Bug (fixed)

assertRedirects not taking url scheme into account

Reported by: rvdrijst Owned by: Unai Zalakain
Component: Testing framework Version: dev
Severity: Normal Keywords: test client assertRedirects https scheme
Cc: rvdrijst Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The assertRedirects method of TestCase doesn't work correctly with https redirects. There are actually two problems here.

Take the following scenario. You access a view with test client mimicking https by passing in **{'wsgi.url_scheme':'https'}. This view then redirects to a relative url which is converted by fix_location_header to an absolute url with https since the request is_secure(). So far so good.

But assertRedirects will blatantly ignore the scheme, checking the redirect url without the scheme. Since I have views that will redirect to https if not called with https, this will fail because the redirect check will again be redirected because the scheme was ignored.

This first problem can be fixed by adding **{'wsgi.url_scheme':scheme} to the redirect check and also taking the scheme into account when matching the url with expected, but this creates another problem. The fix_location_header response fix will build the absolute url using request.get_host(), which for the test client will return testserver:80. The port part is not expected by assertRedirects, which again fails, trying to match the expected https://testserver/some/path with https://testserver:80/some/path.

Change History (10)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Unai Zalakain, 11 years ago

Owner: changed from nobody to Unai Zalakain
Status: newassigned

Depends on #21341

comment:6 by Unai Zalakain, 11 years ago

Version: 1.2master

comment:8 by loic84, 11 years ago

Triage Stage: AcceptedReady for checkin

Other than the comment I left on the PR, LGTM.

comment:9 by Unai Zalakain <unai@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 9c5f6cd565f1bc519dec20e3e44313cb8d8e0e94:

Fixed #13725 -- take url scheme into account in assertRedirects

Scheme is handled correctly when making comparisons between two URLs. If
there isn't any scheme specified in the location where we are redirected to,
the original request's scheme is used. If present, the scheme in
expected_url is the one used to make the comparations to.

comment:10 by Anssi Kääriäinen <akaariai@…>, 11 years ago

In 30203a0deaf82c8af26b1b5453851f83d2248b67:

Merge pull request #1850 from unaizalakain/ticket_13725

Fixed #13725 -- take url scheme into account in assertRedirects

Thanks to Loic for review.

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