Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed a remaining case of bug #85 #100

Merged
merged 2 commits into from

2 participants

@danwerner

This fixes one remaining case where bug #85 still occurs.

@mcdonc mcdonc merged commit 82fb465 into Pylons:master
@mcdonc
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 3, 2013
  1. @danwerner
  2. @danwerner
This page is out of date. Refresh to see the latest.
View
1  CONTRIBUTORS.txt
@@ -107,3 +107,4 @@ Contributors
- Sebastian Hanula 2012/12/17
- Aaron Spaulding, 2013/01/20
- Hadrien David, 2013/01/23
+- Daniel Werner, 2013/06/03
View
11 pyramid_debugtoolbar/tests/test_utils.py
@@ -86,3 +86,14 @@ def test_in_multi(self):
def test_in_network(self):
self.assertTrue(self._callFUT('127.0.0.1', ['127.0.0.1/24']))
+
+class Test_last_proxy(unittest.TestCase):
+ def _callFUT(self, addr):
+ from pyramid_debugtoolbar.utils import last_proxy
+ return last_proxy(addr)
+
+ def test_single_host(self):
+ self.assertEqual(self._callFUT('192.168.1.2'), '192.168.1.2')
+
+ def test_multiple_hosts(self):
+ self.assertEqual(self._callFUT('192.168.1.1, 192.168.1.2'), '192.168.1.2')
View
3  pyramid_debugtoolbar/toolbar.py
@@ -17,6 +17,7 @@
from pyramid_debugtoolbar.utils import EXC_ROUTE_NAME
from pyramid_debugtoolbar.utils import logger
from pyramid_debugtoolbar.utils import addr_in
+from pyramid_debugtoolbar.utils import last_proxy
from pyramid.httpexceptions import WSGIHTTPException
@@ -121,7 +122,7 @@ def toolbar_tween(request):
exclude)))
if request.remote_addr:
- last_proxy_addr = request.remote_addr.split(',').pop().strip()
+ last_proxy_addr = last_proxy(request.remote_addr)
if last_proxy_addr is None \
or starts_with_excluded \
View
2  pyramid_debugtoolbar/utils.py
@@ -159,3 +159,5 @@ def addr_in(addr, hosts):
return True
return False
+def last_proxy(addr):
+ return addr.split(',').pop().strip()
View
8 pyramid_debugtoolbar/views.py
@@ -14,16 +14,18 @@
from pyramid_debugtoolbar.utils import format_sql
from pyramid_debugtoolbar.utils import get_setting
from pyramid_debugtoolbar.utils import addr_in
+from pyramid_debugtoolbar.utils import last_proxy
from pyramid_debugtoolbar.toolbar import IRequestAuthorization
def valid_host(info, request):
hosts = get_setting(request.registry.settings, 'hosts')
- remote_addr = request.remote_addr
- if remote_addr is None:
+ if request.remote_addr is None:
return False
- return addr_in(request.remote_addr, hosts)
+ last_proxy_addr = last_proxy(request.remote_addr)
+
+ return addr_in(last_proxy_addr, hosts)
def valid_request(info, request):
Something went wrong with that request. Please try again.