You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/11/20 15:40:57 UTC
[2/3] allura git commit: [#7787] get rid of weird problems where
error handling and ssl redirects collide
[#7787] get rid of weird problems where error handling and ssl redirects collide
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/25b87336
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/25b87336
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/25b87336
Branch: refs/heads/ib/7787
Commit: 25b8733647944e1d3c475dff62fefbb6762183e2
Parents: f66f754
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Tue Nov 18 02:27:38 2014 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Nov 20 07:42:34 2014 +0000
----------------------------------------------------------------------
Allura/allura/lib/custom_middleware.py | 9 +++++++--
Allura/allura/tests/functional/test_root.py | 14 ++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/25b87336/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 1116b45..8212cd2 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -168,21 +168,26 @@ class SSLMiddleware(object):
if self._no_redirect_re.match(environ['PATH_INFO']):
return req.get_response(self.app)(environ, start_response)
resp = None
+
try:
request_uri = req.url
request_uri.decode('ascii')
except UnicodeError:
resp = exc.HTTPNotFound()
+
secure = req.url.startswith('https://')
srv_path = req.url.split('://', 1)[-1]
# allura-loggedin is a non-secure cookie as a flag to know that the user has a session over on https
force_ssl = (self._force_ssl_logged_in and req.cookies.get('allura-loggedin')) \
or self._force_ssl_re.match(environ['PATH_INFO'])
- if not secure and force_ssl:
+ if req.environ.get('pylons.original_request'):
+ # if an error occurs, then /error/document is fetched (denoted by pylons.original_request)
+ # and we don't want to do any redirects within that sub-request
+ pass
+ elif not secure and force_ssl:
resp = exc.HTTPFound(location='https://' + srv_path)
elif secure and not force_ssl:
resp = exc.HTTPFound(location='http://' + srv_path)
-
if not resp:
resp = self.app
return resp(environ, start_response)
http://git-wip-us.apache.org/repos/asf/allura/blob/25b87336/Allura/allura/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index 179f19a..8f29b31 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -166,3 +166,17 @@ class TestRootController(TestController):
assert_equal(arg.undecorated,
NeighborhoodController.index.undecorated)
set_transaction_name.assert_called_with('foo')
+
+
+class TestRootWithSSLPattern(TestController):
+ def setUp(self):
+ with td.patch_middleware_config({'force_ssl.pattern': '^/auth'}):
+ super(TestRootWithSSLPattern, self).setUp()
+
+ def test_no_weird_ssl_redirect_for_error_document(self):
+ # test a 404, same functionality as a 500 from an error
+ r = self.app.get('/auth/asdfasdf',
+ extra_environ={'wsgi.url_scheme': 'https'},
+ status=404)
+ assert '302 Found' not in r.body, r.body
+ assert '/error/document' not in r.body, r.body