[Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
---------------------------------------------+------------------------
               Reporter:  Roland van Laar    |          Owner:  nobody
                   Type:  Bug                |         Status:  new
              Component:  Testing framework  |        Version:  1.11
               Severity:  Normal             |       Keywords:
           Triage Stage:  Unreviewed         |      Has patch:  0
    Needs documentation:  0                  |    Needs tests:  0
Patch needs improvement:  0                  |  Easy pickings:  0
                  UI/UX:  0                  |
---------------------------------------------+------------------------
 I would like to see `assertRedirects` honor the `HTTP_HOST` settings in
 self.client.get.

 I'm writing middleware that checks if `request.get_host()` is coupled to a
 site, else we do a redirect to an external domain.
 {{{
 def test_redirect(self):
     response = self.client.get("/", follow=False,
 HTTP_HOST=self.site1.domain)
     self.assertRedirects(response, '/accounts/login/?next=',
 fetch_redirect_response=True)
 }}}
 The `assertRedirect` does an extra request to follow the redirect. What
 goes wrong is that the HTTP_HOST with the request is not set to
 '{{ self.site1.domain }}'  but to `testserver`. This results in a redirect
 to our external domain.

 Middleware code:
 {{{
 class SiteMiddleware(object):
     def __init__(self, get_response):
         self.get_response = get_response
     def __call__(self, request):
         host = self.request.get_host()
         try:
             request.site = Site.objects.get(domain=host)
         except ObjectDoesNotExist:
             return HttpResponseRedirect("http://example.com")
         return self.get_response(request)
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28337>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/051.cf06708c1f2243b86878d8791ac15cde%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
--------------------------------------+------------------------------------
     Reporter:  Roland van Laar       |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Testing framework     |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

 * type:  Bug => Cleanup/optimization
 * stage:  Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.b437eb62073c03d9eefbe51cffa80e80%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
In reply to this post by Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
-------------------------------------+-------------------------------------
     Reporter:  Roland van Laar      |                    Owner:  Patrick
         Type:                       |  Jenkins
  Cleanup/optimization               |                   Status:  assigned
    Component:  Testing framework    |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Patrick Jenkins):

 * owner:  nobody => Patrick Jenkins
 * status:  new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.00a0ef4d9193fca4d4efc2e14012b2c0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
In reply to this post by Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
-------------------------------------+-------------------------------------
     Reporter:  Roland van Laar      |                    Owner:  Patrick
         Type:                       |  Jenkins
  Cleanup/optimization               |                   Status:  assigned
    Component:  Testing framework    |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Patrick Jenkins):

 The problem with the provided example is that under certain conditions
 assertRedirect will replay the request with different parameters than
 originally specified. The conditions necessary for this to occur are
 passing follow=False to the original client.get and also passing 'extra'
 parameters that will be interpreted as HTTP header's. Assert redirect
 (version 1.11.4:
 https://github.com/django/django/blob/1a34dfcf797640d5d580d261694cb54e6f97c552/django/test/testcases.py#L317)
 makes an assumption that it is possible to exactly recreate the original
 request with the information that is available.

 To properly recreate the the original request it would be necessary to
 pass ALL method parameters AND all of the kwarg parameters that were
 originally passed in. This would require storing the 'extras' in the
 Client (django.test.client.py) so they could be acccessed in
 assertRedrrects and properly replayed.

 I believe this is the proper solution because it removes the assumptions
 present when assertRedirect attempts to recreate the request. Although
 this is a corner case, it is certainly acceptable for Django users to
 utilize the infinite space that is HTTP headers and provide varying logic
 depending on the values present. The downside of this implementation is
 that it bloats the Client by requiring it to store the extra parameters
 passed in. These extra parameters will rarely be used but I believe the
 tradeoff of adding properties to Client and potentially increasing memory
 footprint are small enough to warrant this change.

--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.ac87f0293365d242f0c7c224a843559d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
In reply to this post by Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
-------------------------------------+-------------------------------------
     Reporter:  Roland van Laar      |                    Owner:  Patrick
         Type:                       |  Jenkins
  Cleanup/optimization               |                   Status:  assigned
    Component:  Testing framework    |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Patrick Jenkins):

 * has_patch:  0 => 1


Comment:

 Pull request https://github.com/django/django/pull/8931

--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.3b548a1922e81bb885c8969a56c20762%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
In reply to this post by Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
-------------------------------------+-------------------------------------
     Reporter:  Roland van Laar      |                    Owner:  Patrick
         Type:                       |  Jenkins
  Cleanup/optimization               |                   Status:  assigned
    Component:  Testing framework    |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * needs_better_patch:  0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.b243c02dc157b69da2bce4c8df752287%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
In reply to this post by Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
-------------------------------------+-------------------------------------
     Reporter:  Roland van Laar      |                    Owner:  Hasan
         Type:                       |  Ramezani
  Cleanup/optimization               |                   Status:  assigned
    Component:  Testing framework    |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

 * owner:  Patrick Jenkins => Hasan Ramezani
 * needs_better_patch:  1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.6988de8ac68301907154fa3613744728%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get

Django
In reply to this post by Django
#28337: fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST
setting in self.client.get
-------------------------------------+-------------------------------------
     Reporter:  Roland van Laar      |                    Owner:  Hasan
         Type:                       |  Ramezani
  Cleanup/optimization               |                   Status:  closed
    Component:  Testing framework    |                  Version:  1.11
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"46e74a525671f2eef09021c06933c45b49f9d421" 46e74a52]:
 {{{
 #!CommitTicketReference repository=""
 revision="46e74a525671f2eef09021c06933c45b49f9d421"
 Fixed #28337 -- Preserved extra headers of requests made with
 django.test.Client in assertRedirects().

 Co-Authored-By: Hasan Ramezani <[hidden email]>
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28337#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.4360c53a6045d10d9f10b02cfef81d4f%40djangoproject.com.