Login

SSL Redirect Middleware and testing

Author:
willhardy
Posted:
July 14, 2008
Language:
Python
Version:
.96
Tags:
middleware ssl testing redirect
Score:
1 (after 1 ratings)

While we're on the topic of SSLRedirect (See snippet 240 and 880) here's what I add to the end of my ssl middleware module, so that SSLRedirect wont break my automated testing.

It simply creates a dummy middleware class that removes the SSL argument, but does not do any redirecting. If you were to simply remove the middleware from settings, the extra SSL argument will then get passed on to all the relevant views.

Of course, you'll need to define a TESTING variable in settings, or change this to something else like settings.DEBUG. Having the separate variable for testing allows you to run your server in DEBUG mode without side effects like the change above.

1
2
3
4
5
6
7
# Create a dummy middleware class for testing, that simply removes the SSL argument
# and does nothing else.
if settings.TESTING:
    class SSLRedirect:
        def process_view(self, request, view_func, view_args, view_kwargs):
            if SSL in view_kwargs:
                del view_kwargs[SSL]

More like this

  1. SSL Middleware by sjzabel 8 years, 6 months ago
  2. Enable AWS ELB with SSL Termination by zvikico 4 years, 2 months ago
  3. RegEx redirect fallback middleware by bowdengm 3 years, 1 month ago
  4. TLS(SSL) middleware, per URL pattern or whole site by robmadole 4 years, 9 months ago
  5. HTTPS redirections middleware with updated URL template tag by xlq 2 years, 10 months ago

Comments

Please login first before commenting.